griff316 Posted November 12, 2016 Share Posted November 12, 2016 Hey guys! I've a problem with setVehicleEngineState. When I use it to turn off the engine, the engine immediately turns on and I don't know why. I hope you can help me. (Sorry for my bad english:S) Link to comment
Gravestone Posted November 12, 2016 Share Posted November 12, 2016 You must provide us with the code you're using. Link to comment
griff316 Posted November 12, 2016 Author Share Posted November 12, 2016 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
Gordon_G Posted November 12, 2016 Share Posted November 12, 2016 (edited) Hello, in LUA the return is like end or break when you use for. So, remove the end after the return false. Edited November 12, 2016 by Gordon_G Link to comment
iPrestege Posted November 12, 2016 Share Posted November 12, 2016 Try this ; function engine ( aPlayer ) if not isPedInVehicle ( aPlayer ) then return end setVehicleEngineState ( getPedOccupiedVehicle ( aPlayer ),not getVehicleEngineState ( getPedOccupiedVehicle ( aPlayer ) ) ) end addCommandHandler ( 'engine',engine ) Link to comment
Dimos7 Posted November 12, 2016 Share Posted November 12, 2016 (edited) 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 November 12, 2016 by Dimos7 Link to comment
iPrestege Posted November 12, 2016 Share Posted November 12, 2016 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
Captain Cody Posted November 12, 2016 Share Posted November 12, 2016 (edited) 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 November 12, 2016 by CodyL Link to comment
griff316 Posted November 13, 2016 Author Share Posted November 13, 2016 (edited) I tried all of your codes, but the problem is same. Im thikning maybe a basic resource in mta, or similar. I dont know. Any idea? Edited November 13, 2016 by griff316 Link to comment
iPrestege Posted November 13, 2016 Share Posted November 13, 2016 What's the problem explain more and better please because i've tried mine and Cody Code's and work just fine the engine off and on . Link to comment
griff316 Posted November 13, 2016 Author Share Posted November 13, 2016 When the engine turns off, immediately i hear the basic engine start sound and the engine turns on. It happens every second time. So it detect, but the engine didnt stop. Link to comment
iPrestege Posted November 13, 2016 Share Posted November 13, 2016 You mean that when you enter the vehicle and the engine was off and it start? Link to comment
LoPollo Posted November 13, 2016 Share Posted November 13, 2016 (edited) 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 November 13, 2016 by LoPollo 1 Link to comment
griff316 Posted November 13, 2016 Author Share Posted November 13, 2016 I'll try what you say @LoPollo. And the same thing, if Im in the vehicle or not and I turns off the engine it automatically turns on. 1 Link to comment
griff316 Posted November 13, 2016 Author Share Posted November 13, 2016 Thanks all of your help, its solved. I written a car script 1 years ago, wich is prevent car blow and I forgot that I written a line to in wich turns the engine on when vehicle health is more then the min value. One more time thanks, its my fault, sorry. 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