esx_core icon indicating copy to clipboard operation
esx_core copied to clipboard

[Bug] - es_extended - KeyMapping interfere with es_extended when it shouldn't

Open s1nyx opened this issue 10 months ago • 3 comments

Hi,

Describe the bug If I try to create a KeyMapping on another script, when pressing the key it will show the message error 'Invalid Command - /cmd'.

To Reproduce Steps to reproduce the behavior: Create a client-side script with for example:

local handsUp = false
CreateThread(function()
    while true do
        Wait(0)
        if handsUp then
            TaskHandsUp(PlayerPedId(), 250, PlayerPedId(), -1, true)
        end
    end
end)
RegisterCommand('+handsup', function()
    handsUp = true
end, false)
RegisterCommand('-handsup', function()
    handsUp = false
end, false)

RegisterKeyMapping('+handsup', 'Hands Up', 'keyboard', 'i')

Expected behavior Nothing, shouldn't interfere with other scripts.

Screenshots image

Debug Info (please complete the following information):

  • OS: Linux
  • FiveM Artifact: Latest recommended
  • ESX Version: 1.10.5

Additional context

This issue is from this part of the code located in es_extended/server/main.lua.

AddEventHandler("chatMessage", function(playerId, _, message)
    local xPlayer = ESX.GetPlayerFromId(playerId)
    if message:sub(1, 1) == "/" and playerId > 0 then
        CancelEvent()
        local commandName = message:sub(1):gmatch("%w+")()
        xPlayer.showNotification(TranslateCap("commanderror_invalidcommand", commandName))
    end
end)

s1nyx avatar Apr 09 '24 15:04 s1nyx

@s1nyx Hi! I copied your code into a plain client-side lua file and didn't experience any problems, the chatMessage is only called when you actually try to call a non-valid command, otherwise it is not called.

For me your code worked flawlessly, it up the hand nicely then down the hand I didn't get any errors.

Gellipapa avatar Apr 13 '24 19:04 Gellipapa

@s1nyx Hi! I copied your code into a plain client-side lua file and didn't experience any problems, the chatMessage is only called when you actually try to call a non-valid command, otherwise it is not called.

For me your code worked flawlessly, it up the hand nicely then down the hand I didn't get any errors.

Hi,

Let me check again. I'll get back to you asap.

s1nyx avatar Apr 14 '24 11:04 s1nyx

Hi! @s1nyx Any news?

Gellipapa avatar May 03 '24 09:05 Gellipapa

Hi! @s1nyx Any news? Hi,

The issue came from the fact that I didn't register the command with the -, only the +. Now fixed and works perfectly.

Have a nice day.

s1nyx avatar May 04 '24 14:05 s1nyx