Editing MG/Lua
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
[[Lua]] is the scripting language used in [[MegaGlest]]'s [[scenarios]]. It allows scenarios to expand and do things not normally possible in regular games of Glest. This page lists all the Lua commands available in MegaGlest. For information on how to create scenarios and working with Lua in general, see [[Lua]]. | [[Lua]] is the scripting language used in [[MegaGlest]]'s [[scenarios]]. It allows scenarios to expand and do things not normally possible in regular games of Glest. This page lists all the Lua commands available in MegaGlest. For information on how to create scenarios and working with Lua in general, see [[Lua]]. | ||
− | |||
− | |||
==Text== | ==Text== | ||
Line 7: | Line 5: | ||
Displays a message box on the screen, that will have to be dismissed by the player. | Displays a message box on the screen, that will have to be dismissed by the player. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''text''' - a string identifying the'' text'' from a language file.<br />{C}'''header''' - a string identifying the'' title bar text ''from a language file. |
− | '''text''' - a string identifying the'' text'' from a language file.<br /> | ||
− | '''header''' - a string identifying the'' title bar text ''from a language file. | ||
=== addConsoleText(text) === | === addConsoleText(text) === | ||
Displays a message in the game console messages area. Will remain until the user-specified message timeout has elapsed. | Displays a message in the game console messages area. Will remain until the user-specified message timeout has elapsed. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''text''' - a string identifying the'' text'' from a language file. |
− | '''text''' - a string identifying the'' text'' from a language file. | + | |
+ | === addConsoleLangText(const char *fmt, ...)=== | ||
+ | Available in rev 2813. Displays a message in the game console messages area. Will remain until the message timeout has elapsed. Works like | ||
− | === | + | === addConsoleText(text) === |
− | + | <tt>)</tt> besides the fact that <tt>addConsoleLangText()</tt> uses the language-file for resolving the format of the text. | |
− | Parameters:<br /> | + | Parameters:<br />{C}'''text''' - a string identifying the ''text'' from a language file. |
− | '''text''' - a string identifying the ''text'' from a language file. | ||
=== setDisplayText(text) === | === setDisplayText(text) === | ||
Displays a message at the top of the screen. Will remain until dismissed with <tt>clearDisplayText()</tt> or <tt>setDisplayText()</tt> is called again. | Displays a message at the top of the screen. Will remain until dismissed with <tt>clearDisplayText()</tt> or <tt>setDisplayText()</tt> is called again. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''text''' - a string identifying the ''text'' from a language file. |
− | '''text''' - a string identifying the ''text'' from a language file. | ||
− | ===displayFormattedText (fmt, ...)=== | + | ===displayFormattedText (const char *fmt, ...)=== |
− | Works like <tt>setDisplayText()</tt> but allows formatting of text. | + | Available in rev 2767. Works like <tt>setDisplayText()</tt> but allows formatting of text. |
− | Parameters:<br /> | + | Parameters:<br />{C}'''fmt''' - a string identifying the format of text ''(like in printf)''.<br />{C}'''...''' - variable parameter list to pass values to fmt ''(like in printf)''. |
− | '''fmt''' - a string identifying the format of text ''(like in printf)''.<br /> | ||
− | '''...''' - variable parameter list to pass values to fmt ''(like in printf)''. | ||
− | ===displayFormattedLangText (fmt, ...)=== | + | ===displayFormattedLangText (const char *fmt, ...)=== |
− | Works like <tt>displayFormattedText()</tt> but uses the language-file for resolving the format of the text. | + | Available in rev 2767. Works like <tt>displayFormattedText()</tt> but uses the language-file for resolving the format of the text. |
− | Parameters:<br /> | + | Parameters:<br />{C}'''fmt''' - a string identifying the format of text ''(like in printf)''.<br />{C}'''...''' - variable parameter list to pass values to fmt ''(like in printf)''. |
− | '''fmt''' - a string identifying the format of text ''(like in printf)''.<br /> | ||
− | '''...''' - variable parameter list to pass values to fmt ''(like in printf)''. | ||
− | === clearDisplayText() === | + | === clearDisplayText () === |
Clears the message from the top of the screen previously set with <tt>setDisplayText()</tt>. | Clears the message from the top of the screen previously set with <tt>setDisplayText()</tt>. | ||
==Unit== | ==Unit== | ||
=== createUnit(unitID, faction, pos) === | === createUnit(unitID, faction, pos) === | ||
− | Creates a unit. If ''pos'' is occupied, a nearby cell will be chosen. The game attempts to keep a 2 cell 'border' between the new unit and other units or objects (eg, trees). If a position can not be found, the game crashes | + | Creates a unit. If ''pos'' is occupied, a nearby cell will be chosen. The game attempts to keep a 2 cell 'border' between the new unit and other units or objects (eg, trees). '''Warning''': If a position can not be found, the game crashes. |
− | |||
− | |||
− | |||
− | |||
+ | Parameters:<br />{C}'''unit''' - name of a unit in the loaded factions.<br />{C}'''faction''' - the index of the faction this unit will belong to.<br />{C}'''pos''' - an array of two elements, specifying the co-ordinates {x,y}. | ||
− | ===destroyUnit(unitID)=== | + | === destroyUnit(unitID) === |
Destroys a unit. | Destroys a unit. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''unitID''' - the ID of the unit to destroy. |
− | '''unitID''' - the ID of the unit to destroy. | ||
=== morphToUnit(unitID, morphName, ignoreRequirements) === | === morphToUnit(unitID, morphName, ignoreRequirements) === | ||
Morphs a unit into another unit of type morphName. If ignoreRequirements is set to 1 then the morph is executed even if the unit does not satisfy the morph requirements. | Morphs a unit into another unit of type morphName. If ignoreRequirements is set to 1 then the morph is executed even if the unit does not satisfy the morph requirements. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''unitID''' - the ID of a unit.<br />{C}'''morphName''' - the name of the morph to execute.<br />{C}'''ignoreRequirements''' - a 0 or 1 value indicating whether to respect morph requirements (0) or not (1) |
− | '''unitID''' - the ID of a unit.<br /> | ||
− | '''morphName''' - the name of the morph to execute.<br /> | ||
− | '''ignoreRequirements''' - a 0 or 1 value indicating whether to respect morph requirements (0) or not (1) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | === moveToUnit(unitID, destUnitID) === | + | === moveToUnit ( unitID, destUnitID ) === |
Move unitID to the location of destUnitID. | Move unitID to the location of destUnitID. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''unitID''' - the ID of the unit to move (starting location).<br />{C}'''destUnitID''' - the ID of the unit to move to (ending location of unitID). This would essentially make unitID 'follow' destUnitID until it arrives at the location of destUnitID. |
− | '''unitID''' - the ID of the unit to move (starting location).<br /> | ||
− | '''destUnitID''' - the ID of the unit to move to (ending location of unitID). This would essentially make unitID 'follow' destUnitID until it arrives at the location of destUnitID | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===giveAttackCommand(unitID, unitToAttackID)=== | ===giveAttackCommand(unitID, unitToAttackID)=== | ||
Instruct a unit to carry out a command of type 'attack' on a specific unit. | Instruct a unit to carry out a command of type 'attack' on a specific unit. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''unitID''' - the ID of a unit that has an attack command. {C}'''unitToAttackID''' - the ID of a unit that should be attacked. |
− | '''unitID''' - the ID of a unit that has an attack command. | ||
− | '''unitToAttackID''' - the ID of a unit that should be attacked. | ||
=== giveAttackStoppedCommand(unitID, valueName, ignoreRequirements) === | === giveAttackStoppedCommand(unitID, valueName, ignoreRequirements) === | ||
Executes the attack stopped command for a unit specified by 'valueName'. If ignoreRequirements is set to 1 then the command is executed even if the unit does not satisfy the command requirements. | Executes the attack stopped command for a unit specified by 'valueName'. If ignoreRequirements is set to 1 then the command is executed even if the unit does not satisfy the command requirements. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''unitID''' - the ID of a unit.<br />{C}'''valueName''' - the name of the attack stopped command to execute.<br />{C}'''ignoreRequirements''' - a 0 or 1 value indicating whether to respect command requirements (0) or not (1). |
− | '''unitID''' - the ID of a unit.<br /> | ||
− | '''valueName''' - the name of the attack stopped command to execute.<br /> | ||
− | '''ignoreRequirements''' - a 0 or 1 value indicating whether to respect command requirements (0) or not (1). | ||
=== giveResource(resource, faction, amount) === | === giveResource(resource, faction, amount) === | ||
Give an amount of a specified resource to a player, negative values are valid and have the obvious effect. | Give an amount of a specified resource to a player, negative values are valid and have the obvious effect. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''resource''' - a corresponding resource in the techtree.<br />{C}'''faction''' - the index of the faction to give the resource.<br />{C}'''amount''' - the amount of resource the faction will receive. |
− | '''resource''' - a corresponding resource in the techtree.<br /> | ||
− | '''faction''' - the index of the faction to give the resource.<br /> | ||
− | '''amount''' - the amount of resource the faction will receive. | ||
=== givePositionCommand(unitID, command, pos) === | === givePositionCommand(unitID, command, pos) === | ||
Instruct a unit to carry out a command of type 'attack' or 'move'. The unit being given the command must have such a command available. | Instruct a unit to carry out a command of type 'attack' or 'move'. The unit being given the command must have such a command available. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''unitID''' - the ID of a unit that has an attack and/or move command.<br />{C}'''command''' - the type of command to carry out ('attack' or 'move')<br />{C}'''pos''' - an array of two elements, specifying the co-ordinates {x,y}. |
− | '''unitID''' - the ID of a unit that has an attack and/or move command.<br /> | ||
− | '''command''' - the type of command to carry out ('attack' or 'move')<br /> | ||
− | '''pos''' - an array of two elements, specifying the co-ordinates {x,y}. | ||
=== giveProductionCommand(unitID, produced) === | === giveProductionCommand(unitID, produced) === | ||
Instruct a unit to carry out a command of type 'produce'. The unit being given the command must have such a command available. | Instruct a unit to carry out a command of type 'produce'. The unit being given the command must have such a command available. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''unitID''' - the ID of a unit that is to produce the new unit.<br />{C}'''produced''' - the name of the unit to produce. |
− | '''unitID''' - the ID of a unit that is to produce the new unit.<br /> | ||
− | '''produced''' - the name of the unit to produce. | ||
=== giveUpgradeCommand(unitID, upgrade) === | === giveUpgradeCommand(unitID, upgrade) === | ||
Instruct a unit to carry out a command of type 'upgrade'. The unit being given the command must have such a command available. | Instruct a unit to carry out a command of type 'upgrade'. The unit being given the command must have such a command available. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''unitID''' - the ID of the unit to perform the upgrade.<br />{C}'''upgrade '''- the name of the upgrade to perform. |
− | '''unitID''' - the ID of the unit to perform the upgrade.<br /> | ||
− | '''upgrade '''- the name of the upgrade to perform | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | === | + | ===giveKills(unit, amount)=== |
− | + | Available in rev 2823. Gives a specified unit a certain number of kills (which can be used to level them up). | |
− | Parameters:<br /> | + | Parameters:<br />{C}'''unit''' - The ID of the unit to give the kills to.<br />{C}'''amount''' - The number of kills given. |
− | ''' | ||
==Game== | ==Game== | ||
Line 214: | Line 98: | ||
Move the camera to the coordinates of pos. | Move the camera to the coordinates of pos. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''pos''' - an array of two elements, specifying the co-ordinates {x,y}. |
− | '''pos''' - an array of two elements, specifying the co-ordinates {x,y}. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===togglePauseGame(pauseStatus)=== | ===togglePauseGame(pauseStatus)=== | ||
Toggle the pause state of the existing game. | Toggle the pause state of the existing game. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''pauseStatus''' - 0 indicates normal game play, 1 indicates a paused game |
− | '''pauseStatus''' - 0 indicates normal game play, 1 indicates a paused game | ||
=== setPlayerAsWinner(factionID) === | === setPlayerAsWinner(factionID) === | ||
Sets the player with index faction ID as the winner. Would typically be followed by <tt>endGame()</tt>. | Sets the player with index faction ID as the winner. Would typically be followed by <tt>endGame()</tt>. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''faction '''- the index of the faction. |
− | '''faction '''- the index of the faction. | ||
=== endGame() === | === endGame() === | ||
Ends the scenario, bringing up the "you win" screen and asking the player if they want to leave the game. Usually would be called after <tt>setPlayerAsWinner()</tt> when victory conditions have been met. | Ends the scenario, bringing up the "you win" screen and asking the player if they want to leave the game. Usually would be called after <tt>setPlayerAsWinner()</tt> when victory conditions have been met. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==AI== | ==AI== | ||
Line 301: | Line 123: | ||
Disables a factions AI. None of the faction's units will move with this command. | Disables a factions AI. None of the faction's units will move with this command. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''faction '''- the index of the faction. |
− | '''faction '''- the index of the faction. | ||
===getAiEnabled(faction)=== | ===getAiEnabled(faction)=== | ||
Checks the enabled status of a factions AI. Returns 0 if the AI is disabled, and 1 if enabled. | Checks the enabled status of a factions AI. Returns 0 if the AI is disabled, and 1 if enabled. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''faction '''- the index of the faction. |
− | '''faction '''- the index of the faction. | ||
===enableConsume(faction)=== | ===enableConsume(faction)=== | ||
Line 319: | Line 139: | ||
Disbles a factions requirement to consume resources like food. All of the faction's units will not consume food type resources with this command. | Disbles a factions requirement to consume resources like food. All of the faction's units will not consume food type resources with this command. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''faction '''- the index of the faction. |
− | '''faction '''- the index of the faction. | ||
===getConsumeEnabled(faction)=== | ===getConsumeEnabled(faction)=== | ||
Checks the consume status of a factions AI. Returns 0 if disabled, and 1 if enabled. | Checks the consume status of a factions AI. Returns 0 if disabled, and 1 if enabled. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''faction '''- the index of the faction. |
− | '''faction '''- the index of the faction. | ||
==Sound== | ==Sound== | ||
Line 332: | Line 150: | ||
Play a static sound file specified by 'soundFile'. | Play a static sound file specified by 'soundFile'. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''soundFile''' - the filename of the sound file to play. |
− | '''soundFile''' - the filename of the sound file to play. | ||
===playStreamingSound(soundFile)=== | ===playStreamingSound(soundFile)=== | ||
Play a streaming sound file (background music) specified by 'soundFile'. | Play a streaming sound file (background music) specified by 'soundFile'. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''soundFile''' - the filename of the sound file to play. |
− | '''soundFile''' - the filename of the sound file to play. | ||
===stopStreamingSound(soundFile)=== | ===stopStreamingSound(soundFile)=== | ||
Stop playing a streaming sound file (background music) specified by 'soundFile'. | Stop playing a streaming sound file (background music) specified by 'soundFile'. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''soundFile''' - the filename of the sound file to play. |
− | '''soundFile''' - the filename of the sound file to play. | ||
===stopAllSound()=== | ===stopAllSound()=== | ||
Line 354: | Line 169: | ||
Register a cell 'trigger' event. Any time sourceUnit comes next to destUnit the eventID returned by this function will be triggered inside an event called '<cellTriggerEvent>'. | Register a cell 'trigger' event. Any time sourceUnit comes next to destUnit the eventID returned by this function will be triggered inside an event called '<cellTriggerEvent>'. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''sourceUnitID''' - the ID of a unit moves next to destUnit.<br />{C}'''destUnitID''' - the ID of a unit that source moves next to. |
− | '''sourceUnitID''' - the ID of a unit moves next to destUnit.<br /> | ||
− | '''destUnitID''' - the ID of a unit that source moves next to. | ||
− | Example: | + | Example: {C}<syntaxhighlight lang="lua"> |
− | <syntaxhighlight lang="lua"> | ||
<startup> | <startup> | ||
unitA = 'guard'; | unitA = 'guard'; | ||
Line 383: | Line 195: | ||
Register a cell 'trigger' event. Any time sourceUnit comes into the cell co-ordinates specified by pos, the event called '<cellTriggerEvent>' is triggered using the eventID returned by this function. | Register a cell 'trigger' event. Any time sourceUnit comes into the cell co-ordinates specified by pos, the event called '<cellTriggerEvent>' is triggered using the eventID returned by this function. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''sourceUnitID''' - the ID of a unit moves next to destUnit.<br />{C}'''pos''' - the x and y cell coordinates that will trigger the event when sourceUnitID enters the cell |
− | '''sourceUnitID''' - the ID of a unit moves next to destUnit.<br /> | ||
− | '''pos''' - the x and y cell coordinates that will trigger the event when sourceUnitID enters the cell | ||
===registerCellTriggerEventForFactionToUnit(sourceFactionID, destUnitID)=== | ===registerCellTriggerEventForFactionToUnit(sourceFactionID, destUnitID)=== | ||
− | Register a cell 'trigger' event. Any time a unit from sourceFaction comes next to destUnit the eventID returned by this function will be triggered inside an event called ' | + | Register a cell 'trigger' event. Any time a unit from sourceFaction comes next to destUnit the eventID returned by this function will be triggered inside an event called '<cellTriggerEvent>'. |
− | Parameters:<br /> | + | Parameters:<br />{C}'''sourceFactionID''' - the ID of a faction who has at least one unit that moves next to destUnit.<br />{C}'''destUnitID''' - the ID of a unit that source moves next to. |
− | '''sourceFactionID''' - the ID of a faction who has at least one unit that moves next to destUnit.<br /> | ||
− | '''destUnitID''' - the ID of a unit that source moves next to. | ||
===registerCellTriggerEventForFactionToLocation(sourceFactionID, pos)=== | ===registerCellTriggerEventForFactionToLocation(sourceFactionID, pos)=== | ||
Register a cell 'trigger' event. Any time a unit from sourceFaction comes into the cell co-ordinates specified by pos, the event called '<cellTriggerEvent>' is triggered using the eventID returned by this function. | Register a cell 'trigger' event. Any time a unit from sourceFaction comes into the cell co-ordinates specified by pos, the event called '<cellTriggerEvent>' is triggered using the eventID returned by this function. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''sourceFactionID''' - the ID of a faction who has at least one unit that moves next to destUnit.<br />{C}'''pos''' - the x and y cell co-ordinates that will trigger the event when a unit from sourceFactionID enters the cell. |
− | '''sourceFactionID''' - the ID of a faction who has at least one unit that moves next to destUnit.<br /> | ||
− | '''pos''' - the x and y cell co-ordinates that will trigger the event when a unit from sourceFactionID enters the cell. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===getCellTriggerEventCount(eventID)=== | ===getCellTriggerEventCount(eventID)=== | ||
Returns the number of times the event specified by eventID has been triggered. | Returns the number of times the event specified by eventID has been triggered. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''eventID''' - the ID of a previously registered event |
− | '''eventID''' - the ID of a previously registered event | ||
− | |||
− | |||
− | |||
===unregisterCellTriggerEvent(eventID)=== | ===unregisterCellTriggerEvent(eventID)=== | ||
Unregister the event specified by eventID. | Unregister the event specified by eventID. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''eventID''' - the ID of a previously registered event. |
− | '''eventID''' - the ID of a previously registered event | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===startTimerEvent()=== | ===startTimerEvent()=== | ||
Registers a timer and returns its unqiue ID, which can later be compared within a '<timerTriggerEvent>' event. | Registers a timer and returns its unqiue ID, which can later be compared within a '<timerTriggerEvent>' event. | ||
− | Example: | + | Example: {C}<syntaxhighlight lang="lua"> |
− | <syntaxhighlight lang="lua"> | ||
<timerTriggerEvent> | <timerTriggerEvent> | ||
if triggeredTimerEventId() == timer_event1 then | if triggeredTimerEventId() == timer_event1 then | ||
Line 512: | Line 236: | ||
Reset the timer specified by eventID. This function also returns the number of seconds elapsed since the timer started. | Reset the timer specified by eventID. This function also returns the number of seconds elapsed since the timer started. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''eventID''' - the ID of a previously registered timer. |
− | '''eventID''' - the ID of a previously registered timer. | ||
− | ===stopTimerEvent(eventID)=== | + | ===int stopTimerEvent(eventID)=== |
Stop the timer specified by eventID. This function also returns the number of seconds elapsed since the timer started. | Stop the timer specified by eventID. This function also returns the number of seconds elapsed since the timer started. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''eventID''' - the ID of a previously registered timer. |
− | '''eventID''' - the ID of a previously registered timer. | ||
===timerEventSecondsElapsed(eventID)=== | ===timerEventSecondsElapsed(eventID)=== | ||
This function returns the number of seconds elapsed since the timer started. | This function returns the number of seconds elapsed since the timer started. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''eventID''' - the ID of a previously registered timer. |
− | '''eventID''' - the ID of a previously registered timer. | ||
===triggeredCellEventId()=== | ===triggeredCellEventId()=== | ||
Line 533: | Line 254: | ||
This function returns the eventID that is currently triggering a '<timerTriggerEvent>'. | This function returns the eventID that is currently triggering a '<timerTriggerEvent>'. | ||
− | === | + | ==Queries== |
− | + | ===startLocation(faction) === | |
+ | Returns the start location for a given faction as a set of coordinates. | ||
+ | |||
+ | Parameters:<br />{C}'''faction '''- the index of the faction. | ||
+ | |||
+ | Example: {C}<syntaxhighlight lang="lua"> | ||
+ | createUnit ( "someunit", 0, {startLocation(0)[1] + 5, startLocation(0)[2]} ) | ||
+ | </syntaxhighlight> {C}This would create a unit 5 cells east of startLocation 0. | ||
− | |||
=== unitPosition(unitID) === | === unitPosition(unitID) === | ||
Returns the current location of a given unit. | Returns the current location of a given unit. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''unitID - '''the unitID of the unit whose position you wish to know. |
− | '''unitID - '''the unitID of the unit whose position you wish to know. | ||
− | Example: | + | Example: {C}<syntaxhighlight lang="lua"> |
− | <syntaxhighlight lang="lua"> | ||
if (unitPosition(myUnit)[1] > 47 and 75 > unitPosition(myUnit)[1] and unitPostion(myUnit)[2] > 95 ) then | if (unitPosition(myUnit)[1] > 47 and 75 > unitPosition(myUnit)[1] and unitPostion(myUnit)[2] > 95 ) then | ||
-- The unit's x co-ord is between 47 and 75, and its y cord is larger than 95. | -- The unit's x co-ord is between 47 and 75, and its y cord is larger than 95. | ||
Line 553: | Line 278: | ||
Returns the faction index of the unit with unitID. | Returns the faction index of the unit with unitID. | ||
− | Parameters:<br /> | + | Parameters:<br />{C}'''unitID''' - The ID of the unit who's faction you wish you check. |
− | '''unitID''' - The ID of the unit | ||
=== resourceAmount(resource, faction) === | === resourceAmount(resource, faction) === | ||
Line 562: | Line 286: | ||
'''resource''' - The name of the resource you wish you check.<br /> | '''resource''' - The name of the resource you wish you check.<br /> | ||
'''faction''' - The index of the faction to check. | '''faction''' - The index of the faction to check. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== lastCreatedUnitName() === | === lastCreatedUnitName() === | ||
Line 575: | Line 293: | ||
Returns the unit ID of the last created unit. | Returns the unit ID of the last created unit. | ||
− | === lastDeadUnitName() === | + | === lastDeadUnitName () === |
Returns the name of the last unit to die. | Returns the name of the last unit to die. | ||
− | === lastDeadUnit()=== | + | === lastDeadUnit ()=== |
Returns the ID of the last unit to die. | Returns the ID of the last unit to die. | ||
+ | |||
+ | === lastDeadUnitKillerName () === | ||
+ | Available in rev 2835. Returns the name of the killer of the last dead unit. Returns "" if the cause of death was not from an attacker (Attacked). | ||
+ | |||
+ | === lastDeadKillerUnit ()=== | ||
+ | Available in rev 2835. Returns the ID of the killer of the last dead unit. Returns -1 if the cause of death was not from an attacker (Attacked). | ||
===lastDeadUnitCauseOfDeath()=== | ===lastDeadUnitCauseOfDeath()=== | ||
− | Returns the following depending on how the last unit died: | + | Available in rev 2824. Returns the following depending on how the last unit died: |
:None = 0 | :None = 0 | ||
:Attacked = 1 | :Attacked = 1 | ||
Line 588: | Line 312: | ||
:Starved resource = 3 | :Starved resource = 3 | ||
:Negative regeneration = 4 | :Negative regeneration = 4 | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===lastAttackedUnit()=== | ===lastAttackedUnit()=== | ||
− | Returns the ID of the last unit which was attacked. | + | Available in rev 2823. Returns the ID of the last unit which was attacked. |
===lastAttackedUnitName()=== | ===lastAttackedUnitName()=== | ||
− | Returns the name of the last unit which was attacked. | + | Available in rev 2823. Returns the name of the last unit which was attacked. |
===lastAttackingUnit()=== | ===lastAttackingUnit()=== | ||
− | Returns the ID of the last unit to attack. | + | Available in rev 2823. Returns the ID of the last unit to attack. |
− | === | + | ===lastAttackingUnit()=== |
− | Returns the name of the last unit to attack | + | Available in rev 2823. Returns the name of the last unit to attack. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== unitCount(faction) === | === unitCount(faction) === | ||
Line 641: | Line 335: | ||
Parameters:<br /> | Parameters:<br /> | ||
− | '''faction''' - The index of the faction you wish to check. | + | '''faction''' - The index of the faction you wish to check. |
'''name''' - The name of the specific unit you wish to check. | '''name''' - The name of the specific unit you wish to check. | ||
===gameWon()=== | ===gameWon()=== | ||
Returns true if the human player won the game, and false if they did not. | Returns true if the human player won the game, and false if they did not. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== XML events == | == XML events == | ||
These are XML tags used to execute Lua code on its specified event. Variables can be used across different events. | These are XML tags used to execute Lua code on its specified event. Variables can be used across different events. | ||
− | <syntaxhighlight lang="xml">< | + | <syntaxhighlight lang="xml"><startup> |
<!-- | <!-- | ||
− | Code here will be executed | + | Code here will be executed once on startup. |
− | |||
− | |||
− | |||
− | |||
− | |||
--> | --> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<startup> | <startup> | ||
− | |||
− | |||
− | |||
− | |||
<unitCreatedOfType type="unitname"> | <unitCreatedOfType type="unitname"> | ||
<!-- | <!-- | ||
Line 749: | Line 363: | ||
<!-- | <!-- | ||
Code here will be executed every time a unit gets attacked. | Code here will be executed every time a unit gets attacked. | ||
+ | Works with SVN rev 2823. | ||
--> | --> | ||
</unitAttacked> | </unitAttacked> | ||
Line 754: | Line 369: | ||
<!-- | <!-- | ||
Code here will be executed every time a unit is attacking. | Code here will be executed every time a unit is attacking. | ||
+ | Works with SVN rev 2823. | ||
--> | --> | ||
</unitAttacking> | </unitAttacking> | ||
Line 779: | Line 395: | ||
==See Also== | ==See Also== | ||
− | |||
*[[Lua]] | *[[Lua]] | ||
*[[Scenarios]] | *[[Scenarios]] | ||
Line 789: | Line 404: | ||
[[Category:MG]] | [[Category:MG]] | ||
[[Category:Scenarios]] | [[Category:Scenarios]] | ||
− | |||
− |