Sophie

Sophie

distrib > Mageia > 6 > x86_64 > media > core-updates > by-pkgid > 6ef0fdc2c18d666ec7b59c27c05c5d78 > files > 31

boswars-2.7-10.20170903.1.mga6.x86_64.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<!--
----	(c) Copyright 2002-2007 by Lutz Sammer, Russell Smith, Fran�is Beerten

----    This program is free software; you can redistribute it and/or modify
----    it under the terms of the GNU General Public License as published by
----    the Free Software Foundation; only version 2 of the License.
----
----    This program is distributed in the hope that it will be useful,
----    but WITHOUT ANY WARRANTY; without even the implied warranty of
----    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
----    GNU General Public License for more details.
----
----    You should have received a copy of the GNU General Public License
----    along with this program; if not, write to the Free Software
----    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
----    02111-1307, USA.
-->
    <title>Bos Wars Scripting API: Triggers</title>
    <meta http-equiv="Content-Type" content="text/html; CHARSET=iso-8859-1">
    <link rel="stylesheet" type="text/css" href="scripts.css">
</head>
<body>
    <h1>Bos Wars Scripting API: Triggers</h1>
<hr>
<a href="../index.html">Bos Wars</a> 
<a href="../faq.html">FAQ</a> 
<a href="sound.html">PREV</a> 
<a href="ui.html">NEXT</a> 
<a href="index.html">LUA Index</a>
<hr>
<a href="#ActionDefeat">ActionDefeat</a>
<a href="#ActionDraw">ActionDraw</a>
<a href="#ActionSetTimer">ActionSetTimer</a>
<a href="#ActionStartTimer">ActionStartTimer</a>
<a href="#ActionStopTimer">ActionStopTimer</a>
<a href="#ActionVictory">ActionVictory</a>
<a href="#AddTrigger">AddTrigger</a>
<a href="#IfNearUnit">IfNearUnit</a>
<a href="#GetNumOpponents">GetNumOpponents</a>
<a href="#IfRescuedNearUnit">IfRescuedNearUnit</a>
<a href="#GetTimer">GetTimer</a>
<a href="#GetNumUnitsAt">GetNumUnitsAt</a>
<hr>
<h2>Intro - Introduction to trigger functions and variables</h2>

Everything around triggers.<br>
Triggers are a couple of (condition, action).
Each cycles in the game, if the condition of the active triggers is true,
then the associated actions are executed.
There are used for condition's victory
and could be usefull to add special actions when an event occurs.

<h2>Functions</h2>

<a name="ActionDefeat"></a>
<h3>ActionDefeat()</h3>

The player lose the game.


<h4>Example</h4>

<pre class="lua">
-- Adds a trigger. If the player on the console has 0 units then he loses.
AddTrigger(
  function() return IfUnit("this", "==", 0, "all") end,
  function() return ActionDefeat() end)
</pre>

<a name="ActionDraw"></a>
<h3>ActionDraw()</h3>

The condition player is set to draw. (NOT SUPPORTED)


<a name="ActionSetTimer"></a>
<h3>ActionSetTimer(cycles, increasing)</h3>

Set the timer.


<dl>
  <dt>cycles</dt>
  <dd>The number of cycles (default setting is 30 cycles per second).</dd>
  <dt>increasing</dt>
  <dd>Set this to 1 if you want the timer to increase, set it to 0 for decreasing.</dd>
</dl>

<h4>Example</h4>

<pre class="lua">
-- Sets the timer to 9000 cycles (300 seconds or 5 minutes) and decreasing.
ActionSetTimer(9000, 0)
</pre>

<a name="ActionStartTimer"></a>
<h3>ActionStartTimer()</h3>

Start the timer.


<a name="ActionStopTimer"></a>
<h3>ActionStopTimer()</h3>

Stop the timer.


<a name="ActionVictory"></a>
<h3>ActionVictory()</h3>

The condition player is set to victory.

<h4>Example</h4>

<pre class="lua">
-- Adds a trigger. If the player on the console has killed all his 
-- opponents he won.
AddTrigger(
  function() return IfOpponents("this", "==", 0) end,
  function() return ActionVictory() end)
</pre>

<a name="AddTrigger"></a>
<h3>AddTrigger(condition, action)</h3>

Creates a new trigger.
<br>FIXME: in code, action could be a table, but crash on execution..

<dl>
  <dt>condition</dt>
  <dd>Function which must return true to execute the condition. It is tested every FIXME.</dd>
  <dt>action</dt>
  <dd>
  Function executed when condition return true. The trigger remains active
  if the action returns true and is removed if the action returns false.
  </dd>
</dl>

<h4>Example</h4>

