Jump to content

[HELP] setVehicleEngineState problem!


griff316

Recommended Posts

No matter how i try, its not working...

function engine (player, command)
  if isPedInVehicle(player) then
    local vehicle = getPedOccupiedVehicle(player)
    local state = getVehicleEngineState(vehicle)
    setVehicleEngineState(vehicle, not state)
  else return false end
end
addCommandHandler("engine", engine)

 

Link to comment
function toggleEngine(thePlayer)
    if isPedInVehicle(player) then
	    local theVehicle = getPedOccupiedVehicle(thePlayer)
        if getPedOccupiedVehicleSeat(thePlayer) == 0 then
		   if (getVehicleEngineState(theVehicle) == true) then
		       setVehicleEngineState(theVehicle, false)
	       else
		      setVehicleEngineState(theVehicle, true)
		   end
		else
		   outputChatBox("You but be the driver for use that command!", thePlayer, 255, 0, 0)
       end
	else
	    outputChatBox("You must be in a vehicle to use that command!", thePlayer, 255, 0, 0)
	end
end
addCommandHandler("engine", toggleEnginea)

 

Edited by Dimos7
Link to comment
20 minutes ago, Dimos7 said:

function toggleEngine(thePlayer)
    if isPedInVehicle(player) then
	    local theVehicle = getPedOccupiedVehicle(thePlayer)
        if getPedOccupiedVehicleSeat(thePlayer) == 0 then
		   if (getVehicleEngineState(theVehicle) == true) then
		       setVehicleEngineState(theVehicle, false)
	       else
		      setVehicleEngineState(theVehicle, true)
		   end
		else
		   outputChatBox("You but be the driver for use that command!", thePlayer, 255, 0, 0)
       end
	else
	    outputChatBox("You must be in a vehicle to use that command!", thePlayer, 255, 0, 0)
	end
end
addCommandHandler("engine", toggleEnginea)

 

 

Your code is to long also you have an extra 'a' in the addCommandHandler function in the function name part.

Link to comment

Includes the chat box messages, and semi compact format.

function engine ( aPlayer )
local vehicle = getPedOccupiedVehicle ( aPlayer )
  if not vehicle then outputChatBox("You must be in a vehicle",aPlayer) return end
		setVehicleEngineState ( getPedOccupiedVehicle ( aPlayer ),not getVehicleEngineState (vehicle) )
	if getVehicleEngineState (vehicle) then
		outputChatBox("Engine has been turned on",aPlayer)
	else
		outputChatBox("Engine has been turned off",aPlayer)
	end
end
addCommandHandler ( 'engine',engine )

Could compact it more using an and statement though.

Edited by CodyL
Link to comment

Just a thought, but if the codes posted above do not work for you... maybe there's another resource forcing the engine on? Are you trying the resource in a default server (no other resource other than defaults ones)? If not, try stopping all resources. Check if it works. If it works, start one resource at a time and check everytime if it works. If you have lots of resources, you can start them in blocks, and when you encounter the problem, probably the resource that is causing the problem is in that block of resources. If no resource causes problem (it does not work even if all non-default res are stopped) then i'm missing something :(

 

1 minute ago, iPrestege said:

You mean that when you enter the vehicle and the engine was off and it start?

If i understood correctly, when he turns off the engine it automatically turns on again. 

@griff316 but what @iPrestege said lead me to think one thing: what happens if you (via script) turn off the engine when you are not in the vehicle (if you are testing while in it) (or inside it if you are testing when you are not in the vehicle)? (do not do this if you do not want to, it's optional. Do what i wrote above first)

Edited by LoPollo
  • Like 1
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...