Gamemode.PlayerSpawnedVehicle

From GMod Wiki

Jump to: navigation, search
Event Hook
Hook NamePlayerSpawnedVehicle
SyntaxGM:PlayerSpawnedVehicle( Player Entity, Vehicle Vehicle, )
DescriptionCalled when a player has already spawned a vehicle. Use this to record the vehicle's propid. Useful for prop protection.
ReturnsNil
Lua StateNewerServer.png
BBCode[b][url=wiki.garrysmod.com/?title=Gamemode.PlayerSpawnedVehicle]Gamemode.PlayerSpawnedVehicle [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]

Examples

DescriptionRecord the vehicle's entity index in a table with the owner.
Used onNewerServer.png
Code
props = {}
function SpawnedVehicle( PlayerEntity, VehicleEntity)
	vehicle_index = VehicleEntity:GetIndex()
	props[vehicle_index] = {}
	props[vehicle_index].entity = VehicleEntity
	props[vehicle_index].owner = PlayerEntity:SteamID()
end
 
hook.Add( "PlayerSpawnedVehicle", "playerSpawnedVehicle", SpawnedVehicle )
OutputN/A



DescriptionCreates a horse statue on top of every jeep spawned by players.
Used onNewerServer.png
Code
hook.Add("PlayerSpawnedVehicle","JeepAttachment",function( ply, vehicle )
 
    if not vehicle:GetModel( ) == "models/buggy.mdl" then return end
 
    local horse = ents.Create( "prop_dynamic" )
    horse:SetModel( "models/props_c17/statue_horse.mdl" )
    horse:SetPos( vehicle:GetPos() + Vector(0,0,50) )
    horse:SetAngles( vehicle:GetAngles() + Angle(-25,-90,0) )
    horse:SetParent( vehicle )
    vehicle:DeleteOnRemove( horse )
    horse:Spawn( )
 
end)
OutputN/A


Additional Notes

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox