Jump to content

[HELP] System Seat belt system


Recommended Posts

I have problems with this code, the problem happens that the passenger 
can be lowered even if he is wearing a seat belt. Everything else works fine.

 

		 local SizeX, SizeY = guiGetScreenSize()
		 local px,py = 1680,1050
		 local x,y = (SizeX/px), (SizeY/py)

		 local Fade = true
		 local Pulso = 0
		 
		 -- Cinturón
		 local key = "B"      
		 local interval = 1.05 

		 local moto = {
		 [522]=true,[521]=true,[461]=true,[462]=true,[463]=true,
		 [586]=true,[581]=true,[468]=true,[471]=true,[523]=true,
		 [448]=true,[481]=true,[510]=true,[509]=true 
		 }

		 local boat = { 
		 [430]=true,[446]=true,[452]=true,[453]=true,[454]=true,
		 [472]=true,[473]=true,[484]=true,[493]=true,[595]=true 
		 }

		 local air = { 
		 [417]=true,[425]=true,[447]=true,[460]=true,[469]=true,
		 [476]=true,[487]=true,[488]=true,[497]=true,[511]=true,
		 [512]=true,[513]=true,[519]=true,[520]=true,[548]=true,
		 [553]=true,[563]=true,[577]=true,[592]=true,[593]=true 
		 }

function toggleRemen()
		 if getElementInterior(getLocalPlayer()) == 0 and getElementDimension(getLocalPlayer()) == 0 then
         local veh = getPedOccupiedVehicle(getLocalPlayer()) 
         if veh then		 	 	 	 	 	   
         if (moto [getElementModel (veh)]) then 
         elseif (boat [getElementModel (veh)]) then 
         elseif (air [getElementModel (veh)]) then
         else
		 
	 	 if Fade then
		 Pulso = Pulso - 20
		 if (Pulso <= 0) then
	     Pulso = 0
		 Fade = false
		 end
		 else
		 Pulso = Pulso + 20
		 if (Pulso >= 255) then
		 Pulso = 255
		 Fade = true
		 end			
		 end			 
		 
         if getElementData(getLocalPlayer(),"remeshok") == "Cinturón_abrochado" then
         dxDrawImage(SizeX - 410,SizeY - 83, 30, 22,"Imagenes/Vehiculos/con-cinturon.png",0.0,0.0,0.0,tocolor(255,255,255,255),false)
         setElementData(getLocalPlayer(),"remeshok","Cinturón_desabrochado")
		 triggerEvent("Información", getLocalPlayer(), "Inventory", "¡Cinturón desabrochado!", 0, 255, 0)
         else
         setElementData(getLocalPlayer(),"remeshok","Cinturón_abrochado")
		 triggerEvent("Información", getLocalPlayer(), "Inventory", "¡Cinturón abrochado!", 0, 255, 0)
         dxDrawImage(SizeX - 410,SizeY - 83, 30, 22,"Imagenes/Vehiculos/sin-cinturon.png",0.0,0.0,0.0,tocolor(255,255,255,Pulso),false)
        	   	 end
             end
         end
     end
end
bindKey(key, "down", toggleRemen)
addCommandHandler("cinturon", toggleRemen)

addEvent("Denegar",true)
addEventHandler("Denegar",getRootElement(),function()
		 playSound("Sonidos/Denegar/Denegar.mp3")		 		 
end)

function updateCamera()
		 if getElementInterior(getLocalPlayer()) == 0 and getElementDimension(getLocalPlayer()) == 0 then
         local veh = getPedOccupiedVehicle(getLocalPlayer())
         if veh then
         if (moto [getElementModel (veh)]) then
         elseif (boat [getElementModel (veh)]) then
         elseif (air [getElementModel (veh)]) then
         else
		 
	 	 if Fade then
		 Pulso = Pulso - 20
		 if (Pulso <= 0) then
	     Pulso = 0
		 Fade = false
		 end
		 else
		 Pulso = Pulso + 20
		 if (Pulso >= 255) then
		 Pulso = 255
		 Fade = true
		 end			
		 end			 
		 
         if getElementData(getLocalPlayer(),"remeshok") == "Cinturón_abrochado" then
         dxDrawImage(SizeX - 410,SizeY - 83, 30, 22,"Imagenes/Vehiculos/con-cinturon.png",0.0,0.0,0.0,tocolor(255,255,255,255),false)
         else
         dxDrawImage(SizeX - 410,SizeY - 83, 30, 22,"Imagenes/Vehiculos/sin-cinturon.png",0.0,0.0,0.0,tocolor(255,255,255,Pulso),false)
         end
         end
         else
         setElementData(getLocalPlayer(),"remeshok","Cinturón_desabrochado")
         end
     end
end
addEventHandler("onClientRender", root, updateCamera)

function handleVehicleDamage(attacker, weapon, loss, x, y, z, tyre)
		 local player = getVehicleOccupant(source,0)
		 if (moto [getElementModel (source)]) then
		 elseif (boat [getElementModel (source)]) then
		 elseif (air [getElementModel (source)]) then
		 else
         if tonumber(loss) > 170 then
         if getElementData(getLocalPlayer(),"remeshok") == "Cinturón_desabrochado" then
         triggerServerEvent("removeMe", player, player) 
             end
         end
     end
end
addEventHandler("onClientVehicleDamage", root, handleVehicleDamage)

setTimer(function()
		 local veh = getPedOccupiedVehicle(getLocalPlayer())
		 if veh then
         if getElementData(getLocalPlayer(),"remeshok") == "Cinturón_desabrochado" then
         if (moto [getElementModel (veh)]) then
         elseif (boat [getElementModel (veh)]) then
         elseif (air [getElementModel (veh)]) then
         else
         playSound("Sonidos/Alarma-cinturon/Cinturon.mp3",false)
             end
         end
     end
end, interval * 1000 , 0)

 

Edited by Maruchan
Link to comment
  • Patrick changed the title to [HELP] System Seat belt system

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...