Player.EnterVehicle

From GMod Wiki

Jump to: navigation, search
Function
Syntax Player:EnterVehicle( Entity vehicle )
Description:
Forces a player into a vehicle
Returns: nil
In Object: Player
Realm: NewerServer.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Player.EnterVehicle]Player.EnterVehicle [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionMakes everyone enter the first vehicle found
Used onNewerServer.png
Code
local jeep = NULL --Init the jeep entity
local found = false --We use this variable to see if there's a jeep entity around
 
for _, v in pairs ( ents.GetAll() ) do --For all entities...
    if ( v:GetClass() == "prop_vehicle_jeep" ) then --If it's a jeep then...
        found = true --We found it!
        jeep = v --Change our jeep variable to the jeep we found
        break --Break out of the loop
    end
end
 
if ( !found ) then return end --Only enter it if we found a jeep!
for _, v in pairs ( player.GetAll() ) do --For every player...
    if ( !v:InVehicle() ) then --If he's not in the vehicle...
        v:EnterVehicle( v ) --Enter it!
    end
end
OutputN/A

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox