Difference between revisions of "TMap.Spawns"

From Soldat Community Wiki
Jump to: navigation, search
(new page)
m
 
(4 intermediate revisions by 2 users not shown)
Line 4: Line 4:
 
==Description==
 
==Description==
 
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. Use other higher type than Byte (e.g., Word, Integer) for "for i := 1 to 255 do" as it will make not ending loop.'''
 +
 
 +
==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]]

Latest revision as of 01:09, 17 June 2018

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. Use other higher type than Byte (e.g., Word, Integer) for "for i := 1 to 255 do" as it will make not ending loop.

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;