docs: translated ScriptPlayers.xml examples

Tobias Zwick 2011-07-24 00:08:36 +02:00
parent 0a8e09abcf
commit be511996bf
1 changed files with 38 additions and 42 deletions

View File

@ -12,37 +12,35 @@
<h id="Runtime">Runtime join</h>
<text>For creating an AI player at run time - e.g. a new deathmatch opponent - you can use <funclink>CreateScriptPlayer</funclink>. This call will be followed (possibly with a little delay) by a InitializePlayer callback for the new player.</text>
<text>Example:</text>
<code>/* Script einer aktivierten Spielregel namens &quot;KI Erzeugen&quot; */
<code>/* Script of a game rule named &quot;Create AI&quot; */
public func Activate(int player)
{
// Der Spieler player hat die Spielregel ausgewählt. Erzeuge einen KI-Gegner!
<funclink>return</funclink>(<funclink>CreateScriptPlayer</funclink>(&quot;Computer&quot;, 0x7f7f7f));
}
func Activate(int player)
{
// The player selected the rule. Create a AI enemy.
<funclink>return</funclink> <funclink>CreateScriptPlayer</funclink>(&quot;Computer&quot;, 0x7f7f7f);
}
protected func InitializePlayer(int player)
{
// Ein Spieler ist beigetreten. Dieser Aufruf erfolgt an das Szenarienscript, sowie an alle Spielregeln,
// Spielziele und Umweltobjekte
// Ist es ein Scriptspieler?
func InitializePlayer(int player)
{
// A player has joined. This call is issed to both the scenario script and all game rules, goals and
// environment objects
// Is it a script player?
<funclink>if</funclink> (<funclink>GetPlayerType</funclink>(player) == C4PT_Script)
{
// Dann übernimm die Steuerung für alle Clonks!
{
// Then take over the controls for all clonks!
var crew_counter, crew;
<funclink>while</funclink> (crew = <funclink>GetCrew</funclink>(player, crew_counter++))
<funclink>AddEffect</funclink>(&quot;Int_EAI&quot;, crew, 1, 100, <funclink>this</funclink>());
}
<funclink>AddEffect</funclink>(&quot;Int_EAI&quot;, crew, 1, 100, <funclink>this</funclink>);
}
}
protected func FxInt_EAITimer(object crew, int num, int time)
{
// Nächsten Gegner angreifen
func FxInt_EAITimer(object crew, effect, int time)
{
// attack next enemy
var enemy = <funclink>FindObject</funclink>(<funclink>Find_Hostile</funclink>(<funclink>GetOwner</funclink>(crew)), <funclink>Find_OCF</funclink>(<funclink>OCF_Alive</funclink>), <funclink>Sort_Distance</funclink>());
<funclink>if</funclink> (enemy) <funclink>SetCommand</funclink>(crew, &quot;Attack&quot;, enemy);
<funclink>if</funclink> (enemy) crew-&gt;<funclink>SetCommand</funclink>(&quot;Attack&quot;, enemy);
<funclink>return</funclink> FX_OK;
}
}
</code>
<text>This script for a sample rule object allows the user to create AI opponents at runtime. Also, it will order all clonks of the AI players to attack. Notice: this sample script only handles those clonks automatically created through the scenario settings. Additional clonks placed by specialized scripting are not handled.</text>
<text>For internet games you can set MaxScriptPlayers in <emlink href="scenario/Teams.html">Teams.txt</emlink> to a value greater than 0. This will enable the option to have script players join in the game lobby.</text>
@ -70,35 +68,33 @@ LastPlayerID=1
<h id="Specialized">Specialized Players</h>
<text>Sometimes it can be desirable to create a script player at runtime, but still execute a specialized initialization instead of the default crew and base material creation. For example, a Hazard deathmatch scenario may provide a specialized alien enemy.</text>
<text>By passing a parameter to <funclink>CreateScriptPlayer</funclink>, scenario initialization can be prevented, i.e. no creation of start materials, no setting of player parameters such as homebase material by the according presets and no InitializePlayer-calls are done. Instead, a single CreateScriptPlayer-callback is done to the definition passed as idExtraData. Example:</text>
<code>/* Script einer aktivierten Spielregel namens &quot;Aliens erzeugen&quot; */
<code>/* Script of a rule named &quot;Create aliens&quot; */
public func Activate(int player)
{
// Der Spieler player hat die Spielregel ausgewählt. Erzeuge einen Alien-Gegner!
<funclink>return</funclink>(<funclink>CreateScriptPlayer</funclink>(&quot;Aliens&quot;, 0x00ff00, 0, CSPF_FixedAttributes | CSPF_NoScenarioInit, GetID()));
}
func Activate(int player)
{
// The player selected the game rule. Create an alien enemy!
<funclink>return</funclink> <funclink>CreateScriptPlayer</funclink>(&quot;Aliens&quot;, 0x00ff00, 0, CSPF_FixedAttributes | CSPF_NoScenarioInit, GetID());
}
protected func InitializeScriptPlayer(int player, int idTeam)
{
// Ein Alienspieler ist beigetreten
// Da keine Szenarieninitialisierung durchgeführt wurde, muss in diesem Callback eine Crew für den Spieler erstellt werden
// Erstelle einen grünen Clonk - ein richtiges Szenario sollte natürlich echte Aliens mitbringen :)
func InitializeScriptPlayer(int player, int idTeam)
{
// An alien player has joined
// since no scenario initialization has been executed, a crew for this player has to be created in this callback
// create a green clonk. A real scenario should of course have it's own aliens :-)
var alien = CreateObject(Clonk, LandscapeWidth()/2, -1, player);
MakeCrewMember(alien, player);
SetClrModulation(0x7fff7f, alien);
// Und angreifen lassen
// and attack
<funclink>AddEffect</funclink>(&quot;Int_EAI&quot;, alien, 1, 100, 0, GetID());
}
}
protected func FxInt_EAITimer(object crew, int num, int time)
{
// Nächsten Gegner angreifen
func FxInt_EAITimer(object crew, effect, int time)
{
// Attack next enemy
var enemy = <funclink>FindObject</funclink>(<funclink>Find_Hostile</funclink>(<funclink>GetOwner</funclink>(crew)), <funclink>Find_OCF</funclink>(<funclink>OCF_Alive</funclink>), <funclink>Sort_Distance</funclink>());
<funclink>if</funclink> (enemy) <funclink>SetCommand</funclink>(crew, &quot;Attack&quot;, enemy);
<funclink>if</funclink> (enemy) crew-&gt;<funclink>SetCommand</funclink>(&quot;Attack&quot;, enemy);
<funclink>return</funclink> FX_OK;
}
}
</code>
</part>
<author>Sven2</author><date>2007-12</date>