CreateScriptPlayer

Category: Player
Since engine version: 4.9.6.0 CR

Description

Initializes a joining script player. Script players appear as regular players from the scripting point of view. They have a crew, wealth, build knowledge, home base material, hostility, teams, etc. However, script players do not have a game view port and they can not be controlled by human users.
Script players can be used to create AI controlled opponent teams in special scenarios.

Syntax

bool CreateScriptPlayer (string szName, int dwClr, int idTeam, int dwFlags, id idExtraData);

Parameters

szName:
Name for the script player. Required.
dwClr:
Player color
idTeam:
[opt] Team-Id. If 0, a team is automatically chosen according to the rules also applied to normal joining players.
dwFlags:
[opt] Bit mask composed of the following values:
Bit Constant Description
0 CSPF_FixedAttributes If set, the player is guaranteed to join with the name and color specified in the parameters. Otherwise those preferences might be ignored in case of conflicts with other players' preferences.
1 CSPF_NoScenarioInit If true, the scenario initialization (i.e. placement of home base material, clonks, setting of build knowledge, etc.) is not performed for this player. Also, the global callbacks PreInitializePlayer and InitializePlayer to the scenario script and to goal, rule, and environment objects are not performed. Instead, the callback InitializeScriptPlayer(Player number, Team) is made to the object definition specified in idExtraData. The call is made as DefinitionCall (without this() object). Using this parameter you can create script-controlled AI players which do not receive the same standard treatment as user-controlled players.
2 CSPF_NoEliminationCheck If set, the player will not be eliminated automatically if its crew is empty.
3 CSPF_Invisible If set, the player will not show up in player lists such as in the lobby or hostility menu.
idExtraData:
[opt] Id which is passed to the InitializePlayer call. Using this id, it is quite simple to create different types of script players. E.g. a scenario could feature AI players with different types of crew members.

Remark

As do normal players, script player join with a slight delay in network games. This means that following the call to CreateScriptPlayer the player will not be immediately available.
That means, actual initialization of that player should happen in the InitializePlayer callback which can use GetPlayerType() to check whether this is a script player.
If the script player really needs to be available even before normal player initialization - e.g. as opponent in a single player mission - you could create the player via the SavePlayerInfos.txt component.

Example

For examples see Script Players.
See also: GetPlayerType, Script Player
Sven2, Dezember 2007