Difference between revisions of "Lua:IsPlayer"

From Fortress Forever Wiki
Jump to navigationJump to search
 
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{Infobox manual/Header}}
 
==IsPlayer==
 
==IsPlayer==
  
Line 13: Line 14:
  
 
===Example===
 
===Example===
Here's an example of seeing if someone touching a trigger_ff_script named "red_goal" is a player or not and then giving that player's a team a point:
+
Here's an example of seeing if someone touching a trigger_ff_script named "red_goal" is a player or not and then giving that players team a point:
  
 
<pre>-- In the map's .LUA file...
 
<pre>-- In the map's .LUA file...
Line 23: Line 24:
 
function red_goal:ontouch( ent_id )
 
function red_goal:ontouch( ent_id )
 
     if IsPlayer( ent_id ) then
 
     if IsPlayer( ent_id ) then
           -- Add 1 point to the playerss team
+
           -- Add 1 point to the players team
 
           AddTeamScore( GetPlayerTeam( ent_id ), 1 )
 
           AddTeamScore( GetPlayerTeam( ent_id ), 1 )
 
     end
 
     end
 
end</pre>
 
end</pre>
  
[[Category:LUA_Commands]]
+
[[Category:Lua_Commands]]
 +
{{Infobox manual/Footer}}

Latest revision as of 16:40, 31 December 2007


IsPlayer

IsPlayer is used to see if an entity index being passed into a function is a player or not.

Usage

IsPlayer( ent_id )

Input

The ent_id passed in is simply an integer index that refers to an entities game code ENTINDEX().

Output

The output is true or false depending if ent_id is a player or not.

Example

Here's an example of seeing if someone touching a trigger_ff_script named "red_goal" is a player or not and then giving that players team a point:

-- In the map's .LUA file...

-- Define red_goal trigger_ff_script
red_goal = trigger_ff_script:new({})

-- When we're touched by a player, do something
function red_goal:ontouch( ent_id )
     if IsPlayer( ent_id ) then
          -- Add 1 point to the players team
          AddTeamScore( GetPlayerTeam( ent_id ), 1 )
     end
end