p_lights = {}
p_timer = {}
p_lvar = {}
key = "l"
function toggleLights(thePlayer, cmd)
local veh = getPedOccupiedVehicle(thePlayer)
local id = getElementModel(veh)
if (id == 470) or (id == 490) or (id == 427) or (id == 433) or (id == 598) or (id == 597) or (id == 599) or (id == 523) then
local skinid = getElemtModel(thePlayer)
if skinid =280 or skinid==281 or skinid==282 or skinid==283 or skinid==284 or skinid==285 or skinid==286 or skinid==287 or skinid==288 or skinid==163 or skinid==164 or skinid==165 then
if(p_lights[veh] == 0) or(p_lights[veh] == nil) then
p_lights[veh] = 1
outputChatBox("Blaulicht angeschaltet.", thePlayer, 0, 200, 100, true)
setVehicleOverrideLights ( veh, 2 )
p_timer[veh] = setTimer(
function()
if(p_lvar[veh] == 0) or (p_lvar[veh] == nil) then
p_lvar[veh] = 1
setVehicleLightState ( veh, 1, 0)
setVehicleLightState ( veh, 2, 0)
setVehicleLightState ( veh, 0, 1)
setVehicleLightState ( veh, 3, 1)
setVehicleHeadLightColor(veh, 0, 0, 255)
else
setVehicleLightState ( veh, 3, 0)
setVehicleLightState ( veh, 0, 0)
setVehicleLightState ( veh, 1, 1)
setVehicleLightState ( veh, 2, 1)
setVehicleHeadLightColor(veh, 255, 0, 0)
p_lvar[veh] = 0
end
end, 500, 0)
else
p_lights[veh] = 0
outputChatBox("Blaulicht ausgeschaltet.", thePlayer, 0, 200, 100, true)
killTimer(p_timer[veh])
setVehicleLightState ( veh, 0, 0)
setVehicleLightState ( veh, 1, 0)
setVehicleLightState ( veh, 2, 0)
setVehicleLightState ( veh, 3, 0)
setVehicleHeadLightColor(veh, 255, 255, 255)
setVehicleOverrideLights ( veh, 1 )
end
else
outputChatBox("Der Befehl ist nur für die Polizei", thePlayer, 255, 0, 0, false)
end
end
end
addCommandHandler("lights", toggleLights)
bindKey(key,"down",toggleLights)
addEventHandler ( "onVehicleExplode", getRootElement(),
function()
if(p_lights[source] == 1) then
killTimer(p_timer[source])
end
end )
addEventHandler ( "onVehicleRespawn", getRootElement(),
function()
if(p_lights[source] == 1) then
killTimer(p_timer[source])
end
end )
addEventHandler("onElementDestroy", getRootElement(),
function ()
if getElementType(source) == "vehicle" then
if(p_lights[source] == 1) then
killTimer(p_timer[source])
end
end
end)
Alles anzeigen