Xwad Posted March 10, 2015 Posted March 10, 2015 Hi i need a script that makes possible that when a player get in a vehicle then the other player cant open the door, only if he press g. Can you give the functions for this script? Or is there any rescource like this? Thanks.
Donald Duck Posted March 10, 2015 Posted March 10, 2015 setVehicleLocked isVehicleLocked By cancelling the event: "onVehicleStartEnter" if isVehicleLocked returns true you can make sure that non lockable vehicles like bikes for instance also will remain locked.
Xwad Posted March 28, 2015 Author Posted March 28, 2015 hi i test it and it dosent work:/ function lockcar ( thePlayer ) playervehicle = getPlayerOccupiedVehicle ( thePlayer ) -- define 'playervehicle' as the vehicle the player is in if ( playervehicle ) then -- if a player is in a vehicle if isVehicleLocked ( playervehicle ) then -- and if the vehicle is already locked setVehicleLocked ( playervehicle, false ) -- unlock it else -- otherwise (if it isn't locked) setVehicleLocked ( playervehicle, true ) -- lock it end end end function bindLockOnSpawn ( theSpawnpoint ) -- when a player spawns bindKey ( source, "l", "down", "Lock car", lockcar ) -- bind the 'l' key to the 'lockcar' function end addEventHandler ( "onPlayerSpawn", getRootElement(), bindLockOnSpawn ) -- add an event handler for onPlayerSpawn
WhoAmI Posted March 28, 2015 Posted March 28, 2015 addEventHandler ( "onVehicleStartEnter", source, function ( player, seat ) if ( isElement ( getVehicleOccupant ( source ) ) and seat == 0 ) then cancelEvent ( ) end end ) Server side.
Xwad Posted March 28, 2015 Author Posted March 28, 2015 not working:/ But need i only use that server side?
WhoAmI Posted March 28, 2015 Posted March 28, 2015 Yea, only serverside. It should work like that: player want to enter a car, but if there is controller of this vehicle he can enter only on "G".
Xwad Posted March 28, 2015 Author Posted March 28, 2015 So if a player enter a car the after that another players can only enter with g?
xeon17 Posted March 28, 2015 Posted March 28, 2015 addEventHandler ( "onVehicleStartEnter", root, function ( player, seat ) if ( isElement ( getVehicleOccupant ( source ) ) and seat == 0 ) then cancelEvent ( ) end end )
WhoAmI Posted March 28, 2015 Posted March 28, 2015 Ah yea, don't know how this 'source' instead of 'root' got there. Thank XeoN-.
Xwad Posted March 28, 2015 Author Posted March 28, 2015 Its not working i cant enter the car.I mean i spawned and i could not enter and nobody was in the car
Xwad Posted March 28, 2015 Author Posted March 28, 2015 its also lock the car when nobody is in the car
Addlibs Posted March 28, 2015 Posted March 28, 2015 addEventHandler ( "onVehicleStartEnter", root, function ( player, seat ) if ( isElement ( getVehicleOccupant ( source ) ) and seat == 0 ) then cancelEvent ( ) end end ) Ah yea, don't know how this 'source' instead of 'root' got there. Thank XeoN-. His code is correct. It was supposed to be 'source', not 'root'.
WhoAmI Posted March 28, 2015 Posted March 28, 2015 MrTasty, tell me. When shall I use source, when root, and when other elements? It may help me a lot. Thanks.
Addlibs Posted March 29, 2015 Posted March 29, 2015 source is the element that triggered the event (the vehicle that was being entered) By default, all scripts have a predefined root. It is almost as if every script had root = getRootElement() on the top. The root element is the element that is the parent of everything. Read more on Wiki: Element_tree Executing a function on root will execute it on all (possible) elements. Eg, setVehicleLocked(root, true) will lock ALL vehicles.
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