Skip to content

Conversation

MohabCodeX
Copy link
Contributor

Usage

Testing Script
-- Client-side
addEventHandler("onClientCommand", root, function(command, ...)
    if command == "restricted" then
        cancelEvent() 
        outputChatBox("This command is disabled!", 255, 100, 100)
    end
end)


addEventHandler("onClientCommand", root, function(command, ...)
    local args = {...}
    local executedByFunction = args[#args]
    table.remove(args, #args) 
    
    local blockedCommands = {"run", "exec", "execute", "lua", "script"}
    for _, blocked in ipairs(blockedCommands) do
        if command == blocked then
            cancelEvent()
            triggerServerEvent("onPlayerUsedExecutor", localPlayer, command)
            return
        end
    end
    
    if not executedByFunction then
        local currentTime = getTickCount()
        if currentTime - (lastCommandTime or 0) < 100 then
            triggerServerEvent("onPlayerUsedExecutor", localPlayer, "rapid_execution")
        end
        lastCommandTime = currentTime
    end
end)

-- Server-side

addEvent("onPlayerUsedExecutor", true)
addEventHandler("onPlayerUsedExecutor", root, function(reason)
    banPlayer(client, true, false, false, 0, "Lua executor detected: " .. reason)
end)

Fixes #3160

@FileEX FileEX added the enhancement New feature or request label Sep 7, 2025
strClumpedCommand = UTF16ToMbUTF8(strClumpedCommandUTF);

g_pClientGame->GetRegisteredCommands()->ProcessCommand(szCommandBufferPointer, szArguments);
CommandExecutionResult commandResult = g_pClientGame->GetRegisteredCommands()->ProcessCommand(szCommandBufferPointer, szArguments, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now, when you type /foo, do you see the message "Unknown command or cvar"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I fixed this .. they get silently sent to the server. My implementation preserves this original behavior:

  1. If command is cancelled by onClientCommand → return true (don't send to server, don't show unknown command)
  2. If command is not cancelled → continue normal flow (send to server, return true)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops .. wait i need to check your suggestion again

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done @FileEX

2025-09-08.12-29-13.mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also if handled by script & onClientCommand, it will not return unknown
image

Copy link
Contributor Author

@MohabCodeX MohabCodeX Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found new bug while using editor 😅, it also made heavy load than original behavior & network trouble when starting/restarting editor resource
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed ✅

@MohabCodeX MohabCodeX requested a review from FileEX September 8, 2025 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'onPlayerCommand' event for client-side
2 participants