Difference between revisions of "TPlayers.Add"

From Soldat Community Wiki
Jump to: navigation, search
m
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  '''''function CheckAccess(const FilePath: string): Boolean'''''
+
  '''''function Add(NewPlayer: [[TNewPlayer]], JoinType: [[TJoinType]]): [[TActivePlayer]]'''''
   FilePath: a path to a file to check access for
+
   NewPlayer: An instance of TNewPlayer serving as configuration object for the bot
   Result: Whenever file is accessible from script's sandbox or not
+
  JoinType: Enum (TJoinNormal, TJoinSilent). Silent join will not generate message in console
 +
   Result: Active instance of bot
 
==Description==
 
==Description==
This function checks whenever file pointed by FilePath can be opened by script's File API.
+
Adds a new bot to game basing on configuration from [[TNewPlayer]].
 
+
'''Don't forget to free TNewPlayer instance after using it!'''
==Path syntax==
 
Path to a file should be passed in unix-like syntax (slashes, not backslashes) where first character determinates where is the start point:
 
 
 
* '''/''': if path begins from slash ('''/'''), it's assumed to start from hard disk root ("root" / folder on unix, Disk on which soldatserver is located on windows, i.e. C:\)
 
* '''~''': if path begins from tilde ('''~'''), it's assumed to start from script's data directory (soldatserver/scripts/yourscriptname/data/)
 
* Any else character is assumed to be part of the path and start point is set to soldatserver's directory, i.e. 'soldat.ini' points to soldatserver/soldat.ini.
 
  
 
== Example ==
 
== Example ==
<syntaxhighlight lang="pascal">
+
<syntaxhighlight lang="pascal">
begin
+
  var
  if File.CheckAccess('soldat.ini') then
+
    NewPlayer: TNewPlayer;
     WriteLn('soldat ini seems to be accessible!')
+
  begin
  else
+
    NewPlayer := TNewPlayer.Create;
    WriteLn('access to soldat.ini denied.');
+
     try
end;
+
      NewPlayer.Name := 'Test bot!';
 +
      NewPlayer.Team := 1; // important!
 +
      NewPlayer.PantsColor := $FFFFFFFF;
 +
      NewPlayer.SkinColor := $FFFFFFFF;
 +
      Players.Add(NewPlayer, TJoinNormal);
 +
    finally
 +
      NewPlayer.Free; // important!
 +
    end;
 +
  end;
 
</syntaxhighlight>
 
</syntaxhighlight>
[[Category:TFile]]
+
[[Category:TPlayers]]

Latest revision as of 11:08, 9 September 2016

function Add(NewPlayer: TNewPlayer, JoinType: TJoinType): TActivePlayer
 NewPlayer: An instance of TNewPlayer serving as configuration object for the bot
 JoinType: Enum (TJoinNormal, TJoinSilent). Silent join will not generate message in console
 Result: Active instance of bot

Description

Adds a new bot to game basing on configuration from TNewPlayer. Don't forget to free TNewPlayer instance after using it!

Example

  var
    NewPlayer: TNewPlayer;
  begin
    NewPlayer := TNewPlayer.Create;
    try
      NewPlayer.Name := 'Test bot!';
      NewPlayer.Team := 1; // important!
      NewPlayer.PantsColor := $FFFFFFFF;
      NewPlayer.SkinColor := $FFFFFFFF;
      Players.Add(NewPlayer, TJoinNormal);
    finally
      NewPlayer.Free; // important!
    end;
  end;