<pre class="lua">
-- Adds a trigger. If the player on the console has killed all his 
-- opponents he won.
AddTrigger(
  function() return IfOpponents("this", "==", 0) end,
  function() return ActionVictory() end)
</pre>

<a name="IfNearUnit"></a>
<h3>IfNearUnit(player, op, quantity, unit1, unit2)</h3>
 
Return true if the number of unit1 near of unit2 "op" quantity is true for the player.


<dl>
  <dt>player</dt>
  <dd><pre>
0 .. 16     Player number
"any"       Matches any player
"this"      Player on the local computer, Human player in the campaign.
</pre></dd>
  <dt>op</dt>
  <dd><pre>
"=="         operator equal
"&gt;"          operator greater than
"&gt;="         operator greater than or equal
"&lt;"          operator less than
"&lt;="         operator less than or equal
</pre></dd>
  <dt>quantity</dt>
  <dd>Number to compare with number of units</dd>
  <dt>unit1</dt>
  <dd><pre>
unit-name    Unit type of this name
"any"        Matches any unit type
"all"        All units (sum of units and buildings)
"units"      All non building units
"building"   All building units
</pre></dd>
  <dt>unit2</dt>
  <dd>unit-name, so unit type of this name.</dd>
</dl>

<h4>Example</h4>

<pre class="lua">
-- true when the player on the console has 6 archers near one of his/her circle of power.
IfNearUnit("this", "==", 6, "unit-archer", "unit-circle-of-power")
</pre>

<a name="GetNumOpponents"></a>
<h3>GetNumOpponents(player)</h3>

Returns the number of opponent's for the given player.

<dl>
  <dt>player</dt>
  <dd><pre>
0 .. 16     Player number
</pre></dd>
</dl>

<h4>Example</h4>

<pre class="lua">
-- You win when you have no opponents left.
if (GetNumOpponents(ThisPlayer.Index) == 0) then
     ActionVictory()
</pre>

<a name="IfRescuedNearUnit"></a>
<h3>IfRescuedNearUnit(player, op, quantity, unit1, unit2)</h3>
 
Return true if the number of rescued-units of type unit1 which are currently near of unit2
of the player "op" quantity is true.

<dl>
  <dt>player</dt>
  <dd><pre>
0 .. 16     Player number
"any"       Matches any player
"this"      Player on the local computer, Human player in the campaign.
</pre></dd>
  <dt>op</dt>
  <dd><pre>
"=="         operator equal
"&gt;"          operator greater than
"&gt;="         operator greater than or equal
"&lt;"          operator less than
"&lt;="         operator less than or equal
</pre></dd>
  <dt>quantity</dt>
  <dd>Number to compare with number of rescued-unit</dd>
  <dt>unit1</dt>
  <dd><pre>
unit-name    Unit type of this name
"any"        Matches any unit type
"all"        All units (sum of units and buildings)
"units"      All non building units
"building"   All building units
</pre></dd>
  <dt>unit2</dt>
  <dd>unit-name, so unit type of this name.</dd>
</dl>

<h4>Example</h4>

<pre class="lua">
-- True when The player on the console has 1 rescued archer near the circle of power.
IfRescuedNearUnit("this", "==", 1, "unit-archer", "unit-circle-of-power")
</pre>


<a name="GetTimer"></a>
<h3>GetTimer()</h3>
 
Return the number of cycles the timer ran.
 
<h4>Example</h4>

<pre class="lua">
-- True when the timer is at 17 cycles.
time = GetTimer() == 17
</pre>

<a name="GetNumUnitsAt"></a>
<h3>GetNumUnitsAt(player, unit-type, {x1, y1}, {x2, y2})</h3>
 
Return the number of units of type unit-type which are in the rectangle defined with (x1, y1, x2, y2)
of the player.

<dl>
  <dt>player</dt>
  <dd><pre>
0 .. 16     Player number
</pre></dd>
  <dt>unit</dt>
  <dd><pre>
unit-name    Unit type of this name
"any"        Matches any unit type
"all"        All units (sum of units and buildings)
"units"      All non building units
"building"   All building units
</pre></dd>
  <dt>{x1, y1}</dt>
  <dd>Upper left corner</dd>
  <dt>{x2, y2}</dt>
  <dd>Lower right corner</dd>
</dl>

<h4>Example</h4>

<pre class="lua">
-- True when the player on the console has at least 8 archers in the rectangle
-- (10 10) to (12 14).
GetNumUnitsAt(ThisPlayer.Index, "unit-archer", {10, 10}, {12, 14}) >= 8
</pre>

<hr>
All trademarks and copyrights on this page are owned by their respective owners.
<address>(c) 2002-2006 by <a href="http://boswars.org">
The Bos Wars Project</a></address></body></html>