Player/SpectateEntity

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Created page with "{{Func |Name=SpectateEntity |Parent=Player |Description=Makes the player spectate the entity |Realm=Server |IsClass=Yes }} {{Arg |type=Entity |name=entity |desc=Entit...")
 
m (Added a reference to Player:GetObserverTarget())
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=SpectateEntity
 
|Parent=Player
 
 
|Description=Makes the player spectate the entity
 
|Description=Makes the player spectate the entity
 +
 +
To get the applied spectated entity, use {{ClassFunction|Player|GetObserverTarget}}().
 
|Realm=Server
 
|Realm=Server
 
|IsClass=Yes
 
|IsClass=Yes
Line 12: Line 12:
 
}}
 
}}
 
{{Example
 
{{Example
| Description = Creates a entity, spectates it and after 5 seconds, stops spectating it.
+
|Description=Creates a entity, spectates it and after 5 seconds, stops spectating it.
| Code = local ent = ents.Create( "prop_physics" )
+
|Code=local ent = ents.Create( "prop_physics" )
 
ent:SetModel( "models/hunter/misc/sphere025x025.mdl" )
 
ent:SetModel( "models/hunter/misc/sphere025x025.mdl" )
 
ent:SetPos(Vector(0,0,0))
 
ent:SetPos(Vector(0,0,0))
Line 29: Line 29:
 
   
 
   
 
end
 
end
| Output = None.
+
|Output=None.
 
}}
 
}}

Revision as of 21:15, 20 January 2017

 Player:SpectateEntity( )

Contents

Description

Makes the player spectate the entity

To get the applied spectated entity, use Player:GetObserverTarget().

Arguments

Entity entity

Entity to spectate.

Examples

Example

Creates a entity, spectates it and after 5 seconds, stops spectating it.

local ent = ents.Create( "prop_physics" )
ent:SetModel( "models/hunter/misc/sphere025x025.mdl" )
ent:SetPos(Vector(0,0,0))
ent:Spawn()
 
for _,ply in pairs(player.GetAll()) do
 ply:Spectate( OBS_MODE_CHASE )
 ply:SpectateEntity( ent )
 ply:StripWeapons()
 
 timer.Simple(5, function()
 ply:UnSpectate()
 ply:Spawn()
 end)
 
end

Output:

None.
Personal tools
Navigation