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]].
 
Notice: You can’t use the <-operator in within the XML-events. You can use an external script instead or invert the logic.
 
  
 
==Text==
 
==Text==
Line 140: Line 138:
 
'''unitID''' - The ID of the unit to give the kills to.<br />
 
'''unitID''' - The ID of the unit to give the kills to.<br />
 
'''amount''' - The number of kills given.
 
'''amount''' - The number of kills given.
 
===getUnitProperty(unitId,typeId)===
 
Returns the value of the type of the unit.
 
The type can be a number between 1 and 5.
 
1=hp
 
2=ep
 
3=level
 
4=field
 
5=skill
 
 
getUnitProperty is dedicated for hp,ep and field. For skill and level see getUnitPropertyName(unitId,typeId).
 
 
===getUnitPropertyName(unitId,typeId)===
 
Returns the name of the type of the unit.
 
The type can be a number between 1 and 5.
 
1=hp
 
2=ep
 
3=level
 
4=field
 
5=skill
 
 
getUnitPropertyName is dedicated for skill and level. For hp,ep and field see getUnitProperty(unitId,typeId).
 
  
 
===selectUnit(unitID)===
 
===selectUnit(unitID)===
Line 216: Line 192:
 
Parameters:<br />
 
Parameters:<br />
 
'''pos''' - an array of two elements, specifying the co-ordinates {x,y}.
 
'''pos''' - an array of two elements, specifying the co-ordinates {x,y}.
 
=== shakeCamera(intensity, duration) ===
 
Causes the camera to shake.
 
 
Parameters:<br />
 
'''intensity''' - Intensity of the shaking effect<br />
 
'''duration''' - Duration of the shaking effect in update frames (40 equals one second)
 
 
=== shakeCameraOnUnit(intensity, duration, unitId) ===
 
Same as above, but the shake intensity is affected by the distance between camera and unit.
 
Useful if the camera should only shake, when the unit is in sight.
 
 
Parameters:<br />
 
'''intensity''' - Intensity of the shaking effect<br />
 
'''duration''' - Duration of the shaking effect in update frames (40 equals one second)<br />
 
'''unitId''' - Unit ID of the unit, which should influence the shake intensity
 
  
 
===togglePauseGame(pauseStatus)===
 
===togglePauseGame(pauseStatus)===
Line 249: Line 209:
  
 
=== loadScenario(scenario, keepFactions) ===
 
=== loadScenario(scenario, keepFactions) ===
Loads another scenario from inside an existing scenario. The new scenario must have the same techtree and factions, but map, tileset can change.
+
Loads another scenario from inside an existing scenario. The new scenario must have the same techtree and factions, but map, tileset can change.  
  
 
Parameters:<br />
 
Parameters:<br />
Line 263: Line 223:
 
===getAttackWarningsEnabled()===
 
===getAttackWarningsEnabled()===
 
Returns the current status of the attack warnings system (true if enabled, false if disabled).
 
Returns the current status of the attack warnings system (true if enabled, false if disabled).
 
===getIsDayTime()===
 
Returns if it is day ingame. ( 1 is day and 0 is night )
 
 
===getIsNightTime()===
 
Returns if it is night ingame. ( 1 is night and 0 is day )
 
 
===getTimeOfDay()===
 
Returns the ingame time of the day.
 
 
=== storeSaveGameDate(key, value) ===
 
Stores ''value'' at ''key'' in the savegame.<br />
 
'''''Only available in the onSave-tag!'''''
 
 
Parameters:<br />
 
'''key''' - a key string<br />
 
'''value''' - a string that is stored
 
 
=== loadSaveGameDate(key) ===
 
Returns the ''value'' stored at ''key'' in the savegame.<br />
 
'''''Only available in the onLoad-tag!'''''
 
 
Parameters:<br />
 
'''key''' - a key string
 
[[Category:MG]]
 
[[Category:Scenarios]]
 
[[Category:Lua]]
 
  
 
==AI==
 
==AI==
Line 406: Line 339:
 
Parameters:<br />
 
Parameters:<br />
 
'''pos''' - the x and y coordinate of the top left point then the bottom right point (eg, {10,10,5,5} would create a box from points (10,10) to (5,5)).
 
'''pos''' - the x and y coordinate of the top left point then the bottom right point (eg, {10,10,5,5} would create a box from points (10,10) to (5,5)).
 
 
===registerDayNightEvent()===
 
Enables the Day/Night Event which will be triggered when night or day starts.
 
 
Example:
 
<syntaxhighlight lang="lua">
 
<startup>
 
registerDayNightEvent()
 
</startup>
 
<dayNightTriggerEvent> 
 
if getIsDayTime() == 1 then
 
setDisplayText('It is day time, a safer time to roam!')
 
    else
 
setDisplayText('**It is night time, WATCH OUT!**')
 
    end
 
</dayNightTriggerEvent>
 
</syntaxhighlight>
 
 
===unregisterDayNightEvent()===
 
Disables the Day/Night Event.
 
  
 
===triggeredEventAreaEntryUnitId()===
 
===triggeredEventAreaEntryUnitId()===
Line 433: Line 345:
 
===triggeredEventAreaExitUnitId()===
 
===triggeredEventAreaExitUnitId()===
 
Returns the unit ID of the unit who exited a registered cell area trigger event.
 
Returns the unit ID of the unit who exited a registered cell area trigger event.
 
===lastUnitTriggerEventUnit()===
 
Returns the ID of the Unit which triggered the UnitTriggerEvent.
 
 
===lastUnitTriggerEventType()===
 
