Bos Wars Scripting API: Triggers
Bos Wars
FAQ
PREV
NEXT
LUA Index
ActionDefeat
ActionDraw
ActionSetTimer
ActionStartTimer
ActionStopTimer
ActionVictory
AddTrigger
IfNearUnit
GetNumOpponents
IfRescuedNearUnit
GetTimer
GetNumUnitsAt
Intro - Introduction to trigger functions and variables
Everything around triggers.
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.
Functions
ActionDefeat()
The player lose the game.
Example
-- 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)
ActionDraw()
The condition player is set to draw. (NOT SUPPORTED)
ActionSetTimer(cycles, increasing)
Set the timer.
- cycles
- The number of cycles (default setting is 30 cycles per second).
- increasing
- Set this to 1 if you want the timer to increase, set it to 0 for decreasing.
Example
-- Sets the timer to 9000 cycles (300 seconds or 5 minutes) and decreasing.
ActionSetTimer(9000, 0)
ActionStartTimer()
Start the timer.
ActionStopTimer()
Stop the timer.
ActionVictory()
The condition player is set to victory.
Example
-- 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)
AddTrigger(condition, action)
Creates a new trigger.
FIXME: in code, action could be a table, but crash on execution..
- condition
- Function which must return true to execute the condition. It is tested every FIXME.
- action
-
Function executed when condition return true. The trigger remains active
if the action returns true and is removed if the action returns false.
Example
-- 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)
IfNearUnit(player, op, quantity, unit1, unit2)
Return true if the number of unit1 near of unit2 "op" quantity is true for the player.
- player
0 .. 16 Player number
"any" Matches any player
"this" Player on the local computer, Human player in the campaign.
- op
"==" operator equal
">" operator greater than
">=" operator greater than or equal
"<" operator less than
"<=" operator less than or equal
- quantity
- Number to compare with number of units
- unit1
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
- unit2
- unit-name, so unit type of this name.
Example
-- 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")
GetNumOpponents(player)
Returns the number of opponent's for the given player.
- player
0 .. 16 Player number
Example
-- You win when you have no opponents left.
if (GetNumOpponents(ThisPlayer.Index) == 0) then
ActionVictory()
IfRescuedNearUnit(player, op, quantity, unit1, unit2)
Return true if the number of rescued-units of type unit1 which are currently near of unit2
of the player "op" quantity is true.
- player
0 .. 16 Player number
"any" Matches any player
"this" Player on the local computer, Human player in the campaign.
- op
"==" operator equal
">" operator greater than
">=" operator greater than or equal
"<" operator less than
"<=" operator less than or equal
- quantity
- Number to compare with number of rescued-unit
- unit1
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
- unit2
- unit-name, so unit type of this name.
Example
-- 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")
GetTimer()
Return the number of cycles the timer ran.
Example
-- True when the timer is at 17 cycles.
time = GetTimer() == 17
GetNumUnitsAt(player, unit-type, {x1, y1}, {x2, y2})
Return the number of units of type unit-type which are in the rectangle defined with (x1, y1, x2, y2)
of the player.
- player
0 .. 16 Player number
- unit
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
- {x1, y1}
- Upper left corner
- {x2, y2}
- Lower right corner
Example
-- 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
All trademarks and copyrights on this page are owned by their respective owners.
(c) 2002-2006 by
The Bos Wars Project