Mod API Reference: Difference between revisions
No edit summary |
m →Newer API features: alphabeticalised |
||
(32 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
This explains how to use | This explains how to use Warzone's [[Mods|mod]] API and links to the documentation for each object type. | ||
== Types == | == Types == | ||
When writing a mod, you'll encounter variables/objects of three basic types: | When writing a mod, you'll encounter variables/objects of three basic types: | ||
* Primitives: strings, | * Primitives: strings, numbers, booleans, etc. | ||
* Tables: collections of key/value pairs. A table is a lot like a hashmap or dictionary in other languages. Note that in | * Tables: collections of key/value pairs. A table is a lot like a hashmap or dictionary in other languages. Note that in Warzone, the key of a table will always be either a string or an integer. Some places in this reference will refer to Arrays which are just tables with numeric keys starting at 1. | ||
* Proxy objects: Discussed in the next section. | * Proxy objects: Discussed in the next section. | ||
== Proxy Objects == | == Proxy Objects == | ||
A '''proxy object''' proxies information back and forth between your mod and | A '''proxy object''' proxies information back and forth between your mod and Warzone. You can tell if an object is a proxy object by looking for a <code>proxyType</code> field. All proxy objects always have the following fields: | ||
* proxyType: A string identifying the type of proxy object. | * proxyType: A string identifying the type of proxy object. | ||
Line 20: | Line 20: | ||
Here's a handy function you can include in your mod to print out everything on a proxy object: | Here's a handy function you can include in your mod to print out everything on a proxy object: | ||
<pre style="overflow: auto"> | |||
function PrintProxyInfo(obj) | |||
print('type=' .. obj.proxyType .. ' readOnly=' .. tostring(obj.readonly) .. ' readableKeys=' .. table.concat(obj.readableKeys, ',') .. ' writableKeys=' .. table.concat(obj.writableKeys, ',')); | print('type=' .. obj.proxyType .. ' readOnly=' .. tostring(obj.readonly) .. ' readableKeys=' .. table.concat(obj.readableKeys, ',') .. ' writableKeys=' .. table.concat(obj.writableKeys, ',')); | ||
end | |||
</pre> | |||
== Writing Tables == | == Writing Tables == | ||
If a writable | If a writable Warzone proxy object exposes a table, and you wish to make changes to that table, you must assign the table back to the proxy object. For example, assume you have a <code>GameStanding</code> object named <code>standing</code> which exposes the <code>Cards</code> table, and you want to add something at index 9: | ||
standing.Cards[9] = something --WRONG! | standing.Cards[9] = something --WRONG! | ||
Line 44: | Line 46: | ||
* [[Mod API Reference:Armies|Armies]] | * [[Mod API Reference:Armies|Armies]] | ||
* [[Mod API Reference:BonusDetails|BonusDetails]] | * [[Mod API Reference:BonusDetails|BonusDetails]] | ||
* [[Mod API Reference:Boss1|Boss1]] | |||
* [[Mod API Reference:Boss2|Boss2]] | |||
* [[Mod API Reference:Boss3|Boss3]] | |||
* [[Mod API Reference:Boss4|Boss4]] | |||
* [[Mod API Reference:CardGame|CardGame]] | * [[Mod API Reference:CardGame|CardGame]] | ||
* [[Mod API Reference:CardGameAbandon|CardGameAbandon]] | * [[Mod API Reference:CardGameAbandon|CardGameAbandon]] | ||
Line 60: | Line 66: | ||
* [[Mod API Reference:CardInstance|CardInstance]] | * [[Mod API Reference:CardInstance|CardInstance]] | ||
* [[Mod API Reference:ClanPlayerInfo|ClanPlayerInfo]] | * [[Mod API Reference:ClanPlayerInfo|ClanPlayerInfo]] | ||
* [[Mod API Reference:ClientGame|ClientGame]] | |||
* [[Mod API Reference:Commander|Commander]] | |||
* [[Mod API Reference:CustomScenario|CustomScenario]] | * [[Mod API Reference:CustomScenario|CustomScenario]] | ||
* [[Mod API Reference:CustomScenarioTerritory|CustomScenarioTerritory]] | * [[Mod API Reference:CustomScenarioTerritory|CustomScenarioTerritory]] | ||
Line 70: | Line 78: | ||
* [[Mod API Reference:GameOrderAttackTransferResult|GameOrderAttackTransferResult]] | * [[Mod API Reference:GameOrderAttackTransferResult|GameOrderAttackTransferResult]] | ||
* [[Mod API Reference:GameOrderBossEvent|GameOrderBossEvent]] | * [[Mod API Reference:GameOrderBossEvent|GameOrderBossEvent]] | ||
* [[Mod API Reference:GameOrderCustom|GameOrderCustom]] | |||
* [[Mod API Reference:GameOrderDeploy|GameOrderDeploy]] | * [[Mod API Reference:GameOrderDeploy|GameOrderDeploy]] | ||
* [[Mod API Reference:GameOrderDiscard|GameOrderDiscard]] | * [[Mod API Reference:GameOrderDiscard|GameOrderDiscard]] | ||
* [[Mod API Reference:GameOrderEvent|GameOrderEvent]] | |||
* [[Mod API Reference:GameOrderPlayCard|GameOrderPlayCard]] | * [[Mod API Reference:GameOrderPlayCard|GameOrderPlayCard]] | ||
* [[Mod API Reference:GameOrderPlayCardAbandon|GameOrderPlayCardAbandon]] | * [[Mod API Reference:GameOrderPlayCardAbandon|GameOrderPlayCardAbandon]] | ||
Line 94: | Line 104: | ||
* [[Mod API Reference:GameStanding|GameStanding]] | * [[Mod API Reference:GameStanding|GameStanding]] | ||
* [[Mod API Reference:GameWL|GameWL]] | * [[Mod API Reference:GameWL|GameWL]] | ||
* [[Mod API Reference:IncomeMod|IncomeMod]] | |||
* [[Mod API Reference:IsVersionOrHigher|IsVersionOrHigher]] | |||
* [[Mod API Reference:MapDetails|MapDetails]] | * [[Mod API Reference:MapDetails|MapDetails]] | ||
* [[Mod API Reference:MapFamily|MapFamily]] | * [[Mod API Reference:MapFamily|MapFamily]] | ||
Line 107: | Line 119: | ||
* [[Mod API Reference:TerritoryModification|TerritoryModification]] | * [[Mod API Reference:TerritoryModification|TerritoryModification]] | ||
* [[Mod API Reference:TerritoryStanding|TerritoryStanding]] | * [[Mod API Reference:TerritoryStanding|TerritoryStanding]] | ||
* [[Mod API Reference:TickCount|TickCount]] | |||
* [[Mod API Reference:UI|UI]] | |||
* [[Mod API Reference:WL|WL]] | |||
== Newer API features == | |||
Some features were introduced after the first version of the Mod API framework and should be checked for using [[Mod_API_Reference:IsVersionOrHigher|IsVersionOrHigher]]: | |||
{| class="wikitable" | |||
|- | |||
! Version | |||
! Features | |||
|- | |||
| 5.26 | |||
| Use [[Mod_API_Reference:ServerGame|ServerGame.SetPlayerResource]] in [[Mod_Hooks#Server_Hooks|Server_StartGame]] | |||
|- | |||
| 5.24.2 | |||
| [[Mod_API_Reference:CustomSpecialUnit|CustomSpecialUnit.Health]] | |||
|- | |||
| 5.24.1 | |||
| [[Mod_API_Reference:CustomSpecialUnit|CustomSpecialUnit.CombatOrder]]<br>[[Mod_API_Reference:TickCount|WL.TickCount]] | |||
|- | |||
| 5.22.2 | |||
| [[Mod_API_Reference:Boss1|Boss1.CombatOrder]]<br>[[Mod_API_Reference:Boss2|Boss2.CombatOrder]]<br>[[Mod_API_Reference:Boss3|Boss3.CombatOrder]]<br>[[Mod_API_Reference:Boss4|Boss4.CombatOrder]]<br>[[Mod_API_Reference:Commander|Commander.CombatOrder]]<br>[[Mod_API_Reference:CustomSpecialUnitBuilder|CustomSpecialUnitBuilder.Health]] | |||
|- | |||
| 5.22 | |||
| [[Mod_API_Reference:GameOrderCustom|GameOrderCustom.OccursInPhaseOpt]]<br>[[Mod_API_Reference:TerritoryModification|TerritoryModification.RemoveSpecialUnitsOpt]] | |||
|- | |||
| 5.21 | |||
| [[Mod_Hooks#Client_Hooks|Client_PresentCommercePurchaseUI]]<br>[[Mod_API_Reference:ClientGame|ClientGame.CreateLocatorCircle]]<br>[[Mod_API_Reference:ClientGame|ClientGame.HighlightTerritories]]<br>[[Mod_API_Reference:CustomSpecialUnit|CustomSpecialUnit]]<br>[[Mod_API_Reference:GameOrderEvent|GameOrderEvent.JumpToActionSpotOpt]]<br>[[Mod_API_Reference:GameOrderEventResult|GameOrderEventResult.CardInstancesCreated]]<br>[[Mod_API Reference:UI|UI.IsDestroyed]]<br>[[Mod_API_Reference:UI|WL.CancelClickIntercept]] | |||
|- | |||
| 5.20 | |||
| Setting [[Mod_API_Reference:TerritoryStanding|TerritoryStanding]].OwnerPlayerID to [[Mod_API_Reference:PlayerID|WL.PlayerID.AvailableForDistribution]]<br>[[Mod_API_Reference:GameOrderEvent|GameOrderEvent.AddCardPiecesOpt]]<br>[[Mod_API_Reference:GameOrderEvent|GameOrderEvent.AddResourceOpt]]<br>[[Mod_API_Reference:GameOrderEvent|GameOrderEvent.RemoveWholeCardsOpt]]<br>[[Mod_API_Reference:TerritoryModification|TerritoryModification.AddArmies]]<br>[[Mod_API_Reference:TerritoryModification|TerritoryModification.AddStructuresOpt]] | |||
|- | |||
| 5.17 | |||
| Using argument two of <code>addNewOrder</code> in [[Mod_Hooks#Server_Hooks|Server_AdvanceTurn_Order]]<br>[[Mod_API_Reference:GameOrderEvent|GameOrderEvent.IncomeMods]]<br>[[Mod_API_Reference:IncomeMod|IncomeMod]]<br>[[Mod_API_Reference:UI|UI.InterceptNextBonusLinkClick]]<br>[[Mod_API_Reference:UI|UI.InterceptNextTerritoryClick]]<br>[[Mod_API_Reference:IsVersionOrHigher|WL.IsVersionOrHigher]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Arena]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.ArmyCache]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.ArmyCamp]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Attack]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Crafter]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.DigSite]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Draft]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Hospital]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Market]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.MercenaryCamp]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Mine]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.MoneyCache]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Mortar]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Power]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Recipe]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.ResourceCache]]<br>[[Mod_API_Reference:StructureType|WL.StructureType.Smelter]] | |||
|} | |||
There is a chance that a player has a version of the app that pre-dates the introduction of the [[Mod_API_Reference:IsVersionOrHigher|IsVersionOrHigher]] function. Many features were added after the first version of the Mod API Framework, but before the introduction of the function: | |||
{| class="wikitable" | |||
|- | |||
! Version | |||
! Features | |||
|- | |||
| Up to 4.14.2 | |||
| Various bug fixes / performance enhancements relating to mods. No other changes made to mod API framework until version 5.17. | |||
|- | |||
| 3.20.2 | |||
| Mod support for Commerce games (Commerce added in 3.20.0) | |||
|- | |||
| 3.19.3 | |||
| Bug fixes for GameOrderPlayCard, Armies.Add, Armies.Subtract<br>[[Mod_Hooks#Client_Hooks|Client_GameRefresh]]<br>[[Mod_Hooks#Client_Hooks|Client_PresentMenuUI]]<br>[[Mod_Game_Data_Storage|Data storage]]<br>[[Mod_API_Reference:Game|Game]].CreateDialog<br>[[Mod_API_Reference:Game|Game]].SendGameCustomMessage<br>[[Mod_API_Reference:GamePlayer|GamePlayer]].Income<br>[[Mod_Hooks#Server_Hooks|Server_GameCustomMessage]] | |||
|- | |||
| 3.19.2 | |||
| [[Mod_API_Reference:GameOrderCustom|GameOrderCustom]]<br>[[Mod_API_Reference:UI|UI]].Alert<br>UI.Destroy<br>UI.PromptFromList | |||
|- | |||
| 3.18.2 | |||
| Moved all WarLight mod classes into the global "WL" namespace. For example, to create an Armies object instead of just saying "Armies()", you now say WL.Armies.Create() | |||
|- | |||
| 3.18.0 | |||
| Mod API Framework added | |||
|} | |||
[[Category:Mod Developers Guide]][[Category:Mod API Reference]] |
Latest revision as of 23:10, 1 July 2024
This explains how to use Warzone's mod API and links to the documentation for each object type.
Types
When writing a mod, you'll encounter variables/objects of three basic types:
- Primitives: strings, numbers, booleans, etc.
- Tables: collections of key/value pairs. A table is a lot like a hashmap or dictionary in other languages. Note that in Warzone, the key of a table will always be either a string or an integer. Some places in this reference will refer to Arrays which are just tables with numeric keys starting at 1.
- Proxy objects: Discussed in the next section.
Proxy Objects
A proxy object proxies information back and forth between your mod and Warzone. You can tell if an object is a proxy object by looking for a proxyType
field. All proxy objects always have the following fields:
- proxyType: A string identifying the type of proxy object.
- readOnly: False if you're allowed to make changes to this proxy object, or true if it's read-only.
- readableKeys: An array containing all fields you're allowed to read from this object.
- writableKeys: An array containing all fields you're allowed to change on this object if readOnly is False.
To read a field, simply read it like a property: obj.field
. Similarly, to write to a proxy object, just assign to that field: obj.field = newVal
.
Here's a handy function you can include in your mod to print out everything on a proxy object:
function PrintProxyInfo(obj) print('type=' .. obj.proxyType .. ' readOnly=' .. tostring(obj.readonly) .. ' readableKeys=' .. table.concat(obj.readableKeys, ',') .. ' writableKeys=' .. table.concat(obj.writableKeys, ',')); end
Writing Tables
If a writable Warzone proxy object exposes a table, and you wish to make changes to that table, you must assign the table back to the proxy object. For example, assume you have a GameStanding
object named standing
which exposes the Cards
table, and you want to add something at index 9:
standing.Cards[9] = something --WRONG!
This code won't work since the proxy object isn't having anything assigned to it. Proxy objects are only aware of changes when something is directly assigned into them. To make this work, you must assign the table into the proxy object's field:
local cards = standing.Cards cards[9] = something standing.Cards = cards; --Right
Note: If you use lua's type
function, proxy objects will identify themselves as tables. However, that should be considered an implementation detail. For the purposes of this wiki, proxy objects aren't considered tables.
API Reference
- ActiveCard
- ActiveCardWoreOff
- Armies
- BonusDetails
- Boss1
- Boss2
- Boss3
- Boss4
- CardGame
- CardGameAbandon
- CardGameAirlift
- CardGameBlockade
- CardGameBomb
- CardGameDiplomacy
- CardGameGift
- CardGameOrderDelay
- CardGameOrderPriority
- CardGameReconnaissance
- CardGameReinforcement
- CardGameSanctions
- CardGameSpy
- CardGameSurveillance
- CardInstance
- ClanPlayerInfo
- ClientGame
- Commander
- CustomScenario
- CustomScenarioTerritory
- DistributionMode
- Game
- GameColor
- GameOpenSeat
- GameOrder
- GameOrderAttackTransfer
- GameOrderAttackTransferResult
- GameOrderBossEvent
- GameOrderCustom
- GameOrderDeploy
- GameOrderDiscard
- GameOrderEvent
- GameOrderPlayCard
- GameOrderPlayCardAbandon
- GameOrderPlayCardAirlift
- GameOrderPlayCardAirliftResult
- GameOrderPlayCardBlockade
- GameOrderPlayCardBomb
- GameOrderPlayCardDiplomacy
- GameOrderPlayCardFogged
- GameOrderPlayCardGift
- GameOrderPlayCardOrderDelay
- GameOrderPlayCardOrderPriority
- GameOrderPlayCardReconnaissance
- GameOrderPlayCardReinforcement
- GameOrderPlayCardSanctions
- GameOrderPlayCardSpy
- GameOrderPlayCardSurveillance
- GameOrderReceiveCard
- GameOrderStateTransition
- GamePlayer
- GameSettings
- GameStanding
- GameWL
- IncomeMod
- IsVersionOrHigher
- MapDetails
- MapFamily
- NoParameterCardInstance
- PendingStateTransition
- PlayerCards
- PlayerInfo2
- ReinforcementCardInstance
- ServerGame
- SpecialUnit
- TerritoryConnection
- TerritoryDetails
- TerritoryModification
- TerritoryStanding
- TickCount
- UI
- WL
Newer API features
Some features were introduced after the first version of the Mod API framework and should be checked for using IsVersionOrHigher:
There is a chance that a player has a version of the app that pre-dates the introduction of the IsVersionOrHigher function. Many features were added after the first version of the Mod API Framework, but before the introduction of the function:
Version | Features |
---|---|
Up to 4.14.2 | Various bug fixes / performance enhancements relating to mods. No other changes made to mod API framework until version 5.17. |
3.20.2 | Mod support for Commerce games (Commerce added in 3.20.0) |
3.19.3 | Bug fixes for GameOrderPlayCard, Armies.Add, Armies.Subtract Client_GameRefresh Client_PresentMenuUI Data storage Game.CreateDialog Game.SendGameCustomMessage GamePlayer.Income Server_GameCustomMessage |
3.19.2 | GameOrderCustom UI.Alert UI.Destroy UI.PromptFromList |
3.18.2 | Moved all WarLight mod classes into the global "WL" namespace. For example, to create an Armies object instead of just saying "Armies()", you now say WL.Armies.Create() |
3.18.0 | Mod API Framework added |