Исходник [SC21] Cheat Monitor - Game Console (Recommended for 2 monitor users)

orel56000

Известный
Автор темы
5
35
Cheat Monitor

1622500430562.png

Credits: Orel56000 (ME)
Discord: orel56000();#1143
Hello everybody, as a participant of the SA:MP Coder 2021 contest, I'm publishing this script.

So what it is?
Simply, this script will open a console, which other scripts can write in it.

What can I do with it?
You can see chat messages from other scripts, which were supposed to be written in chat, but in the console, the main goal of this script is to print the cheats messages in another place, so when you want to screenshot your chat, it will be clean from cheats. The console is a literally new window, which can be dragged even to another monitor - which what makes it special.

How do I use it?
By default, the console will be opened automatically when you open the game (can be changed in the config).
You can close/open it with the default command "/console (off).
By default, every print () command from every script, will be written there.

wgdC7DH.png


Cheat Browser:
The cheat browser is kinda an improvised menu, which will let you active cheats from other scripts (Only if they support it)
The default key to active it is "INS".
It is working in this way:
Up and Down arrows - Browse between cheat files.
Left and Right arrows - Browse between cheats within the same cheat file you are on by the Up and Down arrows.
Enter key - Will toggle the selected cheat from the selected cheat file.

Pros and Cons:

Pros:
  1. Can be used to hide your cheats' messages, and your cheats at all, as it is also possible to toggle cheats with the cheat browser.
  2. Isn't part of the game, so it can be dragged to a second or third (even fourth if you are extravagantly rich🤑💸) monitor, so you will not see until you move your head (Real head of course) right or left (depends on where the other monitor is).
  3. Cheats will stop spamming your SA:MP chat, causing you sometimes to lose the message you really wanted to read and forces you to scroll up (idk about you, I found it really annoying).
  4. Finally a good use of your second monitor, until now, you just used it to watch who of your friends muted himself on discord.
  5. It just cool.
