Professional Documents
Culture Documents
Age of Wonders 3 Scripting Guide
Age of Wonders 3 Scripting Guide
Phoenixstraat 66
2611 AM Delft
The Netherlands
Phone: + 31 15 2159902
Fax: + 31 15 2159952
3.4.3
PlayerIsLeaderInVoid................................................................................................................25
3.4.4
PlayerEnableResearch...............................................................................................................25
3.4.5
PlayerGetNumSustainedSpells..................................................................................................25
3.4.6
PlayerGetSustainedSpell...........................................................................................................26
3.4.7
PlayerHasMetPlayer..................................................................................................................26
3.4.8
PlayerMeetsPlayer.....................................................................................................................27
3.4.9
PlayerGetDiplomaticState.........................................................................................................27
3.4.10 PlayerSetDiplomaticState..........................................................................................................27
3.4.11 PlayerOpenCloseBorders..........................................................................................................29
3.4.12 PlayerSendMessage...................................................................................................................29
3.4.13 PlayerSendMessageWithSender................................................................................................29
3.4.14 PlayerKillLeader.......................................................................................................................30
3.4.15 PlayerSetVictorious...................................................................................................................30
3.4.16 PlayerSetDefeated.....................................................................................................................31
3.4.17 PlayerAddItem..........................................................................................................................31
3.4.18 PlayerCastSpell.........................................................................................................................32
3.4.19 PlayerIsTrespassingInDomain...................................................................................................32
3.4.20 PlayerGetNumCities..................................................................................................................33
3.4.21 PlayerGetCity............................................................................................................................33
3.4.22 PlayerGetThroneCity................................................................................................................34
3.5
Race...............................................................................................................................................34
3.5.1
RaceIsEliminated......................................................................................................................34
3.6
Unit Groups...................................................................................................................................35
3.6.1
SetGroupHome..........................................................................................................................35
3.6.2
SetGroupBehavior.....................................................................................................................35
3.6.3
GetGroupBehavior....................................................................................................................35
3.6.4
DestroyGroup............................................................................................................................35
3.7
Quest.............................................................................................................................................36
3.7.1
PlayerOfferQuest.......................................................................................................................36
3.7.2
PlayerOfferCityQuest................................................................................................................36
3.7.3
PlayerForceQuest......................................................................................................................37
3.7.4
PlayerOfferSubQuest.................................................................................................................37
3.7.5
PlayerForceSubQuest................................................................................................................38
3.7.6
PlayerCompleteQuest................................................................................................................38
3.7.7
PlayerFailQuest.........................................................................................................................39
3.7.8
PlayerIncreaseQuestCompletionCount.....................................................................................39
3.7.9
PlayerDecreaseQuestCompletionCount....................................................................................39
3.8
AI..................................................................................................................................................40
3.8.1
ToggleAI....................................................................................................................................40
3.8.2
DiplomacyAISetPassive............................................................................................................40
3.8.3
DiplomacyAIEnabled................................................................................................................41
3.8.4
DiplomacyAIDisabled...............................................................................................................41
3.8.5
AISpellcastingLimit..................................................................................................................41
Script Guide - Triumph Studios B.V.
3.8.6
AISetTargetBounty....................................................................................................................42
3.8.7
AISetPlayerTargetBounty.........................................................................................................42
3.8.8
ToggleResources.......................................................................................................................42
3.8.9
SetOffensiveAIEnabled.............................................................................................................43
3.8.10 AISetRazeEnabled....................................................................................................................43
3.9
Camera..........................................................................................................................................44
3.9.1
CenterCameraOnEntity.............................................................................................................44
3.10 Spawn Group................................................................................................................................44
3.10.1 SpawnGroupSpawnAtPosition..................................................................................................45
3.11 Stack..............................................................................................................................................45
3.11.1 StackGetPosition.......................................................................................................................45
3.11.2 StackGetNumUnits....................................................................................................................46
3.11.3 StackGetUnit.............................................................................................................................46
3.11.4 StackJoinPlayer.........................................................................................................................47
3.11.5 StackGetPlayer..........................................................................................................................47
3.11.6 StackSetDirection......................................................................................................................47
3.12 StrategicWorld..............................................................................................................................48
3.12.1 StrategicWorldChangeOverlay..................................................................................................48
3.12.2 StrategicWorldChangeTheme...................................................................................................49
3.12.3 StrategicWorldGetNumPlayers.................................................................................................49
3.12.4 StrategicWorldGetPlayerAlias..................................................................................................50
3.13 Structure........................................................................................................................................50
3.13.1 StructureGetState......................................................................................................................50
3.13.2 StructureSetState.......................................................................................................................51
3.13.3 StructureGetOwner....................................................................................................................51
3.13.4 StructureSetOwner....................................................................................................................52
3.14 Timer.............................................................................................................................................52
3.14.1 TimerStart..................................................................................................................................52
3.14.2 TimerStop..................................................................................................................................53
3.14.3 TimerReset................................................................................................................................53
3.15 Unit...............................................................................................................................................53
3.15.1 UnitHasRequisite......................................................................................................................53
3.15.2 UnitKill......................................................................................................................................54
3.15.3 UnitGetInventoryItem...............................................................................................................54
3.15.4 UnitGetStackAlias.....................................................................................................................55
3.15.5 UnitSetGroup............................................................................................................................55
3.15.6 UnitDropItem............................................................................................................................56
3.15.7 UnitCannotDieInTC..................................................................................................................56
4. Script Reference: Campaign & Data Access...................................................................................57
4.1
Campaign......................................................................................................................................57
4.1.1
CampaignUnlockScenario.........................................................................................................57
4.1.2
CampaignSaveUnit....................................................................................................................57
4.1.3
CampaignSpawnSavedUnit.......................................................................................................57
Script Guide - Triumph Studios B.V.
4.1.4
CampaignSpawnAsLeader........................................................................................................58
4.2
Data Access...................................................................................................................................58
4.2.1
GetMapBool..............................................................................................................................59
4.2.2
SetMapBool...............................................................................................................................60
4.2.3
GetMapNumber.........................................................................................................................60
4.2.4
SetMapNumber.........................................................................................................................60
4.2.5
GetMapString............................................................................................................................60
4.2.6
SetMapString.............................................................................................................................61
4.2.7
GetCampaignBool.....................................................................................................................61
4.2.8
SetCampaignBool......................................................................................................................61
4.2.9
GetCampaignNumber................................................................................................................61
4.2.10 SetCampaignNumber................................................................................................................62
4.2.11 GetCampaignString...................................................................................................................62
4.2.12 SetCampaignString....................................................................................................................62
Scripting Examples:
Here follow a few examples to get you started:
I place the treasure chest pickup on the ground and edit the surroundings to
signify the importance of the chest.
Under Objects I select the Marker tab and place a Stack Area Trigger.
I leave it to its default settings (Active True, Trigger Type Trigger Once, Marker Cancel Movement
True).
When sending story messages Cancel Movement should always be true, otherwise a unit may trigger
other events that can break the scripting (maybe it dies from a Hook Briar hazard so it doesnt exist
anymore to reply, etc).
With the Stack Area Trigger selected I click the Script button to open the
Script Pool.
I drag the gear icon next to OnStackEnters on the script and release it: the
Script Editor will open with a function in it. Everything I write in that function
block will fire as soon as a stack enters the hex I placed the stack area
trigger on.
10
It works, but it would be kind of boring if that was the end of it!
Lets say the treasure has been placed there for a powerful band of thieves by a nearby city, as a bribe
so they wont disturb them for another month. A few assassins, coming to collect the treasure are
spawned nearby and attack.
11
I select the tab on the right that says Spawner, and from the empty-looking
drop-down list I select the unit spawn group (the only possible selection).
Then I click the New Group button.
A new group will be made. I change its alias to ASSASSINSPAWN and the
Owning player to Independent(Hate All). At the bottom I set the groups
alias to ASSASSINS and the behavior to Raid (that will make sure they attack
everyone they meet).
Then, with the group selected, I click Edit and under Rogue units I add 3 Orc
Assassins.
I put down another stack area trigger, but this time I set Marker Is Active to
false, as I only need it as a location for the assassins to spawn at. Since Ill
be using it for that I give it the alias ASSASSINSPAWNLOC.
12
Now for the script, I am going to use the button of the story message I created earlier.
I can just click the On Button 1 Script field and then click the
button and a
script editor will open. This script will be executed as soon as the user clicks
the button on the story message.
The SpawnGroupSpawnAtPosition script needs a location in hexPosition format, but I have no idea
what that could be, so I need to get the position of the stack area trigger in hexPosition format using the
GetPosition script which returns the position of the entity whos alias I filled in.
Since LUA doesnt mind, I can actually substitute the hexPosition parameter by the script that finds it
for me, so I dont need a separate variable to store it in first.
The script I come up with is this:
-- Spawning group ASSASSINSPAWN at the location of the marker with alias
ASSASSINSPAWNLOC, facing southwest.
HexWorld:GetScriptingS():SpawnGroupSpawnAtPosition("ASSASSINSPAWN",
HexWorld:GetScriptingS():GetPosition("ASSASSINSPAWNLOC"), "SW")
13
It works, the Assassins spawn and next turn they will attack me.
Later I can add the city that paid the gold, and when I meet them and tell them about the gold and the
assassins they can give me a quest to kill the leader of the thieves, with the city as reward.
Last tip: save often! As soon as you get a popup with an assertion or any error/access violation however
do not save! You might corrupt the entire map file and lose all your work!
14
1. Scripting Overview
This is a short overview of how scripting works in AoW3.
Please note that scripting may very well break the game! The documentation provided is
incomplete, in the sense that it doesnt warn you about all the ways scripting may go wrong. It
doesnt always define when or how its safe to use the scripts. We also dont guarantee its up to
date and 100% correct.
Scripting in AoW3 consists of LUA scripts that can be attached to all hex entities on the strategic map.
This can be done in the AoW3 LevelEd. Scripting can respond to events or call methods on those hex
entities. This wiki lists these events and methods, and provides descriptions and examples on how to
use them.
The object to call the methods on is always:
HexWorld:GetScriptingS()
For example:
HexWorld:GetScriptingS():StackGetNumUnits("STACKALIAS")
Click the 'New Script' button icon in the top left corner
The script appears under the 'Declared Scripts' folder in the left treeview
Drag a script from the 'Declared Scripts' folder in the left treeview to the 'Attached Scripts'
folder in the right treeview.
15
Notice how the script is opened for editing and a new function has been created. This is the function
that gets executed when the event is fired.
1.2
Diplomatic States
A diplomatic state describes relation standing between two players. The diplomatic states are:
Unknown = 0
The state between two players that have not yet meet each other.
Neutral = 1
The initial state when two players meet for the first time.
War = 2
Peace = 3
Alliance = 4
Alliance = 4
16
1.3
Structure States
Some structures have different functionality depending on the state they are in. This page lists all
structure state. Note that not all structures have a state, and that some states are for a specific type of
structure.
None = 0
Structure_Owned = 1
City Only
City_Owned = 2
City_Occupied = 3
Rebellion State has been Removed, count skips state 4 to prevent previously existing scripts
from not working anymore.
Treasure Site Only
Treasure_Explored = 6
Visit_Charged = 7
receive the benefit.
Visit_Depleted = 8
Teleporter Only:
Teleporter_Active = 9
17
1.4
Alias
An alias is a name given to an entity. You can set your own aliases in levelED. This makes it possible to
refer to an entity in scripting without having to obtain the alias first. For example if you want a specific
unit to speak at some point, you can name that unit ELFGUARDSPEAKER, and use that alias as the
message sender in the story message.
An alias must be unique.
Stacks also have aliases, but beware: stack aliases can change dynamically because stacks can merge,
split, lose a unit etc. So usually you wont use a stack alias unless you have just found out the stack
alias in the same script, or are very sure the stack cannot have changed in the time between.
Localized string: "In this localized string the name of the city {MY_CITY} will be dynamically
added"
Structures
Cities
Units
Quests (Make sure they don't share the same alias as hex entities)
GetAlias
<return value>:
Script Guide - Triumph Studios B.V.
18
Example:
Print the alias of all the units in a stack
for i = 0, HexWorld:GetScriptingS():StackGetNumUnits("stackAlias") - 1, 1 do
local unit = HexWorld:GetScriptingS():StackGetUnit("stackAlias", i)
Print(HexWorld:GetScriptingS():GetAlias(unit))
end
2.2
SetAlias
2.3
GetPosition
19
<param hexEntityAlias>:
The alias of the hex entity to get the position for.
Example:
Change the terrain around a marker to artic. (#0000000105800063 is the resourceID of artic in
this case)
local markerPostion = HexWorld:GetScriptingS():GetPosition("MARKERALIAS")
HexWorld:GetScriptingS():StrategicWorldChangeTheme(markerPostion, 1, "#0000000105800063")
City
A city is a special type of structure. In addition to the methods and functions listed here it also has
access to all the methods and events of the structure class.
Events______________________________________________________
OnRaceChanged
Called when the race of the city has changed.
OnStartRebellion
Called when the city begins rebelling.
OnStopRebellion
Called when the city stops rebelling.
OnCityOperationCompleted
Called when a city operation has been completed.
Please note that OnEnable, OnDisable, OnActivate, OnPostActivate and OnDeactivate are handles that
get fired by code at unpredictable times or only during map creation/destruction. Do not attach
scripting to these.
3.1.1 CityGetRace
string CityGetRace(cityAlias : string)
Get the race name of the city.
<return value>:
The race name of the city. Returns NULL on failure.
<param cityAlias>:
The alias of the city to get the race name for.
20
3.1.2 DestroyCityGuards
void DestroyCityGuards(cityAlias : string)
Destroys all city guards that are defending a city.
Note: Only works for independents.
<param cityAlias>:
The alias of the city.
3.1.3 CitySetDiplomaticState
void CitySetDiplomaticState(cityAlias : string, playerToChangeBordersFor : string, diplomaticState :
int)
Sets the diplomatic state of the independent city.
Player will meet the city if they have not met it yet.
For any state except state 4, there should be an if statement checking that the city isnt already in the
state that it is set to, otherwise the system may assert and throw a warning (example:
if HexWorld:GetScriptingS():CityGetDiplomaticState("SUNDREN", "ELDASTE") ~= 3 then
HexWorld:GetScriptingS():CitySetDiplomaticState("ELDASTE", "SUNDREN", 3)
End)
<param1 - cityAlias >:
The alias of the city who's state will be set.
<param2 - playerToOpenCloseBordersFor>:
The alias of the player for who the relation with the city will be set.
<param3 - diplomaticState>:
The diplomatic state the relation will be set to. See diplomatic states how they are mapped to ints.
Peace will also open borders.
War will also close borders.
Alliance will absorb the city.
3.1.4 AICityBuilding
string AICityBuilding(cityAlias : string, canBuild : boolean)
Sets if the AI may build upgrades and units in the target city
<param cityAlias>:
Script Guide - Triumph Studios B.V.
21
3.1.5 CityGetDiplomaticState
int CityGetDiplomaticState(playerAlias : string, cityAlias : string)
Get the diplomatic state between a player and a city
<return value>:
The diplomatic state between the player and the city. Returns -1 on failure. See diplomatic states
how they are mapped to ints.
<param playerAlias >:
The alias of the player in the relation.
<param cityAlias >:
The alias of the city in the relation.
Example:
local diplomaticState = HexWorld:GetScriptingS():CityGetDiplomaticState("PLAYER1", "CITY1")
3.2
Item
Item
Class
An class that represents a item that can be equiped by hero units
Events______________________________________________________
OnPickUp
Triggers when item is pickup by a unit.
OnDrop
Triggers when item is moved from the unit's inventory to
an item sack
3.2.1 ItemHasTag
bool ItemHasTag(item : Item, tags : string)
Script Guide - Triumph Studios B.V.
22
Returns whether the items has the tags that are specified.
<return value>:
Returns true if the item has the tags.
<param item>:
The item to check for tags.
<param pTags>:
A comma separated list of tags.
3.3
Marker
3.3.1 MarkerEnable
int MarkerEnable(markerAlias : string)
Enable the marker.
<param markerAlias>:
The alias of the marker to enable
3.3.2 MarkerDisable
int MarkerDisable(markerAlias : string)
Script Guide - Triumph Studios B.V.
23
3.4
Player
3.4.1 PlayerGetAlias
string PlayerGetAlias(player : Player)
Get the alias of the specified player
<return value>:
The alias of the player.
<param player>:
The player to get the alias for.
3.4.2 PlayerGetLeaderAlias
string PlayerGetLeaderAlias(playerAlias : Player)
Get the alias of the leader unit from the specified player.
Note that by exception the alias of a Leaderunit is the same as the alias of the Lord player entity, to
make things more intuitive (for example if the Alias of Player 1s Lord is PLAYER1, then the Alias of
the unit ingame representing Player 1s leader also has the alias PLAYER1, even though they are
separate entities in reality).
Script Guide - Triumph Studios B.V.
24
<return playerAlias>:
The alias of the leader unit.
<param player>:
The alias of the player to get the leader for.
3.4.3 PlayerIsLeaderInVoid
bool PlayerIsLeaderInVoid(playerAlias : string)
Returns whether the leader of the specified player is in the void
<return value>:
True if the player is in the void, false otherwise
<param playerAlias >:
The alias of the player for whom we want to know if the leader is in the void
3.4.4 PlayerEnableResearch
void PlayerEnableResearch(playerAlias : string, skillResourceID : string, enable : bool)
Enables or disables a spell from being available for research.
<param playerAlias>:
The alias of the player whose skill will be enabled/disabled for research.
<param skillResourceID>:
The resource id of the skill that will be enabled/disabled. Changes in resources can alter this id, so it
should be considered unsafe to use. For now the only way to obtain a resource id is to ask for it on the
games forums. The devs are the only ones who can look them up.
<param enable>:
Whether the specified skill should be enabled or disabled for research.
3.4.5 PlayerGetNumSustainedSpells
int PlayerGetNumSustainedSpells(playerAlias : string)
Script Guide - Triumph Studios B.V.
25
3.4.6 PlayerGetSustainedSpell
SustainedSpell PlayerGetSustainedSpell(playerAlias : string, index : int)
Get the sustained spell for the player at the specified index.
<return value>:
The sustained spell at the specified index. Returns NULL on failure.
<param playerAlias>:
The alias of the player to get the sustained spells from.
<param index>:
The index of the spell.
3.4.7 PlayerHasMetPlayer
bool PlayerHasMetPlayer(player1Alias : string, player2Alias : string)
Returns whether the two players have met. Useful to detect if its the first time the players meet
(OnMeet is triggered every time a player meets a player/indie city, so if it triggers and
PlayerHasMetPlayer returns true it was the first time they met).
<returns value>
Whether the two players have met.
<param player1Alias>:
The alias of a player.
<param player2Alias>:
The alias of a player.
Script Guide - Triumph Studios B.V.
26
3.4.8 PlayerMeetsPlayer
void PlayerMeetsPlayer(player1Alias : string, player2Alias : string)
Let the two players meet each other. This will allow trading, setting of diplomatic states, applying
modifiers etc.
<param player1Alias>:
The alias of a player.
<param player2Alias>:
The alias of a player.
3.4.9 PlayerGetDiplomaticState
int PlayerGetDiplomaticState(player1Alias : string, player2Alias : string)
Get the diplomatic state between two players.
<return value>:
The diplomatic state between the two players as an int. Returns -1 on failure. See diplomatic states
how they are mapped to ints.
<param player1Alias>:
The alias of one of the players in the relation.
<param player2Alias>:
The alias of one of the players in the relation.
Example:
local diplomaticState = HexWorld:GetScriptingS():PlayerGetDiplomaticState("PLAYER1",
"PLAYER2")
3.4.10
PlayerSetDiplomaticState
27
Set the diplomatic state between two players. There should be an if-statement checking that the players
arent already in the state that they are set to, otherwise the system may assert and throw a warning.
Also note that players, even in a script, should pass through the peace state before they are set to war
from alliance. So first set two allied players to peace, immediate bool true, and then to war, if you want
to script the breaking of an alliance into war.
<return value>:
The diplomatic state between the two players as an int. Returns -1 on failure. See diplomatic states
how they are mapped to ints.
<param1 - player1Alias>:
The alias of one of the players in the relation.
<param2 - player2Alias>:
The alias of one of the players in the relation.
<param3 - diplomaticState>:
The diplomatic state the relation will be set to. See diplomatic states how they are mapped to ints.
<param4 - immediate>:
Whether the new diplomatic state is applied immediately to the relation. If this is set to false the
normal rules for changing diplomatic states of a relation apply (Changes from Alliance to Peace and
Peace to War take a turn before they are applied). True means the changes in diplomatic state are
applied without the 'wait' turn.
Example:
Change the diplomatic state from the relation between "PLAYER1" and "PLAYER2" to alliance.
if HexWorld:GetScriptingS():PlayerGetDiplomaticState("PLAYER1",
"PLAYER2") == 2 then
-- Player1 and Player2 are at war with each other, set the
-- diplomatic state to peace before we can set it to alliance
HexWorld:GetScriptingS():PlayerSetDiplomaticState("PLAYER1",
"PLAYER2", 3, true)
end
-- Set the diplomatic state to alliance
HexWorld:GetScriptingS():PlayerSetDiplomaticState("PLAYER1",
"PLAYER2", 4, true)
28
3.4.11
PlayerOpenCloseBorders
3.4.12
PlayerSendMessage
3.4.13
PlayerSendMessageWithSender
29
Note: When sending a message from an area trigger make sure the area trigger is set to 'Cancel
Movement'
<param messageAlias>:
The alias of the message that will be sent.
<param playerAlias>:
The alias of the player the message will be send to.
<param senderAlias>:
The alias of the unit which will be displayed as the sender of the message.
3.4.14
PlayerKillLeader
3.4.15
PlayerSetVictorious
30
Note! Support to be able to set a string of text to display on win will (probably) come in patch 03!
Note: If you want to enforce that no victory can be gained through any other means than scripting set
victory condition to "Scripted".
<param playerAlias>:
The alias of the player that has won.
<param victoryText>:
The text that will be shown on the victory screen as the reason for victory. (Wait till patch 03 to use
this, check patchnotes to see if it made it in the patch.)
3.4.16
PlayerSetDefeated
3.4.17
PlayerAddItem
31
The alias of the player of whom the leader unit will receive the item
<param itemResourceId>:
The resourceID of the item which will be given to the unit. Changes in resources can alter this id, so
it should be considered unsafe to use. For now the only way to obtain a resource id is to ask for it on
the games forums. The devs are the only ones who can look them up.
3.4.18
PlayerCastSpell
3.4.19
PlayerIsTrespassingInDomain
32
Checks if any units of the player (trespassingPlayerAlias) are trespassing are trespassing in the domain
of the other player (domainOwningPlayerAlias)
<param trepassingPlayerAlias>:
The alias of the player who is trespassing
<param domainOwningPlayerAlias>:
The alias of the player of which its domain is being trespassed
Example:
local isTrespassing =
HexWorld:GetScriptingS():PlayerIsTrespassingInDomain("PLAYER_1","PLAYER_2")
3.4.20
PlayerGetNumCities
3.4.21
PlayerGetCity
33
Example:
local cityIndex = 1
local cityAlias = HexWorld:GetScriptingS():PlayerGetCity("PLAYER1",cityIndex)
3.4.22
PlayerGetThroneCity
3.5
Race
3.5.1RaceIsEliminated
bool RaceIsEliminated(raceName : string)
Check if a race is present on the map
If there are no Cities or Settlers of a specific race, then this function returns true
Note: There is no difference between a race which never existed on the map and a race which was
eliminated.
<param raceName>:
The RaceName of the Race, ex. "DRACONIAN".
Available Races:
HIGHELF
HUMAN
ORC
GOBLIN
DWARF
DRACONIAN
Script Guide - Triumph Studios B.V.
34
Example:
Check if all Draconians have been eliminated from the map
local raceHasBeenEliminated = HexWorld:GetScriptingS():RaceIsEliminated("DRACONIAN")
3.6
Unit Groups
3.6.1 SetGroupHome
void SetGroupHome(GroupAlias : string, HomeAlias: string)
Sets the home location of a group using the alias of a map entity. Some group behaviors have a home
location they will move to.
3.6.2 SetGroupBehavior
void SetGroupBehavior(GroupAlias : string, BehaviorName: string)
Sets the behavior of a group.
<param BehaviorName>:
"GUARD" : guard behavior - guards a single location or a specified area.
"PATROL": patrol behavior - patrols around the home location with a specified range. Attacks all
enemy units it encounters.
"RAID": raid behavior - attacks everything it can find...
3.6.3 GetGroupBehavior
object GetGroupBehavior(GroupAlias : string)
Returns the behavior that is active on a group. Use this function to modifiy behavior parameters..
3.6.4 DestroyGroup
void DestroyGroup(GroupAlias : string)
Destroys a player group, all units will be controlled by the central player AI. (not supported for
independents)
35
3.7
Quest
A Quest is a task you can give to the player, completing a quest gives the player a reward.
3.7.1 PlayerOfferQuest
void PlayerOfferQuest(playerAlias : string, questAlias : string, popupQuest: bool)
Offers a quest to the player which he can accept or decline.
<param playerAlias>:
The alias of the player to offer the quest.
<param questAlias>:
The alias of the quest to offer.
<param popupQuest>:
Determines if it is a popup quest (= true) or a to-do quest (=false).
Example:
HexWorld:GetScriptingS():PlayerOfferQuest("PLAYER1", "QUEST1", false)
3.7.2 PlayerOfferCityQuest
void PlayerOfferCityQuest(playerAlias : string, cityAlias : string, questAlias : string)
Offers a quest from a city to the player which he can accept or decline. Completing this quest will
absorb the city into the player's domain.
<param playerAlias>:
The alias of the player to offer the quest to.
<param cityAlias>:
The alias of the city offering the city quest.
<param questAlias>:
The alias of the quest to offer.
Example:
Script Guide - Triumph Studios B.V.
36
3.7.3 PlayerForceQuest
void PlayerForceQuest(playerAlias : string, questAlias : string)
Force a quest to the player which is automatically accepted (cannot be declined).
<param playerAlias>:
The alias of the player to force the quest.
<param questAlias>:
The alias of the quest to force.
Example:
HexWorld:GetScriptingS():PlayerForceQuest("PLAYER1", "QUEST1")
3.7.4 PlayerOfferSubQuest
void PlayerOfferSubQuest(playerAlias : string, questHeaderAlias : string, questAlias : string,
popupQuest: bool)
Offers a subquest to the player which he can accept or decline, this quest will get added to the
specified quest header.
<param playerAlias>:
The alias of the player to offer the quest.
<param questHeaderAlias >:
The alias of the questheader to which the subquest will be attached (required to add subquest)
<param questAlias>:
The alias of the quest to offer.
<param popupQuest>:
Determines if it is a popup quest (= true) or a to-do quest (=false).
Example:
Script Guide - Triumph Studios B.V.
37
3.7.5 PlayerForceSubQuest
void PlayerForceSubQuest(playerAlias : string, questHeaderAlias : string, questAlias : string)
Force a subquest to the player which is automatically accepted (cannot be declined), this quest will be
added to the specified quest header.
<param playerAlias>:
The alias of the player to force the quest.
<param questHeaderAlias>:
The alias of the questheader the subquest will be attached to.
<param questAlias>:
The alias of the quest to force.
Example:
HexWorld:GetScriptingS():PlayerForceSubQuest("PLAYER1", "QUEST_HEADER1", "QUEST1")
3.7.6 PlayerCompleteQuest
void PlayerCompleteQuest(playerAlias : string, questAlias : string)
Completes a quest of the player.
<param playerAlias>:
The alias of the player to complete the quest.
<param questAlias>:
The alias of the quest to complete.
Example:
HexWorld:GetScriptingS():PlayerCompleteQuest("PLAYER1", "QUEST1")
38
3.7.7 PlayerFailQuest
void PlayerFailQuest(playerAlias : string, questAlias : string)
Fails a quest of the player.
<param playerAlias>:
The alias of the player to fail the quest.
<param questAlias>:
The alias of the quest to fail.
Example:
HexWorld:GetScriptingS():PlayerFailQuest("PLAYER1", "QUEST1")
3.7.8 PlayerIncreaseQuestCompletionCount
void PlayerIncreaseQuestCompletionCount(playerAlias : string, questAlias : string)
Increases the completion count of a player's quest by 1.
<param playerAlias>:
The alias of the player to increase the quest completion type of.
<param questAlias>:
The alias of the quest to increase the quest completion type of.
Example:
HexWorld:GetScriptingS():PlayerIncreaseQuestCompletionCount("PLAYER1", "QUEST1")
3.7.9 PlayerDecreaseQuestCompletionCount
void PlayerDecreaseQuestCompletionCount(playerAlias : string, questAlias : string)
Decreases the completion count of a player's quest by 1.
<param playerAlias>:
The alias of the player to decrease the quest completion type of.
Script Guide - Triumph Studios B.V.
39
<param questAlias>:
The alias of the quest to decrease the quest completion type of.
Example:
HexWorld:GetScriptingS():PlayerDecreaseQuestCompletionCount("PLAYER1", "QUEST1")
3.8
AI
3.8.1 ToggleAI
void ToggleAI(playerAlias : string, enableAI: bool)
Toggles the AI on or off for a specific player.
<param playerAlias>:
The alias of the player to toggle the AI for (the AI player)
<param enableAI>:
Determines if the AI needs to be enabled (=true) or disabled (=false) for a player
Example:
HexWorld:GetScriptingS():ToggleAI("PLAYER1", true)
HexWorld:GetScriptingS():ToggleAI("PLAYER1", false)
3.8.2 DiplomacyAISetPassive
void DiplomacyAISetPassive(playerAlias : string, passive : bool)
Set the diplomacy AI to passive. When passive the AI will not initiated trades but only respond to trades
offered to it
<param playerAlias>:
The alias of the player whose diplomacy AI will be changed
<param passive>:
Script Guide - Triumph Studios B.V.
40
3.8.3 DiplomacyAIEnabled
void DiplomacyAIEnabled( playerAlias : string )
enables the diplomatic AI for an AI player. this way the AI will react on offers and send them to other
players.
NOTE: AIpassive can still be disables and cause the AI to only react on offers
<return value>:
none
<param1 : string>:
The alias of the player to enable the AI of
3.8.4 DiplomacyAIDisabled
void DiplomacyAIDisabled( playerAlias : string )
Disables the diplomatic AI for an AI player. this way the AI will NOT react on offers and NOt send
them to other players.
<return value>:
none
<param1 : string>:
The alias of the player to disable the AI of
3.8.5 AISpellcastingLimit
void AISpellcastingLimit(playerAlias : string, limit : int)
Sets a limit to amount of mana the AI can spend per turn sustaining sustained spells like summons.
<param playerAlias>:
The alias of the player whos AI will be changed
<param limit>:
Script Guide - Triumph Studios B.V.
41
3.8.6 AISetTargetBounty
void AISetTargetBounty(pEntityAlias : string, pBounty : int)
Sets a bounty (in gold) on a target - this influences the target priority of all AI players.
<param pEntityAlias>:
The entity alias of a structure / unit / pickup.
<param pBounty>:
Value in gold (0=none=default)
Note: AI only sees targets in a radius of ~5 turns from all its sources (units / structures)
3.8.7 AISetPlayerTargetBounty
void AISetPlayerTargetBounty(pPlayerAlias: string, pEntityAlias : string, pBounty : int)
Sets a bounty (in gold) on a target player - this influences the target priority of the AI Player with
pPlayerAlias.
<param pPlayerAlias>:
The entity alias of a player.
<param pEntityAlias>:
The entity alias of a structure / unit / pickup.
<param pBounty>:
Value in gold (0=none=default)
3.8.8 ToggleResources
void ToggleResources(playerAlias : string, enableGoldIncome: bool, enableManaIncome: bool,
enableResearch: bool, enableGrowth: bool)
Script Guide - Triumph Studios B.V.
42
3.8.9 SetOffensiveAIEnabled
SetOffensiveAIEnabled("PlayerAlias", bool)
False will disable the offensive AI: AI troops will only defend and return to their cities.
True will enable the offensive AI (basically return it to normal after it has been toggled off).
3.8.10
AISetRazeEnabled
AISetRazeEnabled(playeralias, bool)
Toggles whether the AI is allowed to raze/plunder its own cities.
true means razing/plundering is allowed per normal AI routine
false means razing/plundering is not allowed
Script Guide - Triumph Studios B.V.
43
3.9
Camera
3.9.1 CenterCameraOnEntity
void CenterCameraOnEntity(playerAlias : string, entityAlias : string, exploreArea: bool, radius: int,
timeout: int)
Centers the Camera of the specified Player on the specified Entity
Important note: Only use this function based on user input in order for it to work correctly in
hotseat mode (for example in the OnButton embedded script of a story message).
<param playerAlias>:
The alias of the player to center the camera for.
<param entityAlias >:
The alias of the entity to center the camera on
<param exploreArea>:
If true the surrounding area of the entity will be revealed.
<param radius>:
The amount of hexes surrounding the entity to be revealed.
<param timeout>:
The time in ms the camera remains centered on the center entity before it goes back to its old
camera position
Example:
HexWorld:GetScriptingS():CenterCameraOnEntity("PLAYER1", "DRAGON", true, 2, 2000)
3.10
Spawn Group
44
3.10.1
SpawnGroupSpawnAtPosition
3.11
Stack
A stack entity represents a collection of units on one hex on the strategic map.
3.11.1
StackGetPosition
45
3.11.2
StackGetNumUnits
3.11.3
StackGetUnit
46
Print(HexWorld:GetScriptingS():GetAlias(unit))
end
3.11.4
StackJoinPlayer
3.11.5
StackGetPlayer
3.11.6
StackSetDirection
47
<param pDirection>:
The Direction of the group to face towards
NE, E, SE, SW, W, NW
3.12
StrategicWorld
3.12.1
StrategicWorldChangeOverlay
48
3.12.2
StrategicWorldChangeTheme
3.12.3
StrategicWorldGetNumPlayers
int StrategicWorldGetNumPlayers()
Get the number of players in the world.
<return value>:
The number of players in the world.
49
3.12.4
StrategicWorldGetPlayerAlias
3.13
Structure
3.13.1
StructureGetState
50
if HexWorld:GetScriptingS():StructureGetState("STRUCTUREALIAS") == 10 then
HexWorld:GetScriptingS():StructureSetState("STRUCTUREALIAS", 9)
end
3.13.2
StructureSetState
Example:
Set the teleporter to active if its inactive
if HexWorld:GetScriptingS():StructureGetState("STRUCTUREALIAS") == 10 then
HexWorld:GetScriptingS():StructureSetState("STRUCTUREALIAS", 9)
end
3.13.3
StructureGetOwner
51
3.13.4
StructureSetOwner
3.14
Timer
A timer class which can be used to delay the execution of a script for a specified amount of rounds.
These timers can be created in LevelEd. On the right side on the 'Scripts' tab -> 'Timers' tab. The
number of rounds correspond to the rounds in game (i.e. round = 1 fires at the start of the game)
Events______________________________________________________
OnElapsed
Called when the timer has reached its specified number of rounds.
3.14.1
TimerStart
52
3.14.2
TimerStop
3.14.3
TimerReset
3.15
Unit
3.15.1
UnitHasRequisite
53
3.15.2
UnitKill
3.15.3
UnitGetInventoryItem
54
Example:
Print the the id of the item in the unit's head slot
local item = HexWorld:GetScriptingS():UnitGetInventoryItem("UNITALIAS", 3)
HexWorld:GetScriptingS():ItemHasTag(item, "OVERPOWERED"))
3.15.4
UnitGetStackAlias
3.15.5
UnitSetGroup
55
Adds the unit to an existing group. Note that groups should at most be 3 stacks and they should be
close together. Group behavior will break if members of 1 group are many and/or far apart.
<param stackAlias>:
The alias of the stack to get the strategic group from
<param unitAlias>:
The alias of the unit to add to the group
Example:
HexWorld:GetScriptingS():UnitSetGroup("STACKALIAS", "UNITALIAS")
3.15.6
UnitDropItem
3.15.7
UnitCannotDieInTC
56
HexWorld:GetScriptingS():UnitCannotDieInTC("UNITALIAS")
Campaign
4.1.1 CampaignUnlockScenario
CampaignUnlockScenario(scenarioName : string)
Unlock the named scenario is the current campaign.
<param scenarioName>:
The name of the scenario to unlock. This is the name listed in the campaign editor, typically the
filename of the map without a file extension.
4.1.2 CampaignSaveUnit
void CampaignSaveUnit(unitAlias : string, saveAlias : string)
Save the specified unit in the campaign data so it can be used in other campaign scenarios.
<param unitAlias>:
The alias of the unit to save.
<param saveAlias>:
The name with which the unit will be save, this can be used to spawn the saved unit.
4.1.3 CampaignSpawnSavedUnit
string CampaignSpawnSavedUnit(saveAlias : string, playerAlias : string, position : HexPosition)
Script Guide - Triumph Studios B.V.
57
Save the specified unit in the campaign data so it can be used in other campaign scenarios.
Note 1: Spawned units will NOT have the same alias as when they were saved. If you want to change
the alias of the spawned unit use SetAlias on the spawned unit that is returned by this function
<return value>:
The alias of the unit that is spawned. Returns NULL on failure.
<param saveAlias>:
The alias with which the unit was saved.
<param playerAlias>:
The alias of the player which will own the unit.
<param position>:
The position to spawn the unit.
4.1.4 CampaignSpawnAsLeader
string CampaignSpawnSavedUnitAsLeader(saveAlias : string, playerAlias : string)
Spawn a saved hero unit as a leader unit.
Do this ONLY on map startup (use a timer that triggers at the beginning of turn 1).
Note 1: Spawned units will NOT have the same alias as when they were saved. If you want to change
the alias of the spawned unit use SetAlias on the spawned unit that is returned by the function
Note 2: Unit will be spawned at the position of the current leader unit.
<return value>:
The alias of the unit that is spawned. Returns NULL on failure.
<param saveAlias>:
The alias with which the unit was saved.
<param pPlayerAlias>:
The player whose leader we are spawning.
4.2
Data Access
The following commands are used to read and write data which is saved when the game is saved.
Script Guide - Triumph Studios B.V.
58
Map Data
This data is stored in the current map, and should be used to store data relating to a players progress
through that map.
First data values must be created in the Data Store for the map, found under Map Settings in Level Ed.
Only previously created values can be used by these functions.
Methods____________________________________________________
GetMapBool
Retrieve a boolean value from the map data
SetMapBool
Set a boolean value in the map data
GetMapNumber
Retrieve a numeric value from the map data
SetMapNumber
Set a numeric value in the map data
GetMapString
Retrieve a numeric value from the map data
SetMapString
Set a numeric value in the map data
Campaign Data
This data is stored in the current campaign, and should be used to transmit information between
scenarios within a campaign.
First data values must be created in the Data Store for the campaign, found in the campaign settings in
the campaign editor in Level Ed. Only previously created values can be used by these functions.
Methods____________________________________________________
GetCampaignBool
Retrieve a boolean value from the campaign data
SetCampaignBool
Set a boolean value in the campaign data
GetCampaignNumber
Retrieve a numeric value from the campaign data
SetCampaignNumber
Set a numeric value in the campaign data
GetCampaignString
Retrieve a string value from the campaign data
SetCampaignString
Set a string value in the campaign data
4.2.1 GetMapBool
bool GetMapBool(valueName : string)
Retrieve the named boolean value from the map data store.
<param valueName>:
The name of the value to retrieve, must have been previously created in the map's data store.
59
4.2.2 SetMapBool
SetMapBool(valueName : string, newValue : bool)
Set the named boolean value in the map data store.
<param valueName>:
The name of the value to set, must have been previously created in the map's data store.
<param newValue>:
The bool to place into the data store value
4.2.3 GetMapNumber
float GetMapNumber(valueName : string)
Retrieve the named numeric value from the map data store.
<param valueName>:
The name of the value to retrieve, must have been previously created in the map's data store.
4.2.4 SetMapNumber
SetMapNumber(valueName : string, newValue : float)
Set the named numeric value in the map data store.
<param valueName>:
The name of the value to set, must have been previously created in the map's data store.
<param newValue>:
The number to place into the data store value
4.2.5 GetMapString
string GetMapString(valueName : string)
Retrieve the named string value from the map data store.
<param valueName>:
The name of the value to retrieve, must have been previously created in the map's data store.
Script Guide - Triumph Studios B.V.
60
4.2.6 SetMapString
SetMapString(valueName : string, newValue : string)
Set the named string value in the map data store.
<param valueName>:
The name of the value to set, must have been previously created in the map's data store.
<param newValue>:
The string to place into the data store value
4.2.7 GetCampaignBool
bool GetCampaignBool(valueName : string)
Retrieve the named boolean value from the campaign data store.
<param valueName>:
The name of the value to retrieve, must have been previously created in the campaign's data
4.2.8 SetCampaignBool
SetCampaignBool(valueName : string, newValue : bool)
Set the named boolean value in the campaign data store.
<param valueName>:
The name of the value to set, must have been previously created in the campaign's data store.
<param newValue>: true, false
The bool to place into the data store value
4.2.9 GetCampaignNumber
float GetCampaignNumber(valueName : string)
Retrieve the named numeric value from the campaign data store.
Script Guide - Triumph Studios B.V.
61
<param valueName>:
The name of the value to retrieve, must have been previously created in the campaign's data
4.2.10
SetCampaignNumber
4.2.11
GetCampaignString
4.2.12
SetCampaignString
62