How to bind menu to a key instead of a command

GitHub - XakraD/xakra_animations Is anyone able to help me figure out how to open the menu using a key instead of a command?

There is no such option in xakra_animations, but you can add it like this:

-- client.lua
CreateThread(function()
    while true do
        if IsRawKeyReleased(32) then -- KEY_SPACE
            ExecuteCommand(Config.CommandOpen)
        end
        Wait(0)
    end
end)

Native reference: RDR3 Natives Explorer
Key codes: Virtual-Key Codes

I tried, but it doesn’t work in this script.

If this doesn’t work, then some other script may blocking keys by using DisableRawKeyThisFrame. You can solve it by adjusting the code like this:

-- client.lua
CreateThread(function()
    while true do
        if IsRawKeyReleased(32) or IsDisabledRawKeyReleased(32) then -- KEY_SPACE
            ExecuteCommand(Config.CommandOpen)
        end
        Wait(0)
    end
end)

You also can try other options like IsRawKeyPressed.

There is also other functions IsControlJustReleased, IsControlJustPressed, you can use them, but in that case not all controls will work. You can find list here: rdr3_discoveries/Controls at master · femga/rdr3_discoveries · GitHub

And example of usage:

-- client.lua
CreateThread(function()
    while true do
        if IsControlJustReleased(`INPUT_JUMP`) then
            ExecuteCommand(Config.CommandOpen)
        end
        Wait(0)
    end
end)
1 Like
-- client.lua
CreateThread(function()
    while true do
        if IsRawKeyReleased(32) or IsDisabledRawKeyReleased(32) then -- KEY_SPACE
            ExecuteCommand(Config.CommandOpen)
        end
        Wait(0)
    end
end)

Yeah, that worked perfectly! Damn, I was stuck on this for about 3 hours. Thank you so much for your help, I’m a beginner and still learning everything. I’m really glad there are people like you who keep helping others. You’re awesome!

1 Like

Are you still able to help me? I want to make it so that when the animation menu is open, I can still talk. I’m trying to modify it the same way it works with the inventory, but it’s not working.

inventory client.lua

– ENABLE PUSH TO TALK
CreateThread(function()
repeat Wait(5000) until LocalPlayer.state.IsInSession
local isNuiFocused = false

while true do
    local sleep = 0
    if InInventory then
        if not isNuiFocused then
            SetNuiFocusKeepInput(true)
            isNuiFocused = true
        end

        DisableAllControlActions(0)
        EnableControlAction(0, `INPUT_PUSH_TO_TALK`, true)
    else
        sleep = 1000
        if isNuiFocused then
            SetNuiFocusKeepInput(false)
            isNuiFocused = false
        end
    end
    Wait(sleep)
end

end)

In client/client.lua change file like this:

RegisterCommand(Config.CommandOpen, function(source, args, rawCommand)
    local FavoriteAnimations = json.decode(GetResourceKvpString('FavoriteAnimations') or '[]')

    for i, v in pairs(Config.Animations) do
        v.Favorite = false
        for _, x in pairs(FavoriteAnimations) do
            if x == v.Label then
                v.Favorite = true
            end
        end
    end

    SendNUIMessage({
        type = 'Open',
        Animations = Config.Animations,
    })

    SetNuiFocus(true, true)
    SetNuiFocusKeepInput(true) -- ADD THIS!
    PlaySoundFrontend("BACK", "RDRO_Character_Creator_Sounds", true, 0)
end)
RegisterNUICallback('Close', function(args, cb)
    SetNuiFocus(false, false)
    SetNuiFocusKeepInput(false) -- ADD THIS!
    PlaySoundFrontend("BACK", "RDRO_Character_Creator_Sounds", true, 0)
end)

Unfortunately, this does not work. :frowning:

Works fine on my side :person_shrugging: Here my file:
client.lua (2.9 KB)

Ok, I see you did it a bit differently, but with this method it’s hard to search through the animations since every key is enabled. In the VORP inventory it works great because you can use voice chat while the keys are paused, but this is also some kind of solution :slight_smile:

I did exactly what I suggested in the previous post - just added two lines to the original version, marked with -- Add this!. You can expand on this by disabling all keys and enabling only the ones you need:

-- client/client.lua
local isOpened = false
RegisterCommand(Config.CommandOpen, function(source, args, rawCommand)
    local FavoriteAnimations = json.decode(GetResourceKvpString('FavoriteAnimations') or '[]')

    for i, v in pairs(Config.Animations) do
        v.Favorite = false
        for _, x in pairs(FavoriteAnimations) do
            if x == v.Label then
                v.Favorite = true
            end
        end
    end

    SendNUIMessage({
        type = 'Open',
        Animations = Config.Animations,
    })

    SetNuiFocus(true, true)
    SetNuiFocusKeepInput(true) -- ADD THIS!
    isOpened = true  -- ADD THIS!
     -- ADD THIS!
    CreateThread(function()
        while isOpened do
            Wait(0)
            DisableAllControlActions(0)
            EnableControlAction(0, `INPUT_PUSH_TO_TALK`, true)
        end
    end)
     -- 
    PlaySoundFrontend("BACK", "RDRO_Character_Creator_Sounds", true, 0)
end)
-- client/client.lua
RegisterNUICallback('Close', function(args, cb)
    SetNuiFocus(false, false)
    SetNuiFocusKeepInput(false) -- ADD THIS!
    isOpened = false -- ADD THIS!
    PlaySoundFrontend("BACK", "RDRO_Character_Creator_Sounds", true, 0)
end)

1 Like

I really appreciate your help on the scripts thenks so much ! <3

1 Like