Difference between revisions of "TMap.Spawns"

From Soldat Community Wiki
Jump to: navigation, search
m (+ Example from AddSpawnPoint)
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..254], NOT [0..255]. Calling Spawns[0] or Spawns[255] will cause an error'''
  
 
==Example==
 
==Example==
Line 19: Line 19:
 
   Player_X := Players[ID].X;
 
   Player_X := Players[ID].X;
 
   Player_Y := Players[ID].Y;
 
   Player_Y := Players[ID].Y;
   for i := 1 to 255 do
+
   for i := 1 to 254 do
 
   if (Map.SpawnPoints[i].Style = Players[ID].Team) and
 
   if (Map.SpawnPoints[i].Style = Players[ID].Team) and
 
       (Distance(Map.SpawnPoints[i].X,Map.SpawnPoints[i].Y,Player_X,Player_Y) < 50)  
 
       (Distance(Map.SpawnPoints[i].X,Map.SpawnPoints[i].Y,Player_X,Player_Y) < 50)  

Revision as of 23:50, 16 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..254], NOT [0..255]. Calling Spawns[0] or Spawns[255] 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 254 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;