TMap.AddObject

From Soldat Community Wiki
Revision as of 11:43, 22 August 2013 by Mighty (talk | contribs) (new page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
function AddObject(Obj: TNewMapObject):TActiveMapObject
 Obj: new object to be placed on the map
 Result: newly created object

Description

This function will add a new object at position X,Y with target style. It will always be active.

Example

The below example will spawn a medkit on the players position whenever he types "Medic!"

var
  i: integer;

procedure SpawnMedkit(posx,posy: single);
var temp: TNewMapObject;
begin
  temp := TNewMapObject.Create; 
  temp.X := posx;
  temp.Y := posy;
  temp.Style := 16; // medkit
  Map.AddObject(temp);
  temp.Free; // IMPORTANT!
end;

procedure MyOnSpeak(p: TActivePlayer; Text: string);
begin
  if Text = 'Medic!' then
    SpawnMedkit(p.X,p.Y);
end;

begin
  for i:=1 to 32 do
    Players[i].OnSpeak := @MyOnSpeak;
end.