Hey there, I’m not positive if this is the correct area for this, but I was curious if anyone could help me with a basic script. I’m not familiar with LUA nor can I find too many tutorials for FiveM scripting, so I was hoping someone here could help point me in the right direction or perhaps even work with me on a basic script. All I need is a command to disable the radar for all members on the server. If I could execute “/radar” or something similar to have the radar disabled that would be outstanding. Like I said, even if a few basic tutorials or information could be provided you would be helping me so much, thank you!
So far this I what I have, am I on the correct path at all?
Server:
-- Add an event handler for the 'chatMessage' event
AddEventHandler( 'chatMessage', function( source, n, msg )
-- Check to see if a client typed in /showradar
if ( msg == "/showradar" ) then
-- Cancel the chat message event (stop the server from posting the message)
CancelEvent()
-- Trigger the client event
TriggerClientEvent( 'displayRadar', source )
end
end )
-- Add an event handler for the 'chatMessage' event
AddEventHandler( 'chatMessage', function( source, n, msg )
-- Check to see if a client typed in /hideradar
if ( msg == "/hideradar" ) then
-- Cancel the chat message event (stop the server from posting the message)
CancelEvent()
-- Trigger the client event
TriggerClientEvent( 'noDisplayRadar', source )
end
end )
Client:
-- Register a network event
RegisterNetEvent( 'noDisplayRadar' )
-- Add an event handler for the noDisplayRadar event.
AddEventHandler( 'noDisplayRadar', function()
DisplayRadar(false)
end )
-- Register a network event
RegisterNetEvent( 'displayRadar' )
-- Add an event handler for the displayRadar event.
AddEventHandler( 'displayRadar', function()
DisplayRadar(true)
end )
You can use 1 chat message event and 1client t event. As for doing it on start just call the client event as someone joins.
For chat message just put the two if’s in one and for the client even pass in a true/false value from the command.
Other than that yes. You are heading in the right way
Yes you can easily make this a toggle which means the code block will be smaller. The way you are doing it is not wrong that is definately an option for sure. Just a lot of extra lines.
Oh here is a tip. Where you trigger the client event inside the chat message. If you replace “source” with -1 it will run that event on all connected players
TriggerClientEvent( 'noDisplayRadar', -1 )
Hey thanks everyone, I’ve got the script working, with only a minor problem. Everyone has Lambda Trainer installed, and it automatically sets the radar back when it is disabled. The radar flashes away for a brief second before being reset. I’m wondering if there’s a way I can loop the command to continue running so it hides it every time it comes back. I know this might be a little laggy, but it’s just a temp solution.
You can do a while true do loop.
Maybe use this as an example. – This is the client side server side should not be any different. Other than maybe the event name.
local radarDisabled = false
RegisterNetEvent("disableRadar")
AddEventHandler("disableRadar", function()
if not radarDisabled then
radarDisabled = true
else
radarDisabled = false
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if not radarDisabled then
DisplayRadar(false)
end
if radarDisabled then
DisplayRadar(true)
end
end
end)
Thank you so much! This is exactly what I need, plus it helped me understand the scripting better, thank you!
or change it do do radarDisplay = not radarDisplay for a bit shorter, also using elseif’s