zapezel Posted June 12, 2010 Share Posted June 12, 2010 I'm begginer :"> .I made a script to stop the engine when i press a key but didn't work local root = getRootElement () local thisResourceRoot = getResourceRootElement(getThisResource()) function thisResourceStart () local players = getElementsByType ( "player" ) bindKey ( source, "1", "down", stopEngine, "Lights on/off" ) end addEventHandler ( "onResourceStart", thisResourceRoot, thisResourceStart ) function stopEngine ( player, key, state ) if ( getPedOccupiedVehicleSeat ( player ) == 0 ) then local vehicle = getPedOccupiedVehicle ( player ) if ( getVehicleEngineState ( vehicle ) == true ) then setVehicleEngineState ( vehicle, false) else setVehicleEngineState ( vehicle, true ) end end end Link to comment
DiSaMe Posted June 12, 2010 Share Posted June 12, 2010 When resource starts, to bind the key for all players, you must loop through them. function thisResourceStart () local players = getElementsByType ( "player" ) for _,this_player in ipairs(players) do bindKey ( this_player, "1", "down", stopEngine, "Lights on/off" ) end end To bind the key for players who join when resource has already started, put bindKey into function triggered by onPlayerJoin event. function playerJoined() bindKey ( source, "1", "down", stopEngine, "Lights on/off" ) end addEventHandler("onPlayerJoin",root,playerJoined) Function stopEngine seems to be fine, but we can shorten its code. function stopEngine ( player, key, state ) if getPedOccupiedVehicleSeat ( player ) == 0 then local vehicle = getPedOccupiedVehicle ( player ) setVehicleEngineState ( vehicle, not getVehicleEngineState ( vehicle ) ) end end By the way, I don't see what does that function argument "Lights on/off" mean Link to comment
zapezel Posted June 14, 2010 Author Share Posted June 14, 2010 I don't know even all the words from english , I'm from Romania and my english lessons are very poor :-<. I need to replace "Light" with "motor or engine" ! Thanks a lot man ! I apreciate your help ! Regards from Zapezel Regards from Romania Link to comment
zapezel Posted June 14, 2010 Author Share Posted June 14, 2010 function thisResourceStart () local players = getElementsByType ( "player" ) for _,this_player in ipairs(players) do bindKey ( this_player, "1", "down", stopEngine, "Lights on/off" ) end end This will not work if we don't write a event :>.like this without this when you will restart the resource or start when you have players that bindkey will not work.Else will work when a player join :> addEventHandler ("onResourceStart", getRootElement(), thisResourceStart) Link to comment
loler Posted June 14, 2010 Share Posted June 14, 2010 Salut , si eu sunt din romania vreau doar sa iti spun ca daca iti trebuie ceva sa imi ai un PM Link to comment
50p Posted June 14, 2010 Share Posted June 14, 2010 Salut , si eu sunt din romania vreau doar sa iti spun ca daca iti trebuie ceva sa imi ai un PM This forum is English only. If you say something in your language, translate it to English. Link to comment
dzek (varez) Posted June 14, 2010 Share Posted June 14, 2010 i think (too lazy to use google translate) he want to help him via pm.. nice, loler wants to help somebody, that will be good 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