in the code you put on github, for the codeTwo and codeThree client events you have them finding new targets without having a source.
-- code two --
RegisterNetEvent('codeTwo')
AddEventHandler('codeTwo', function(vehicle)
local player = GetPlayerPed()
local vehicle = GetVehiclePedIsIn(player, false)
local class = GetVehicleClass(vehicle)
-- turn on siren
SetVehicleSiren(vehicle, true)
-- turn off siren (sound)
DisableVehicleImpactExplosionActivation(vehicle, true)
end)
--------------
-- code three --
RegisterNetEvent('codeThree')
AddEventHandler('codeThree', function()
local player = GetPlayerPed()
local vehicle = GetVehiclePedIsIn(player, false)
local class = GetVehicleClass(vehicle)
-- for server event --
SetVehicleSiren(vehicle, true)
DisableVehicleImpactExplosionActivation(vehicle, false)
the vehicle is already determined and being sent along tot he server and back tot he client, so you dont want to try to find a new one.
the code should look like:
-- code two --
RegisterNetEvent('codeTwo')
AddEventHandler('codeTwo', function(vehicle)
-- turn on siren
SetVehicleSiren(vehicle, true)
DisableVehicleImpactExplosionActivation(vehicle, true)
end)
--------------
-- code three --
RegisterNetEvent('codeThree')
AddEventHandler('codeThree', function()
-- turn on siren
SetVehicleSiren(vehicle, true)
DisableVehicleImpactExplosionActivation(vehicle, false)
end)
of course I realize now this code will only make the lights turn on, not off.
to make it toggle:
-- code two --
RegisterNetEvent('codeTwo')
AddEventHandler('codeTwo', function(vehicle)
if IsVehicleSirenOn(vehicle) then
SetVehicleSiren(vehicle, false)
else
SetVehicleSiren(vehicle, true)
end
DisableVehicleImpactExplosionActivation(vehicle, true)
end)
--------------
-- code three --
RegisterNetEvent('codeThree')
AddEventHandler('codeThree', function()
if IsVehicleSirenOn(vehicle) then
SetVehicleSiren(vehicle, false)
else
SetVehicleSiren(vehicle, true)
end
DisableVehicleImpactExplosionActivation(vehicle, false)
end)
also in the Citizen thread you might want to check for toggle as well:
-- if player hits 'LCTRL + 2' - set police car to code 2
if IsControlPressed(0, Keys['LEFTCTRL']) and IsControlJustPressed(0, Keys['2']) then
-- set variables
local player = PlayerPedId()
local vehicle = GetVehiclePedIsIn(player, false)
local class = GetVehicleClass(vehicle)
-- if player is in a vehicle
if vehicle ~= 0 then
-- if vehicle ped is in, is an emergency vehicle
if class == 18 then
-- trigger codeTwo server event
TriggerServerEvent('codeTwo', vehicle)
-- give user notification
if IsVehicleSirenOn(vehicle) then
ShowNotification("You've canceled ~y~code two~w~.")
else
ShowNotification("You've entered ~y~code two~w~.")
end
end
end
end
-- if player hits 'LCTRL + 3' - set police car to code 3
if IsControlPressed(0, Keys['LEFTCTRL']) and IsControlJustPressed(0, Keys['3']) then
local player = PlayerPedId()
local vehicle = GetVehiclePedIsIn(player, false)
local class = GetVehicleClass(vehicle)
if vehicle ~= 0 then
if class == 18 then
TriggerServerEvent('codeThree', vehicle)
if IsVehicleSirenOn(vehicle) then
ShowNotification("You've canceled ~y~code three~w~.")
else
ShowNotification("You've entered ~y~code three~w~.")
end
end
end
end