its just not turning off
Simplified code and added a sound for toggle. This ONLY sends siren status to connected players. Joining players will hear your siren unless you toggle it again.
Just wanted to give you a heads up that the client code uses a MyPed() function which is not included.
Replacing with GetPlayerPed(-1) works or setting that to a variable on key press.
Edit: My bad, hadn’t seen that MyPed() function up top
Did you change all 3 “MyPed()”? Mine is not working, even after changing them.
Apparently there is a MyPed() function that I did not see if you scroll the code up, however there are some other errors as well that must be fixed and it seems to work, although I haven’t tested it with other players.
These lines need to be changed in the client:
if IsControlJustPressed(1, 58) then -- G
local myPed = GetPlayerPed(-1)
if IsPedInAnyVehicle(myPed, false) then
Vehicle = GetVehiclePedIsIn(myPed)
if GetPedInVehicleSeat(Vehicle, -1) == myPed then
if IsPedInAnyPoliceVehicle(myPed) then
-- Siren Toggle if statements
And this small change in the server:
TriggerClientEvent('updateSirens', -1, source, Toggle)
source instead of netID since netID is never set to anything.
Added missing function MyPed() and fixed other variables. Sorry
Still not working… When I press G nothing happens.
Don’t feel bad man, everyone makes mistakes. I’m happy to help.
To get it working you just need to change one more thing I believe,
- Move GetPedVehicleSeat(MyPed()) to its own if statement below the Vehicle variable, then change it to GetPedInVehicleSeat(Vehicle, -1) == MyPed().
Like this:
if IsPedInAnyVehicle(MyPed(), false) then
Vehicle = GetVehiclePedIsIn(MyPed())
if GetPedInVehicleSeat(Vehicle, -1) == MyPed()then
Then it should work just fine, it does for me at least.
That worked perfectly. Thanks!
This is still not working, at least not for me. Anyone have any suggestions?
This is still not working, at least not for me. Anyone have any suggestions?
Did you try the suggestion above? Works for me.
Yes, I think so, but apperantly have I missed something.
Can someone (that is really nice) post the code that works here? That would be great.
Can someone please post their code here for both the client and server?
I’ve updated the code, should work fine.
I’ve updated the code, should work fine.
Just tried it, and it doesn’t work for me. The fix provided by @Cosmo is what is currently working for me. Both __resource.lua and server.lua are correct, but client.lua is as follows:
function MyPed()
return GetPlayerPed(-1)
end
SirenToggle = false
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if IsControlJustPressed(1, 58) then -- G
if IsPedInAnyVehicle(MyPed(), false) then
Vehicle = GetVehiclePedIsUsing(MyPed())
if GetPedInVehicleSeat(Vehicle, -1) == MyPed()then
if SirenToggle then
PlaySoundFrontend(-1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1)
SirenToggle = false
TriggerServerEvent('SilentSiren', SirenToggle)
else
PlaySoundFrontend(-1, "NAV_LEFT_RIGHT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1)
SirenToggle = true
TriggerServerEvent('SilentSiren', SirenToggle)
end
end
end
end
end
end)
-- Called by server to disable siren on any target vehicle
RegisterNetEvent('updateSirens')
AddEventHandler('updateSirens', function(PID, Toggle)
local Veh = GetVehiclePedIsIn(GetPlayerPed(GetPlayerFromServerId(PID)), false)
DisableVehicleImpactExplosionActivation(Veh, Toggle)
end)
How do you install it
How do you install it
Holy necro batman!
I believe this was wrote for CitizenMP the previous version of FiveM - it’s now using FXServer.
Though by the looks of the thread previously, this didn’t work as intended originally, I’d recommend using Luxart Vehicle Control instead, you can find it here.