File: triggers.html

package info (click to toggle)
boswars 2.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 96,652 kB
  • sloc: cpp: 57,250; python: 1,715; sh: 25; makefile: 17
file content (304 lines) | stat: -rw-r--r-- 8,251 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<!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>