Difference between revisions of "TMap.AddObject"

From Soldat Community Wiki
Jump to: navigation, search
(new page)
 
m
Line 1: Line 1:
  '''''function AddObject(Obj: [[TNewMapObject]]):[[TActiveMapObject]]'''''
+
  '''function AddObject(Obj: [[TNewMapObject]]):[[TActiveMapObject]]'''
 
   Obj: new object to be placed on the map
 
   Obj: new object to be placed on the map
 
   Result: newly created object<br>
 
   Result: newly created object<br>

Revision as of 20:02, 22 August 2013

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.