Hey there! So I was looking to help my friend with a basic script he was making (yet another radio ptt script… I know, I know, very saturated market…) but he was looking to take the twist of utilizing the newer (yet still old) RegisterKeyMapping native. Now the only issue that I’ve run into is that I can’t figure out how you would actually check if that key is being help down since I can’t get their mapping. Here’s some snippets of the code so far:
local RadioUp = false
Citizen.CreateThread(function()
RegisterKeyBinds()
while true do
Citizen.Wait(0)
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
if DoesEntityExist(ped) and not IsEntityDead(ped) and not IsPauseMenuActive() then
if RadioUp then ...
function RegisterKeyBinds()
RegisterCommand("radio_toggle", function()
if RadioUp then
RadioUp = false
ResetChar()
else
RadioUp = true
end
end)
RegisterKeyMapping('radio_toggle', 'Key To Bring Your Radio Up', 'keyboard', 'LMENU')
end
Not sure if I’m just being dumb here but I couldn’t find very many topics around this so any discussion would really help me out as well as the rest of the community.
I can kinda anticipate at least one of these comments so I might as well say that YES I have already looked through the docs, google, github and the FiveM cookbook… not sure if I missed something but if the answer lies within one of those sources please actually link me to it rather than saying "ReAd ThE dOcS"
Citizen.CreateThread(function()
RegisterKeyBinds()
while true do
Citizen.Wait(0)
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
if DoesEntityExist(ped) and not IsEntityDead(ped) and not IsPauseMenuActive() then
if RadioUp then ...
RegisterCommand('+radio', function()
RadioUp = true
end, false)
RegisterCommand('-radio', function()
RadioUp = false
ResetChar()
end, false)
RegisterKeyMapping('+radio', 'Key To Bring Your Radio Up', 'keyboard', 'LMENU')
While that toggles the issue is that I only want RadioUp to = true when the key is depressed then when it is released RadioUp = false (aka when they hold L ALT bring radio up). I’ve tried your solution but it doesn’t seem to work with the whole holding thing.
Thanks for the quick response tho. LMK if you have any other ideas or if I just goofed
Citizen.CreateThread(function()
RegisterKeyBinds()
while true do
Citizen.Wait(0)
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
if DoesEntityExist(ped) and not IsEntityDead(ped) and not IsPauseMenuActive() then
if RadioUp then ...
--here the radio should be triggered in order to be displayed
RegisterCommand('+radio', function()
RadioUp = true
end, false)
RegisterCommand('-radio', function()
RadioUp = false
ResetChar()
--here should be triggered the radio to be hide
end, false)
RegisterKeyMapping('+radio', 'Key To Bring Your Radio Up', 'keyboard', 'LMENU')
RegisterCommand('+radio', function() while true do Citizen.Wait(0) local ped = PlayerPedId() local coords = GetEntityCoords(ped) if DoesEntityExist(ped) and not IsEntityDead(ped) and not IsPauseMenuActive() then end, false) RegisterCommand('-radio', function() ResetChar() end, false) RegisterKeyMapping('+radio', 'Key To Bring Your Radio Up', 'keyboard', 'LMENU')
Why not just do it like this where it would just do the while loop when you’re holding then button.