Difference between revisions of "TMap.Spawns"

From Soldat Community Wiki
Jump to: navigation, search
(new page)
m (+ Example from AddSpawnPoint)
Line 5: Line 5:
 
Array of [[TActiveSpawnPoint]], holding all spawn points on the map.<br>  
 
Array of [[TActiveSpawnPoint]], holding all spawn points on the map.<br>  
 
'''Note: it's an array[1..255], NOT [0..255]. Calling Spawns[0] will cause an error'''
 
'''Note: it's an array[1..255], NOT [0..255]. Calling Spawns[0] will cause an error'''
 +
 +
==Example==
 +
The below example will check whether the player spawned somewhere far off of his team's spawnpoints. If he is too far away, he gets killed to spawn in the right place.
 +
 +
<syntaxhighlight lang="pascal">
 +
procedure onPlayerRespawn(ID:Byte);
 +
var
 +
i:Byte;
 +
Player_X,
 +
Player_Y:Single;
 +
begin
 +
if Players[ID].Human then begin
 +
  Player_X := Players[ID].X;
 +
  Player_Y := Players[ID].Y;
 +
  for i := 1 to 255 do
 +
  if (Map.SpawnPoints[i].Style = Players[ID].Team) and
 +
      (Distance(Map.SpawnPoints[i].X,Map.SpawnPoints[i].Y,Player_X,Player_Y) < 50)
 +
  then Exit;
 +
end;
 +
Players[ID].Damage(ID,200);
 +
Players[ID].writeConsole('You spawned too far away from your team''s spawnpoint.');
 +
end;
 +
</syntaxhighlight>
  
 
[[Category:TMap]]
 
[[Category:TMap]]

Revision as of 12:45, 22 August 2013

property Spawns[ID: Byte]: TActiveSpawnPoint
 Access mode: R

Description

Array of TActiveSpawnPoint, holding all spawn points on the map.
Note: it's an array[1..255], NOT [0..255]. Calling Spawns[0] will cause an error

Example

The below example will check whether the player spawned somewhere far off of his team's spawnpoints. If he is too far away, he gets killed to spawn in the right place.

procedure onPlayerRespawn(ID:Byte);
var 
 i:Byte;
 Player_X,
 Player_Y:Single;
begin
 if Players[ID].Human then begin
  Player_X := Players[ID].X;
  Player_Y := Players[ID].Y;
  for i := 1 to 255 do
   if (Map.SpawnPoints[i].Style = Players[ID].Team) and
      (Distance(Map.SpawnPoints[i].X,Map.SpawnPoints[i].Y,Player_X,Player_Y) < 50) 
   then Exit;
 end;
 Players[ID].Damage(ID,200);
 Players[ID].writeConsole('You spawned too far away from your team''s spawnpoint.');
end;