Jump to content

Vehicle lock


Xwad

Recommended Posts

Posted

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.

Posted
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.

  • 3 weeks later...
Posted

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

Posted
addEventHandler ( "onVehicleStartEnter", source, 
    function ( player, seat ) 
        if ( isElement ( getVehicleOccupant ( source ) ) and seat == 0 ) then 
            cancelEvent ( ) 
        end 
    end 
) 

Server side.

Posted

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".

Posted
addEventHandler ( "onVehicleStartEnter", root, 
    function ( player, seat ) 
        if ( isElement ( getVehicleOccupant ( source ) ) and seat == 0 ) then 
            cancelEvent ( ) 
        end 
    end 
) 

Posted
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'.

Posted

404d7793b025e1077db4657db7d9aa32.png

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.

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...