NyiTz Posted March 8, 2019 Share Posted March 8, 2019 Hi guys, i have a problem that i need help to fix it. So in this script i have lights and engine to turn off or on, but the lights works fine and engine just give me a message and dont set to engine off or on, basically engine dont work. With addCommandHandler everything works, but what i want is bindKeys. Thanks in advance for any help! --//Engine On / Off function engine (src, cmd) if getPedOccupiedVehicle (src) and getPedOccupiedVehicleSeat (src) == 0 then local vehicle = getPedOccupiedVehicle (src) if getVehicleEngineState (vehicle) then setVehicleEngineState (vehicle, false) outputChatBox ("Motor ligado!", src, 255, 0, 0) else setVehicleEngineState (vehicle, true) outputChatBox ("Motor desligado!", src, 0, 255, 0) end else return false end end --addCommandHandler ("motor", engine) addEventHandler ("onVehicleStartEnter", getRootElement(), function() bindKey (source, "j", "down", engine) end) --//-- --//Vehicle Lights function lights (src, cmd) if getPedOccupiedVehicle (src) and getPedOccupiedVehicleSeat (src) == 0 then local vehicle = getPedOccupiedVehicle (src) if getVehicleOverrideLights (vehicle) == 1 then setVehicleOverrideLights (vehicle, 2) outputChatBox ("Luzes ligadas!", src, 0, 255, 0) else setVehicleOverrideLights (vehicle, 1) outputChatBox ("Luzes desligadas!", src, 255, 0, 0) end else return false end end --addCommandHandler ("luzes", lights) addEventHandler ("onPlayerVehicleEnter", getRootElement(), function() bindKey (source, "l", "down", lights) end) Link to comment
Moderators Patrick Posted March 8, 2019 Moderators Share Posted March 8, 2019 At the onVehicleStartEnter event source is the vehicle and not the player. The event first argument is the player. addEventHandler ("onVehicleStartEnter", getRootElement(), function(enteringPlayer) bindKey (enteringPlayer, "j", "down", engine) end) Link to comment
NyiTz Posted March 8, 2019 Author Share Posted March 8, 2019 5 hours ago, stPatrick said: At the onVehicleStartEnter event source is the vehicle and not the player. The event first argument is the player. addEventHandler ("onVehicleStartEnter", getRootElement(), function(enteringPlayer) bindKey (enteringPlayer, "j", "down", engine) end) Unfortunately didn't work, only the message appear. Link to comment
Dimos7 Posted March 8, 2019 Share Posted March 8, 2019 addEventHandler("onPlayerLogin", root, function() bindKey(source, "l", "down", lights) bindKey(source, "j", "down", engine) end) addEventHandler("onResourceStart", resourceRoot, function() for _, v in pairs (getElementsByType("player")) do bindKey(v, "l", "down", lights) bindKey(v, "j", "down", engine) end end) --//Engine On / Off function engine (src, cmd) if getPedOccupiedVehicle (src) and getPedOccupiedVehicleSeat (src) == 0 then local vehicle = getPedOccupiedVehicle (src) if getVehicleEngineState (vehicle) then setVehicleEngineState (vehicle, false) outputChatBox ("Motor ligado!", src, 255, 0, 0) else setVehicleEngineState (vehicle, true) outputChatBox ("Motor desligado!", src, 0, 255, 0) end else return false end end addCommandHandler ("motor", engine) --//-- --//Vehicle Lights function lights (src, cmd) if getPedOccupiedVehicle (src) and getPedOccupiedVehicleSeat (src) == 0 then local vehicle = getPedOccupiedVehicle (src) if getVehicleOverrideLights (vehicle) == 1 then setVehicleOverrideLights (vehicle, 2) outputChatBox ("Luzes ligadas!", src, 0, 255, 0) else setVehicleOverrideLights (vehicle, 1) outputChatBox ("Luzes desligadas!", src, 255, 0, 0) end else return false end end addCommandHandler ("luzes", lights) Link to comment
PashaBiceps Posted March 8, 2019 Share Posted March 8, 2019 1 hour ago, Dimos7 said: addEventHandler("onPlayerLogin", root, function() bindKey(source, "l", "down", lights) bindKey(source, "j", "down", engine) end) addEventHandler("onResourceStart", resourceRoot, function() for _, v in pairs (getElementsByType("player")) do bindKey(v, "l", "down", lights) bindKey(v, "j", "down", engine) end end) --//Engine On / Off function engine (src, cmd) if getPedOccupiedVehicle (src) and getPedOccupiedVehicleSeat (src) == 0 then local vehicle = getPedOccupiedVehicle (src) if getVehicleEngineState (vehicle) then setVehicleEngineState (vehicle, false) outputChatBox ("Motor ligado!", src, 255, 0, 0) else setVehicleEngineState (vehicle, true) outputChatBox ("Motor desligado!", src, 0, 255, 0) end else return false end end addCommandHandler ("motor", engine) --//-- --//Vehicle Lights function lights (src, cmd) if getPedOccupiedVehicle (src) and getPedOccupiedVehicleSeat (src) == 0 then local vehicle = getPedOccupiedVehicle (src) if getVehicleOverrideLights (vehicle) == 1 then setVehicleOverrideLights (vehicle, 2) outputChatBox ("Luzes ligadas!", src, 0, 255, 0) else setVehicleOverrideLights (vehicle, 1) outputChatBox ("Luzes desligadas!", src, 255, 0, 0) end else return false end end addCommandHandler ("luzes", lights) Unfortunately, now nothing working 1 Link to comment
PashaBiceps Posted March 9, 2019 Share Posted March 9, 2019 2 hours ago, Dimos7 said: try /debugscript 3 and see Gave me this error in addCommandHandler line addCommandHandler ("luzes", lights) LOADED FAILED: unexpected symbor near ' I tried to remove the addCommandHandler, and the lights works again but the engine just give me the messages, didn't work. 1 Link to comment
Dimos7 Posted March 9, 2019 Share Posted March 9, 2019 addEventHandler("onPlayerLogin", root, function() bindKey(source, "l", "down", lights) bindKey(source, "j", "down", engine) end) addEventHandler("onResourceStart", resourceRoot, function() for _, v in pairs (getElementsByType("player")) do bindKey(v, "l", "down", lights) bindKey(v, "j", "down", engine) end end) --//Engine On / Off function engine (src, cmd) if getPedOccupiedVehicle (src) and getPedOccupiedVehicleSeat (src) == 0 then local vehicle = getPedOccupiedVehicle (src) if getVehicleEngineState (vehicle) == true then setVehicleEngineState (vehicle, false) outputChatBox ("Motor ligado!", src, 255, 0, 0) else setVehicleEngineState (vehicle, true) outputChatBox ("Motor desligado!", src, 0, 255, 0) end else return false end end addCommandHandler ("motor", engine) --//-- --//Vehicle Lights function lights (src, cmd) if getPedOccupiedVehicle (src) and getPedOccupiedVehicleSeat (src) == 0 then local vehicle = getPedOccupiedVehicle (src) if getVehicleOverrideLights (vehicle) == 1 then setVehicleOverrideLights (vehicle, 2) outputChatBox ("Luzes ligadas!", src, 0, 255, 0) else setVehicleOverrideLights (vehicle, 1) outputChatBox ("Luzes desligadas!", src, 255, 0, 0) end else return false end end addCommandHandler ("luzes", lights) 1 Link to comment
PashaBiceps Posted March 9, 2019 Share Posted March 9, 2019 15 minutes ago, Dimos7 said: addEventHandler("onPlayerLogin", root, function() bindKey(source, "l", "down", lights) bindKey(source, "j", "down", engine) end) addEventHandler("onResourceStart", resourceRoot, function() for _, v in pairs (getElementsByType("player")) do bindKey(v, "l", "down", lights) bindKey(v, "j", "down", engine) end end) --//Engine On / Off function engine (src, cmd) if getPedOccupiedVehicle (src) and getPedOccupiedVehicleSeat (src) == 0 then local vehicle = getPedOccupiedVehicle (src) if getVehicleEngineState (vehicle) == true then setVehicleEngineState (vehicle, false) outputChatBox ("Motor ligado!", src, 255, 0, 0) else setVehicleEngineState (vehicle, true) outputChatBox ("Motor desligado!", src, 0, 255, 0) end else return false end end addCommandHandler ("motor", engine) --//-- --//Vehicle Lights function lights (src, cmd) if getPedOccupiedVehicle (src) and getPedOccupiedVehicleSeat (src) == 0 then local vehicle = getPedOccupiedVehicle (src) if getVehicleOverrideLights (vehicle) == 1 then setVehicleOverrideLights (vehicle, 2) outputChatBox ("Luzes ligadas!", src, 0, 255, 0) else setVehicleOverrideLights (vehicle, 1) outputChatBox ("Luzes desligadas!", src, 255, 0, 0) end else return false end end addCommandHandler ("luzes", lights) Now, don't give any error. Lights works well, but the engine just give me the message, physically nothing happens on engine. Thanks u so much in advance for helping me with this. 1 Link to comment
Dimos7 Posted March 9, 2019 Share Posted March 9, 2019 (edited) addEventHandler("onPlayerLogin", root, function() bindKey(source, "l", "down", lights) bindKey(source, "j", "down", engine) end) addEventHandler("onResourceStart", resourceRoot, function() for _, v in pairs (getElementsByType("player")) do bindKey(v, "l", "down", lights) bindKey(v, "j", "down", engine) end end) --//Engine On / Off function engine (src, cmd) if isPedInVehicle(src) and getPedOccupiedVehicleSeat (src) == 0 then local vehicle = getPedOccupiedVehicle (src) if getVehicleEngineState (vehicle) == true then setVehicleEngineState (vehicle, false) outputChatBox ("Motor ligado!", src, 255, 0, 0) else setVehicleEngineState (vehicle, true) outputChatBox ("Motor desligado!", src, 0, 255, 0) end else return false end end addCommandHandler ("motor", engine) --//-- --//Vehicle Lights function lights (src, cmd) if isPedInVehicle(src) and getPedOccupiedVehicleSeat (src) == 0 then local vehicle = getPedOccupiedVehicle (src) if getVehicleOverrideLights (vehicle) == 1 then setVehicleOverrideLights (vehicle, 2) outputChatBox ("Luzes ligadas!", src, 0, 255, 0) else setVehicleOverrideLights (vehicle, 1) outputChatBox ("Luzes desligadas!", src, 255, 0, 0) end else return false end end addCommandHandler ("luzes", lights) Edited March 9, 2019 by Dimos7 Link to comment
PashaBiceps Posted March 9, 2019 Share Posted March 9, 2019 27 minutes ago, Dimos7 said: addEventHandler("onPlayerLogin", root, function() bindKey(source, "l", "down", lights) bindKey(source, "j", "down", engine) end) addEventHandler("onResourceStart", resourceRoot, function() for _, v in pairs (getElementsByType("player")) do bindKey(v, "l", "down", lights) bindKey(v, "j", "down", engine) end end) --//Engine On / Off function engine (src, cmd) if isPedInVehicle(src) and getPedOccupiedVehicleSeat (src) == 0 then local vehicle = getPedOccupiedVehicle (src) if getVehicleEngineState (vehicle) == true then setVehicleEngineState (vehicle, false) outputChatBox ("Motor ligado!", src, 255, 0, 0) else setVehicleEngineState (vehicle, true) outputChatBox ("Motor desligado!", src, 0, 255, 0) end else return false end end addCommandHandler ("motor", engine) --//-- --//Vehicle Lights function lights (src, cmd) if isPedInVehicle(src) and getPedOccupiedVehicleSeat (src) == 0 then local vehicle = getPedOccupiedVehicle (src) if getVehicleOverrideLights (vehicle) == 1 then setVehicleOverrideLights (vehicle, 2) outputChatBox ("Luzes ligadas!", src, 0, 255, 0) else setVehicleOverrideLights (vehicle, 1) outputChatBox ("Luzes desligadas!", src, 255, 0, 0) end else return false end end addCommandHandler ("luzes", lights) The same, nothing changed. 1 Link to comment
Ab-47 Posted March 11, 2019 Share Posted March 11, 2019 (edited) On 09/03/2019 at 16:44, Dimos7 said: Wired I just tested the script in my local server, it works perfectly lol. I feel he may have duplicated his resource by accidently leaving the old one running... On 09/03/2019 at 16:22, GodKraken said: The same, nothing changed. What file type have you saved it under? Have you made sure it's under type server side? Edited March 11, 2019 by Ab-47 1 Link to comment
PashaBiceps Posted March 11, 2019 Share Posted March 11, 2019 7 hours ago, Ab-47 said: Acabei de testar o script no meu servidor local, ele funciona perfeitamente lol. Eu sinto que ele pode ter duplicado seu recurso acidentalmente deixando o antigo funcionando ... Em qual tipo de arquivo você salvou? Você se certificou de que está sob o lado do servidor do tipo ? Thanks for ur anwser! Yes, im working on server side and i tried copy and save the script 10 times. Lights works fine but the engine just give me a message, listening the sound of the car seems like the engine turn on, but dont turn off. 1 Link to comment
KillerX Posted March 11, 2019 Share Posted March 11, 2019 On 08/03/2019 at 14:19, GodKraken said: Gave me this error in addCommandHandler line addCommandHandler ("luzes", lights) LOADED FAILED: unexpected symbor near ' I tried to remove the addCommandHandler, and the lights works again but the engine just give me the messages, didn't work. Try to rewrite this line with your hand and without copying because at times the site copies strange characters like this character ``` Link to comment
PashaBiceps Posted March 11, 2019 Share Posted March 11, 2019 2 hours ago, KillerX said: Try to rewrite this line with your hand and without copying because at times the site copies strange characters like this character ``` This error is already solved yesterday, now is another problem '- 1 Link to comment
PashaBiceps Posted March 11, 2019 Share Posted March 11, 2019 6 minutes ago, Dimos7 said: What is the problem now? Like i said, everything works perfectly, but the engine off the car don't turn off, unfortunately. I don't understand. Thanks to all for helping until now 1 Link to comment
Dimos7 Posted March 11, 2019 Share Posted March 11, 2019 Can you take ss when do it i want to see something also i want be on back view of the vehicle 1 Link to comment
Ab-47 Posted March 12, 2019 Share Posted March 12, 2019 7 hours ago, GodKraken said: Like i said, everything works perfectly, but the engine off the car don't turn off, unfortunately. I don't understand. Thanks to all for helping until now Bro, it's not the script, the engine turns of completely fine as-well as the lights working. You must have another script interfering with the running of engines, try your local server rather than your main server if you're using that. Otherwise in your local server, just make sure no other script is running apart from that one script you're using this code in. Then let us know what happens. 1 Link to comment
PashaBiceps Posted March 12, 2019 Share Posted March 12, 2019 13 hours ago, Ab-47 said: Bro, it's not the script, the engine turns of completely fine as-well as the lights working. You must have another script interfering with the running of engines, try your local server rather than your main server if you're using that. Otherwise in your local server, just make sure no other script is running apart from that one script you're using this code in. Then let us know what happens. You are totally right, was my mistake and i need to say sorry. Script awesome! I had a script interfering ! Thanks guys <3 1 Link to comment
Ab-47 Posted March 12, 2019 Share Posted March 12, 2019 You're welcome just try and learn from that and it'll help you in many cases working with allot of resources. Best of luck! 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now