Mod API Reference: Difference between revisions

From Warzone Wiki
Jump to navigation Jump to search
DanWL60 (talk | contribs)
DanWL60 (talk | contribs)
→‎Newer API features: went through change logs to find more
Line 194: Line 194:
| [[Mod_API_Reference:GameOrderEvent|GameOrderEvent.AddResourceOpt]]
| [[Mod_API_Reference:GameOrderEvent|GameOrderEvent.AddResourceOpt]]
| 5.20
| 5.20
|-
| [[Mod_API_Reference:GameOrderEvent|GameOrderEvent.AddCardPiecesOpt]]
| 5.20
|-
| [[Mod_API_Reference:GameOrderEvent|GameOrderEvent.RemoveWholeCardsOpt]]
| 5.20
|-
| [[Mod_API_Reference:TerritoryModification|TerritoryModification.AddArmies]]
| 5.20
|-
| [[Mod_API_Reference:TerritoryModification|TerritoryModification.AddStructuresOpt]]
| 5.20
|-
| [[Mod_Hooks#Client_Hooks|Client_PresentCommercePurchaseUI]]
| 5.21
|-
| [[Mod_API_Reference:ClientGame|ClientGame.HighlightTerritories]]
| 5.21
|-
| [[Mod_API_Reference:ClientGame|ClientGame.CreateLocatorCircle]]
| 5.21
|-
| [[Mod_API Reference:UI|UI.IsDestroyed]]
| 5.21
|-
| [[Mod_API_Reference:UI|WL.CancelClickIntercept]]
| 5.21
|-
| [[Mod_API_Reference:CustomSpecialUnit|CustomSpecialUnit]]
| 5.21
|-
| [[Mod_API_Reference:GameOrderEventResult|GameOrderEventResult.CardInstancesCreated]]
| 5.21
|-
| [[Mod_API_Reference:GameOrderEvent|GameOrderEvent.JumpToActionSpotOpt]]
| 5.21
|-
|-
| [[Mod_API_Reference:GameOrderCustom|GameOrderCustom.OccursInPhaseOpt]]
| [[Mod_API_Reference:GameOrderCustom|GameOrderCustom.OccursInPhaseOpt]]
Line 214: Line 250:
|-
|-
| [[Mod_API_Reference:Commander|Commander.CombatOrder]]
| [[Mod_API_Reference:Commander|Commander.CombatOrder]]
| 5.22.2
|-
| [[Mod_API_Reference:CustomSpecialUnitBuilder|CustomSpecialUnitBuilder.Health]]
| 5.22.2
| 5.22.2
|-
|-
Line 224: Line 263:
| [[Mod_API_Reference:CustomSpecialUnit|CustomSpecialUnit.Health]]
| [[Mod_API_Reference:CustomSpecialUnit|CustomSpecialUnit.Health]]
| 5.24.2
| 5.24.2
|}
Some new abilities were also added.
{| class="wikitable"
|-
! Ability
! New in version
|-
| Using argument two of <code>addNewOrder</code> in [[Mod_Hooks#Server_Hooks|Server_AdvanceTurn_Order]]
| 5.17
|-
| Setting [[Mod_API_Reference:TerritoryStanding|TerritoryStanding]].OwnerPlayerID to [[Mod_API_Reference:PlayerID|WL.PlayerID.AvailableForDistribution]]
| 5.20
|-
| Visually updating [[gold]] correctly when using [[Mod_API_Reference:ServerGame|ServerGame.SetPlayerResource]] in [[Mod_Hooks#Server_Hooks|Server_StartGame]]
| 5.26
|}
|}


[[Category:Mod Developers Guide]][[Category:Mod API Reference]]
[[Category:Mod Developers Guide]][[Category:Mod API Reference]]

Revision as of 22:45, 18 June 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

Newer API features

Some features were introduced after the first version of the Mod API framework and should be checked for using IsVersionOrHigher:

Symbol New in version
IncomeMod 5.17
GameOrderEvent.IncomeMods 5.17
UI.InterceptNextTerritoryClick 5.17
UI.InterceptNextBonusLinkClick 5.17
WL.StructureType.Arena 5.17
WL.StructureType.ArmyCache 5.17
WL.StructureType.ArmyCamp 5.17
WL.StructureType.Attack 5.17
WL.StructureType.Crafter 5.17
WL.StructureType.DigSite 5.17
WL.StructureType.Draft 5.17
WL.StructureType.Hospital 5.17
WL.StructureType.Market 5.17
WL.StructureType.MercenaryCamp 5.17
WL.StructureType.Mine 5.17
WL.StructureType.MoneyCache 5.17
WL.StructureType.Mortar 5.17
WL.StructureType.Power 5.17
WL.StructureType.Recipe 5.17
WL.StructureType.ResourceCache 5.17
WL.StructureType.Smelter 5.17
GameOrderEvent.AddResourceOpt 5.20
GameOrderEvent.AddCardPiecesOpt 5.20
GameOrderEvent.RemoveWholeCardsOpt 5.20
TerritoryModification.AddArmies 5.20
TerritoryModification.AddStructuresOpt 5.20
Client_PresentCommercePurchaseUI 5.21
ClientGame.HighlightTerritories 5.21
ClientGame.CreateLocatorCircle 5.21
UI.IsDestroyed 5.21
WL.CancelClickIntercept 5.21
CustomSpecialUnit 5.21
GameOrderEventResult.CardInstancesCreated 5.21
GameOrderEvent.JumpToActionSpotOpt 5.21
GameOrderCustom.OccursInPhaseOpt 5.22
TerritoryModification.RemoveSpecialUnitsOpt 5.22
Boss1.CombatOrder 5.22.2
Boss2.CombatOrder 5.22.2
Boss3.CombatOrder 5.22.2
Boss4.CombatOrder 5.22.2
Commander.CombatOrder 5.22.2
CustomSpecialUnitBuilder.Health 5.22.2
WL.TickCount 5.24.1
CustomSpecialUnit.CombatOrder 5.24.1
CustomSpecialUnit.Health 5.24.2

Some new abilities were also added.

Ability New in version
Using argument two of addNewOrder in Server_AdvanceTurn_Order 5.17
Setting TerritoryStanding.OwnerPlayerID to WL.PlayerID.AvailableForDistribution 5.20
Visually updating gold correctly when using ServerGame.SetPlayerResource in Server_StartGame 5.26