Jump to content

[HELP] Engine on/off


NyiTz

Recommended Posts

Posted

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)

 

  • Moderators
Posted

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)

 

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

Posted
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)

 

Posted
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 :(

  • Like 1
Posted
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.

  • Like 1
Posted
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)

 

  • Like 1
Posted
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.

  • Like 1
Posted (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 by Dimos7
Posted
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. :(

  • Thanks 1
Posted (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 by Ab-47
  • Thanks 1
Posted
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.

  • Thanks 1
Posted
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 ```

Posted
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 '-

  • Thanks 1
Posted
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 ❤️ 

  • Thanks 1
Posted
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. 

  • Thanks 1
Posted
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 

  • Thanks 1
Posted

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!

  • Thanks 1

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