Returns the ID of property which changed.
 
1=hp
 
2=ep
 
3=level
 
4=field
 
5=skill
 
  
 
===getCellTriggerEventCount(eventID)===
 
===getCellTriggerEventCount(eventID)===
Line 459: Line 360:
 
Parameters:<br />
 
Parameters:<br />
 
'''eventID''' - the ID of a previously registered event.
 
'''eventID''' - the ID of a previously registered event.
 
===registerUnitTriggerEvent(unitId)===
 
Registers a unit trigger event for a unit which will be triggered if one of his properties changes.
 
 
Example:
 
<syntaxhighlight lang="lua">
 
<startup>
 
    createUnit('battle_machine', 1, startLocation(1))
 
 
    player2_battlemachine= lastCreatedUnit()
 
    registerUnitTriggerEvent(player2_battlemachine)
 
</startup>
 
<unitTriggerEvent>
 
    if player2_battlemachine == lastUnitTriggerEventUnit() then
 
                       
 
        if lastUnitTriggerEventType() == 1 then -- hp changed
 
            print('Unit hp is now: ' .. getUnitProperty(lastUnitTriggerEventUnit(),lastUnitTriggerEventType()))
 
        elseif lastUnitTriggerEventType() == 2 then -- ep changed
 
            print('Unit ep is now: ' .. getUnitProperty(lastUnitTriggerEventUnit(),lastUnitTriggerEventType()))
 
        elseif lastUnitTriggerEventType() == 3 then -- level changed
 
            print('Unit level is now: ' .. getUnitPropertyName(lastUnitTriggerEventUnit(),lastUnitTriggerEventType()))
 
        elseif lastUnitTriggerEventType() == 4 then -- field changed
 
            print('Unit field is now: ' .. getUnitProperty(lastUnitTriggerEventUnit(),lastUnitTriggerEventType()))
 
        elseif lastUnitTriggerEventType() == 5 then -- skill changed
 
            print('Unit skill is now: ' .. getUnitPropertyName(lastUnitTriggerEventUnit(),lastUnitTriggerEventType()))
 
        end
 
    end
 
</unitTriggerEvent>
 
</syntaxhighlight>
 
 
===unregisterUnitTriggerEvent(unitId)===
 
Unregisters the unit trigger event for a unit.
 
  
 
===startTimerEvent()===
 
===startTimerEvent()===
Line 672: Line 541:
  
 
===getUnitsForFaction(factionIndex, commandTypeName, field)===
 
===getUnitsForFaction(factionIndex, commandTypeName, field)===
Returns an array (table) of units in the specified faction which lists all units which have the specified command and can use it on the specified field (such as being able to attack air units).<br />
+
Returns an array (table) of units in the specified faction which:
<tt>0</tt> for land and <tt>1</tt> for air field.
+
*If only the commandTypeName is specified, the table will be a list of all units which have that command (such as <tt>attack</tt>).
[[Category:MG]]
+
*If the commandTypeName is empty and only the field is specified (<tt>0</tt> = land, <tt>1</tt> = air), the table will list all units which are in that specific field.
[[Category:Scenarios]]
+
*If both commandTypeName and the field are specified, the table will list all units which have the specified command can can use it on the specified field (such as being able to attack air units).
[[Category:Lua]]
 
  
 
===getUnitCurrentField(unitId)===
 
===getUnitCurrentField(unitId)===
Line 692: Line 560:
  
 
Parameters:<br />
 
Parameters:<br />
'''flashCount''' -<br />
+
'''flashCount''' - <br />
 
'''factionIndex''' - index of the faction who "placed" the marker.<br />
 
'''factionIndex''' - index of the faction who "placed" the marker.<br />
 
'''note''' - note on the marker.<br />
 
'''note''' - note on the marker.<br />
Line 702: Line 570:
  
 
Parameters:<br />
 
Parameters:<br />
'''factionIndex''' - index of the faction whose camera you wish to move.<br />
+
'''factionIndex''' - index of the faction whose camera you wish to move.<br />
 
'''pos''' - x and y coordinates for the camera's position.
 
'''pos''' - x and y coordinates for the camera's position.
  
Line 709: Line 577:
  
 
Parameters:<br />
 
Parameters:<br />
'''teamNumber''' - team number whose camera you wish to move.<br />
+
'''teamNumber''' - team number whose camera you wish to move.<br />
 
'''pos''' - x and y coordinates for the camera's position.
 
'''pos''' - x and y coordinates for the camera's position.
  
Line 715: Line 583:
 
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"><global>
+
<syntaxhighlight lang="xml"><startup>
 
<!--
 
<!--
Code here will be executed whenever the scenario is started.
+
Code here will be executed once on startup.
 
-->
 
-->
</global>
 
<onSave>
 
<!--
 
Code here will be executed when the game is about to save.
 
-->
 
</onSave>
 
<onLoad>
 
<!--
 
Code here will be executed when the savegame got loaded.
 
-->
 
</onLoad>
 
 
<startup>
 
<startup>
<!--
 
Code here will be executed once on startup.
 
-->
 
</startup>
 
 
<unitCreatedOfType type="unitname">
 
<unitCreatedOfType type="unitname">
 
<!--
 
<!--
Line 790: Line 643:
 
[[Category:Scenarios]]
 
[[Category:Scenarios]]
 
[[Category:Lua]]
 
[[Category:Lua]]
[[Category:XMLs]]
 

Please note that all contributions to MegaGlest are considered to be released under the Creative Commons Attribution Share Alike (see MegaGlest:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)