Lua/Commands

From MegaGlest
Jump to navigation Jump to search

This page is just for the shared commands between all three engines, regular Glest, GAE, and MegaGlest.

For a full list of Lua functions only available in MegaGlest, see MG/Lua.

For a full list of Lua functions only available in GAE, see GAE/Lua.


Lua is the scripting language for Glest, and is used to create scenarios. This page does not explain how to create such scenarios or how to use Lua, but is a collection of the Lua commands available for Glest. For an explanation of how to use Lua in Glest, please see the Lua page.

Game Control[edit]

disableAi(factionIndex)[edit]

Disables AI control of a faction.

Parameters:

  • factionIndex: the index of the faction to disable the AI on.

setPlayerAsWinner(factionIndex)[edit]

Sets a faction as having won the game.

Parameters:

  • factionIndex: the index of the faction to set as a winner.

endGame()[edit]

Finishes the game.

Gui Control[edit]

setCameraPosition(pos)[edit]

Move the camera so that the cell at pos is in the centre of the view.

Parameters:

  • pos: a position to move the camera to, a tables with two values { x, y }

User Feedback[edit]

showMessage(text, header)[edit]

Displays a message to the user in a messagebox that must be dismissed, the game is paused when the message is shown.

Parameters:

  • text: A string identifying the text to look up in the lang file, this is the 'body' of the message.
  • header: A string, looked up in the lang file, for the message box 'title-bar'

setDisplayText(text)[edit]

Displays a message to the user at the top of the screen, remains until setDisplayText() is called again, or clearDisplayText() is called.

Parameters:

  • text: A string identifying the text to look up in the lang file, the text for to display

clearDisplayText()[edit]

Clears the display message from the top of the screen.

Unit creation and Resource/Upgrade hand-outs[edit]

createUnit(type, factionIndex, pos)[edit]

Create a unit a unit for a faction at (or near) pos.

Parameters:

  • type: The unit type to create
  • factionIndex: The index of the faction to create the unit for
  • pos: a position to create the unit at (or near), array of two elements { x, y }

giveResource(type, factionIndex, amount)[edit]

Gifts some resources to a faction (don't forget to make sure they can store them!)

Parameters:

  • type: The resource type
  • factionIndex: The index of the faction to give resources to
  • amount: the amount of the resource to give

Unit commands[edit]

givePositionCommand(unitId, command, pos)[edit]

Give a position based command to a unit

Parameters:

  • unitId: The ID of the unit to give the command to
  • command: the name of the command to give, one of 'move', or 'attack'
  • pos: the command's target position { x, y }

giveProductionCommand(unitId, unitType)[edit]

Give a poduce or morph command to a unit

Parameters:

  • unitId: The ID of the unit to give the command to
  • unitType: the type of unit to produce

giveUpgradeCommand(unitId, upgrade)[edit]

Give an upgrade command to a unit.

Parameters:

  • unitId: The ID of the unit to give the command to
  • upgrade: the Upgrade to produce

Queries[edit]

startLocation(factionIndex)[edit]

Returns a start location, as an array of two elements.

Parameters:

  • factionIndex: The index of the faction

unitPosition(unitId)[edit]

Returns the location of a unit, as an array of two elements.

Parameters:

  • unitId: The ID of the unit.

unitFaction(unitId)[edit]

Returns the faction index of a unit.

Parameters:

  • unitId: The ID of the unit.

resourceAmount(resource, factionIndex)[edit]

Returns the amount of a resource a player has.

Parameters:

  • resource: A string identifying the resource of interest
  • factionIndex: The index of the factiont.

lastCreatedUnit()[edit]

Returns the ID of the last created unit.

lastDeadUnit()[edit]

Returns the ID of the last unit to die.

unitCount(factionIndex)[edit]

Returns the number of units a player has.

Parameters:

  • factionIndex: The index of the faction

unitCountOfType(factionIndex, type)[edit]

Returns the number of units of a specific type a player has.

Parameters:

  • factionIndex: The index of the faction
  • type: String identifying the unit type of interest

See Also[edit]

External Links[edit]