Jump to content

[Problem] police light (flashing light)


Skav

Recommended Posts

Hello, i try to do my own ELS and i have a problem. I create this code (client site): 

local zmienna = 0
local elm = 0
local timer = nil
local lp = nil
local ll = nil
local czas = 500

--[[function czest(player,CommandName,wartosc)
 
tonumber(wartosc)
czas = wartosc
end
addCommandHandler("hz", czest)--]]

function swiatla(source)
	for i,player in ipairs(getElementsByType("player")) do
			local vehicle = getPedOccupiedVehicle ( player )
		
		        	if zmienna == 0 then
						zmienna = 1
						destroyElement ( ll )
						lp = createMarker ( 0, 0, 0, "corona", 0.5, 255, 0, 0, 170 )
						attachElements (lp, vehicle, -0.8, 2.2, 0)
					    setVehicleLightState ( vehicle, 0, 0 )
					    setVehicleLightState ( vehicle, 1, 1 )
				    	setVehicleHeadLightColor(vehicle,255,0,0)
			    	else
						destroyElement ( lp )
						ll = createMarker ( 0, 0, 0, "corona", 0.5, 0, 0, 255, 170 )
						attachElements (ll, vehicle, 0.8, 2.2, 0)
				    	setVehicleLightState ( vehicle, 0, 1 )
				    	setVehicleLightState ( vehicle, 1, 0 )
				    	setVehicleHeadLightColor(vehicle,0,0,255)
						zmienna = 0
			    	end
	end
end

addCommandHandler("els", function ()
if elm == 0 then
elm = 1
timer = setTimer ( swiatla, czas, 0)	
elseif elm == 1 then
elm = 0
killTimer (timer)
for i,player in ipairs(getElementsByType("player")) do
local vehicle = getPedOccupiedVehicle(player)
setVehicleLightState ( vehicle, 0, 0 )
setVehicleLightState ( vehicle, 1, 0 )
setVehicleLightState ( vehicle, 2, 0 )
setVehicleLightState ( vehicle, 3, 0 )
setVehicleHeadLightColor(vehicle,255,255,255)
destroyElement ( lp )
destroyElement ( ll )
end
end
end)

		

In this script its work if I was alone in a server, if someone join in debugscript 3 i have a error like: setVehicleLightState argument 1 is empty or got boolean.

So i do a another code 

setVehicleLightState

local zmienna = 0
local elm = 0
local timer = nil
local lp = nil
local ll = nil
local czas = 500

--[[function czest(player,CommandName,wartosc)
 
tonumber(wartosc)
czas = wartosc
end
addCommandHandler("hz", czest)--]]

function swiatla(source)
			local vehicle = getPedOccupiedVehicle ( source )
		
		        	if zmienna == 0 then
						zmienna = 1
						destroyElement ( ll )
						lp = createMarker ( 0, 0, 0, "corona", 0.5, 255, 0, 0, 170 )
						attachElements (lp, vehicle, -0.8, 2.2, 0)
					    setVehicleLightState ( vehicle, 0, 0 )
					    setVehicleLightState ( vehicle, 1, 1 )
				    	setVehicleHeadLightColor(vehicle,255,0,0)
			    	else
						destroyElement ( lp )
						ll = createMarker ( 0, 0, 0, "corona", 0.5, 0, 0, 255, 170 )
						attachElements (ll, vehicle, 0.8, 2.2, 0)
				    	setVehicleLightState ( vehicle, 0, 1 )
				    	setVehicleLightState ( vehicle, 1, 0 )
				    	setVehicleHeadLightColor(vehicle,0,0,255)
						zmienna = 0
			    	end
end

addCommandHandler("els", function ()
if elm == 0 then
elm = 1
timer = setTimer ( swiatla, czas, 0)	
elseif elm == 1 then
elm = 0
killTimer (timer)
for i,player in ipairs(getElementsByType("player")) do
local vehicle = getPedOccupiedVehicle(player)
setVehicleLightState ( vehicle, 0, 0 )
setVehicleLightState ( vehicle, 1, 0 )
setVehicleLightState ( vehicle, 2, 0 )
setVehicleLightState ( vehicle, 3, 0 )
setVehicleHeadLightColor(vehicle,255,255,255)
destroyElement ( lp )
destroyElement ( ll )
end
end
end)

		

And this don't work. erorr like this:setVehicleLightState [expected element at argument 1, got boolean.

So what i should do to repair this? I want a flashing light work in car when i on car and when i leave from car. And 1 have a 2st question, what should i do if i want a change a freq of flash light? its my try to do this:

function czest(player,CommandName,wartosc)
 
tonumber(wartosc)
czas = wartosc
end
addCommandHandler("hz", czest)

("wartosc" its a whats layer type in chat for example: /hz 100, the "czas" is a stock value (500, its on 6 line of code). I wanna change a "czas" value to a "wartosc" vaule but if i do this i have error: setTimer [expected number at argument 2, got nil]

Sorry for my english

Thanks

Link to comment
  • Moderators
Quote

And this don't work. erorr like this:setVehicleLightState [expected element at argument 1, got boolean.

If you are not inside a vehicle, there is no vehicle you can point at. To solve that issue:

local vehicle = getPedOccupiedVehicle ( player )
if vehicle then
-- the rest of the code
end

--------------------------------------------------

--------------------------------------------------

local vehicle = getPedOccupiedVehicle ( source )
if vehicle then
-- the rest of the code
end

 


 

function czest(player,CommandName,wartosc)

    tonumber(wartosc)

    czas = wartosc

end

addCommandHandler("hz", czest)

 

function czest(player,CommandName,wartosc)
	wartosc = tonumber(wartosc)
  	if wartosc then
		czas = wartosc
   	end
end
addCommandHandler("hz", czest)

 

Edited by IIYAMA
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...