NextGenRP Posted April 30, 2012 Share Posted April 30, 2012 When a player enters a vehicle the engine automatically comes on, How can i stop this? Link to comment
Castillo Posted April 30, 2012 Share Posted April 30, 2012 Turn off the engine when a player enter the vehicle: setVehicleEngineState combined with the event: onVehicleEnter. Link to comment
Kenix Posted April 30, 2012 Share Posted April 30, 2012 (edited) Turn off the engine when a player enter the vehicle: setVehicleEngineState combined with the event: onVehicleEnter. setVehicleEngineState On wiki already have example with this function. function turnEngineOff ( theVehicle, leftSeat, jackerPlayer ) -- if it's the driver who got out, and he was not jacked, if leftSeat == 0 and not jackerPlayer then -- turn off the engine setVehicleEngineState ( theVehicle, false ) end end -- add 'turnEngineOff' as a handler for "onPlayerExitVehicle" addEventHandler ( "onPlayerVehicleExit", getRootElement ( ), turnEngineOff ) Just change to 'onPlayerVehicleEnter' Edited April 30, 2012 by Guest Link to comment
NextGenRP Posted April 30, 2012 Author Share Posted April 30, 2012 Yeah i have made it like this; for k, i in ipairs(getElementsByType("vehicle")) do setVehicleEngineState(i,false) setVehicleLocked(i,true) end But when the player gets in the vehicle it just turns back on. function enter(player,seat) if seat == 0 then local eniginestate = getVehicleEngineState(source) if eniginestate == false then outputChatBox("Press J to start the "..getVehicleName(source).."'s engine.",player,255,255,0) end end end addEventHandler("onVehicleEnter", getRootElement(), enter) It will output to the chat but then the engine just comes on. Link to comment
Scooby Posted April 30, 2012 Share Posted April 30, 2012 thats because u didnt turn it off once they enter the vehicle. just add: setVehicleEngineState (source, false) before u output the text. Link to comment
NextGenRP Posted April 30, 2012 Author Share Posted April 30, 2012 Changed it to this; function enter(player,seat) if seat == 0 then local eniginestate = getVehicleEngineState(source) if eniginestate == false then setVehicleEngineState(source,false) outputChatBox("Press J to start the "..getVehicleName(source).."'s engine.",player,255,255,0) end end end addEventHandler("onVehicleEnter", getRootElement(), enter) Now it doesn't output and the engine still starts Link to comment
Castillo Posted April 30, 2012 Share Posted April 30, 2012 function enter ( player, seat ) if ( seat == 0 ) then setVehicleEngineState ( source, false ) local eniginestate = getVehicleEngineState ( source ) if ( eniginestate == false ) then outputChatBox ( "Press J to start the ".. getVehicleName ( source ) .."'s engine.", player, 255, 255, 0 ) end end end addEventHandler ( "onVehicleEnter", getRootElement(), enter ) Link to comment
Kenix Posted April 30, 2012 Share Posted April 30, 2012 Tested function setVehicleEngineOff ( pVehicle, nLeftSeat, pJackerPlayer ) if nLeftSeat == 0 and not pJackerPlayer then -- turn off the engine outputChatBox ( "Press J to start the ".. getVehicleName ( pVehicle ) .."'s engine.", source, 255, 255, 0 ) setVehicleEngineState ( pVehicle, false ) end end addEventHandler ( 'onPlayerVehicleEnter', root, setVehicleEngineOff ) Link to comment
NextGenRP Posted May 1, 2012 Author Share Posted May 1, 2012 Thanks guys i managed to get it working, I have another problem though im trying to create a /handbrake and im using setVehicleFrozen but if i bind it and jump off something then press the key it will freeze my vehicle in mid air, Is there anything else i can use other than setVehicleFrozen? Link to comment
Castillo Posted May 1, 2012 Share Posted May 1, 2012 You want to set the velocity of the vehicle to 0? if so, use setElementVelocity. 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