Cons:
  1. There is a known bug, that if you close the console from the X button on the window, it will close also the game. (Close the window only by the command "/console off" or from other scripts with Console.Close()
  2. The console's colors are getting broken after 10K lines. (Just wanted to mention, not like you gonna get to it, and even if so, just close the console and reopen it with "/console off" and then "/console"). It will change the color of the whole window to the last color used.
  3. It is really useless if you are poor(Meaning you do not have two monitors), it will just run in the background (even though you can still see it if you turn your game to window mode (CTRL + ENTER).
  4. FBI may break into your house thinking you are a big hacker, but it rarely happens so don't worry too much about it.



"I'm not a programmer, and I want other cheats to support it, what do I do??"
easy pizi lemon squeezy🙃.

Wanna upgrade an old cheat you are using? Just pray it's not encrypted, and if not (Yey) just paste this at the top of the file. (Don't worry, if the console is closed it will just print it in the chat like it used to do before):
Integration code:
local Console = import("CheatMonitor.lua")
sampAddChatMessage = Console.sampAddChatMessage



Config (Can be changed on the top of the file):
Lua:
-------------------------------CONFIG---------------------------
--[[/*/*    Here you can modify the script's default settings    */*/]]

local OpenAtStartup = true -- Will open the console automaticlly after SA:MP initialization.                     | Default: false
-- Console Default Settings
local ReplacePrint = true -- If every print() will be written in the console.                                     | Default: true
local DefaultBackgroundColor = ConsoleColors["BLACK"] -- Default console background color.                         | Default: ConsoleColors["BLACK"]
local DefaultTextColor = ConsoleColors["WHITE"] -- Default console text color.                                     | Default: ConsoleColors["WHITE"]
local CommandToOpenConsole = "console" -- '/' is built-in.                                                         | Default: "console"
local ConsoleTitle = "SA:MP Cheat Console" -- Console title.                                                     | Default: "SA:MP Cheat Console"
-- Cheat Browser
local BrowserCheats = true -- If cheat browser is enabled.                                                         | Default: true
local DefaultBrowseKey = 0x2D -- INS key - Will open browse cheats menu.                                         | Default: 0x2D
local BrowserLeftKey = 0x25 -- Left Key - Browse between cheats whithin the current cheat file (backwards).     | Default: 0x25
local BrowserRightKey = 0x27 -- Right Key - Browse between cheats whithin the current cheat file (forwards).     | Default: 0x27
local BrowserUpKey = 0x26 -- Up Key - Browse between cheat files (backwards).                                     | Default: 0x26
local BrowserDownKey = 0x28 -- Down Key - Browse between cheat files (forwards).                                 | Default: 0x28
local BrowserEnterKey = 0x0D -- Enter Key - Will toggle current cheat.                                             | Default: 0x0D
----------------------------------------------------------------

API:


Cheat Browser:

In order to make your script appear in the Cheat Browser, all you need to do is create a toggle function for your cheat, and make it an EXPORT inside a `cheats` object
Example of a small Fast Run script I made:
Lua:
local thisFrame = true  ---------- SCROLL DOWN, THIS PART IS NOT THE IMPORTANT ONE
function FastRun()
    wait(30)
    if isCharInAnyCar(playerPed) then
        wait(1000)
    else
        if thisFrame then
            setGameKeyState(16, 0)
        end
        thisFrame = not thisFrame  ---------- YOU ARE ALMOST THERE, STILL NOT THE IMPORTANT PART
    end
end
local work = true
function ToggleFastRun()
    work = not work
end

function main()
    while not isSampAvailable() do
        wait(3000)
    end
    while true do                 -------------------- YOU ARE JUST ABOUT TO SEE IT, JUST A LITTLE MORE SCROLLING
        wait(0)
        if work then
            FastRun()
        end
    end
end
---------------------- THIS IS THE IMPORTANT PART -----------------------------
EXPORTS = {
    cheats = { -- Will change between FastRun and TestPrint5 with the Left and Right arrows.
        FastRun = ToggleFastRun,
        TestPrint5 = function() print(5) end
    }
}
------------------- IMPORTANT PART OVER, KEEP WALKING ------------------------

Console Write:
So since this script is not standalone, and requires other scripts to realize its potential, it has a very easy API, which allows to other scripts communicate with it.
First of all - add this line in one of the first lines:
Lua:
local Console = import("CheatMonitor.lua")
This will let you use the next functions:


bool IsActive() - This function has no parameters and checks if there's an active console at the moment.
Example of use:
Lua:
if Console.IsActive() then
    -- Code
end

bool WriteLine(Message, TextColor = CurrentTextColor, BackgroundColor = CurrentBackgroundColor) - This function is one of the main functions of this script, its use it to write text in the console, the TextColor and BackgroundColor parameters are optional.
TextColor = The color the literal text.
BackgroundColor = The color of the background of the text, behind the text itself.

**
The parameters TextColor and BackgroundColor will not change the rest of the console's message color, just this one!!
**
Example of use:
Lua:
sampRegisterChatCommand("Hey", function(params)
    if Console.IsActive() then
        Console.WriteLine("Hey: "..params, Console.ColorList["BLUE"], Console.ColorList["BLACK"]) -- Will print the message colored blue with a black background.
        Console.WriteLine("Another print") -- Will be written with the last **set** colors
    end
end)

1622507615510.png


bool Write(Message, TextColor = CurrentTextColor, BackgroundColor = CurrentBackgroundColor) - This function does the same as WriteLine, just without creating a new line (\n), so the next message will be on the same line as this.
Example of use:
Lua:
if Console.IsActive then
    Console.Write("Hey ")
    Console.Write("I'm colored", Console.ColorList["RED"], Console.ColorList["BLUE"])
    Console.WriteLine(" and I'm not")
    -- Will be written as "Hey I'm colored and I'm not" only the "I'm colored" will be colored red with a blue background.
end
1622507647320.png

table ColorList - Will return a table of numbers which is used to paint the console lines and text.
Colors definitions:
Lua:
local ConsoleColors = {
    ["BLACK"] = 0,
    ["BLUE"] = 1,
    ["GREEN"] = 2,
    ["CYAN"] = 3,
    ["RED"] = 4,
    ["MAGENTA"] = 5,
    ["BROWN"] = 6,
    ["LIGHTGRAY"] = 7,
    ["DARKGRAY"] = 8,
    ["LIGHTBLUE"] = 9,
    ["LIGHTGREEN"] = 10,
    ["LIGHTCYAN"] = 11,
    ["LIGHTRED"] = 12,
    ["LIGHTMAGENTA"] = 13,
    ["YELLOW"] = 14,
    ["WHITE"] = 15
}

--Useage:
Console.ColorList["Color Name"]
SetColors(TextColor, BackgroundColor) - This function is used to change the next written text color and background color. Will change all the texts that being used by Write and WriteLine function without their optional parameters. This is not recommended, as it will also change other scripts' text colors.
Example of use:
Lua:
Console.SetColors(Console.ColorList["BLACK"], Console.ColorList["WHITE"]) -- All the texts that being written by Write and WriteLine without the optional parameters will be from now on black with white background.
Console.WriteLine("HEYYY") -- Will be written black on white background.
Console.WriteLine("I'm red on yellow", Console.ColorList["RED"], Console.ColorList["YELLOW"]) -- Will be written red on yellow background, as it is using the optional parameters.
Console.WriteLine("Back to black") -- Will be written again in black on white background, as these are the global colors.
1622507778721.png

number TextColor, number BackgroundColor = GetCurrentColors() - Used to get the last colors from SetColors function, if it was never used, will get the default colors.
Example of use:
Lua:
local OldTextColor, OldBackgroundColor = Console.GetCurrentColors()
Console.SetColors(Console.ColorList["GREEN"], Console.ColorList["BLUE"])
Console.WriteLine("Green on Blue background")
Console.SetColors(OldTextColor, OldBackgroundColor)
Console.WriteLine("Okay boomer")
1622507848516.png

SetToDefaultColors() - Will set the color to the default colors, from the config.
Close() - Will close the console, if it's opened.
Open() - Will reopen the console, if it's closed.


Requirements:
  1. GTA San Andreas
  2. SA:MP 0.3.7 r1
  3. Sampfuncs
  4. Moonloader
Hope you liked it, tell me what do you think... (Good comments only)
 

Вложения

  • 1622507686020.png
    1622507686020.png
    27 KB · Просмотры: 439
  • 1622507837776.png
    1622507837776.png
    19 KB · Просмотры: 431
  • CheatMonitor.lua
    9.6 KB · Просмотры: 104
Последнее редактирование:

MrCreepTon

وНеизвестный
Всефорумный модератор
2,127
4,711
The file itself was created long time ago, but it didn't had anything, as I didn't have a will to make this cheat. The actual progress and content was made yesterday after I saw the contest.

I guess that maybe counts as the project started yesterday?
By rules your file must start development after competition started.
 

livingflore

Известный
366
319
ну и зачем ты со своими плюсами в луа лезешь
тут вообще совершенно другой скрипт под луа, у тебя же плагин, который используется только в плюсах и нигде более
писать какой-то костыль чтобы юзать твой плагин в луа? а зачем, если уже есть это?