The S2 Script-o-Rama is a resource based on alpaca's ETW Script-o-Rama and my NTW Script-o-Rama that aims to serve many similar purposes:
Firstly it's meant as a general scripting discussion point, so if you'd like to just talk about some freak ideas or anything, they're welcome here.
Secondly it will serve as a focal point for scripting help and advice. You will find a lot of information here that alpaca never got round to posting in his old thread, but that is common knowledge among us more experienced scripters. I will also keep an eye on this thread and whenever I get the chance try to help people out with scripting related issues
As of yet this is a direct copy of the NTW Script-o-Rama and can simply be used as a reference manual for those looking to do some basic S2 scripting. I've started documenting functions for S2, but I don't have time to post them here yet (as you can see this thread takes a lot of manual formatting to be so accessible).
NOTE: Some of the content here is completely alpaca's work, I have just updated it and added a lot of new info. Credit goes to him for the idea and the basis of this work Table of Contents:
This section will explain some basic scripting rules, and give some tips to help get you started. Also contained here is extensive script documentation on usage, output, arguments and caveats.
Lua is a powerful, fast, lightweight, embeddable scripting language.
Lua is an open source, very fast, real-world scripting language. This means that in-game scripting is not technically limited to functions provided by the game - we can extend it with operators and functions that are not ever seen in CA's scripting code. Although this doesn't offer us much in terms of practicality for simple scripting, it can be put to great use for those interested in more advanced scripting.
Case sensitivity:
All Lua functions and objects are case-sensitive. That is, CampaignUI is not equal to campaignui, campaignUi or anything like that. So a mistake with case will cause your script to malfunction.
Whitespace:
Lua ignores whitespace, where applicable. So 3 > 1 is the same as 3>1 is the same as 3> 1
Key Words:
Click to view content:
Strings: Strings are sentences containing numbers, characters or symbols. They begin and end with quotation marks. Eg:
Code:
"Hello World"
Boolean Values: Boolean values can only be true or false
Type: The type of a variable can either be boolean, function, nil, number, string, table, thread or userdata. If any function requests a variable of a certain type, and a variable of a different type is passed to it it may well cause a CTD.
int: Short for integer. (Negative or positive whole number)
Comments:Comments are part of the scripting file that will be ignored by the game. A normal comment begins with "--" (without the quotes) and lasts the length of the line. A long comment begins with "--[[" (without the quotes) and ends with "]]--" (without the quotes). Long comments comment everything inside them out, so can be used to efficiently comment out large blocks of code. Examples:
Code:
--I'm a short comment
--[[And
I'm
A
Long
Comment ]]--
Basic Lua Operators & Statements:
Click to view content:
Arithmetic Operators:
Click to view content:
Addition:
+
Subtraction:
-
Multiplication:
*
Division:
/
Exponentiation:
^
Relational Operators:
Click to view content:
Equal to:
==
Not equal to:
~=
Less than:
<
Less than or equal to:
<=
Greater than:
>
Greater than or equal to:
>=
Logical Operators: Note: Logical operators are sometimes referred to as Boolean Operators, but they can be given non-boolean values.
Click to view content:
and
and takes two or more arguments and only returns true if they are all true
or
or only gives a false result if both of it's arguments are false
not
not is, simply put, a logical no. Putting not before a statement that would otherwise return true, will make it return false and vice versa.
Basic Statements:
Click to view content:
if
while
while is a type of loop. I'll not be explaining loops here, you can find tutorials on them with google very easily.
for
Another type of loop.
Backslash Escaping (Very important for logging):
Click to view content:
Backslash escaping allows the user to do things inside strings that would normally be quite akward to do. It is a very simple method of manipulating text. The following list contains the most relevant escape sequences used in game scripting:
\n - Newline. This moves the following text onto a new line.
\t - Tab. This tabs horizontally.
\\ - Backslash. This allows a single backslah to be inserted into the text.
\" - double quote. This allows a double quote to be inserted without ending the string.
Concatenation:
Click to view content:
Lua's string concatenation operator is written as follows:
Code:
..
That's two periods with no spaces between them. The whitespace rule does not apply here as this is an operator, which is easy to forget.
It is used for splicing strings together, as follows(output is listed respectively in the next spoiler):
Notice that it doesn't put spaces between arguments there for you (the first example), so it has to be done manually(the second example).
I.2 Effects
The game's general effect library not specifically geared towards scripting. From here you can do stuff like edit cash amounts, edit traits + ancillaries etc.
events.HistoricalEvents[#events.HistoricalEvents+1] =
function (context)
effect.historical_event("luddite_movement", context)
end
I.3 Campaign UI
CampaignUI seems to have loads of useful functions (see the list above). The main advantage of using CamaignUI is that the functions often don't require any arguments and return boolean values, making them very useable. CUI's main use is to retrieve data from the game - it has very little use for actually changing things.
CurrentSeasonString()
Calling CampaignUI.CurrentSeasonString() will return the current season as a string.
Spoiler Alert, click show to read:
Returns: Current season as string. One of Summer or Winter
Example:
Code:
CampaignUI.CurrentSeasonString() == "Summer"
Notes:
Be careful about case sensitivity
CurrentTurn()
Calling CampaignUI.CurrentTurn() will return the current turn number.
Spoiler Alert, click show to read:
Returns: Current turn as int.
Example:
Code:
CampaignUI.CurrentTurn() == 0
CurrentYear()
Calling CampaignUI.CurrentYear() will return the current year.
Spoiler Alert, click show to read:
Returns: Current year as int.
Example:
Code:
CampaignUI.CurrentYear() >= 1700
DisplayingTurns()
Calling CampaignUI.DisplayingTurns() will tell you if the game is displaying years or turns.
Spoiler Alert, click show to read:
Returns: Boolean: true if displaying turns, false if displaying years
Example:
Code:
if CampaignUI.DisplayingTurns() then
...
end
EndTurn()
Calling CampaignUI.EndTurn() will end the turn.
Spoiler Alert, click show to read:
Example:
Code:
CampaignUI.EndTurn()
EntityTypeSelected()
CampaignUI.EntityTypeSelected() will give you information about the currently selected game entity
Spoiler Alert, click show to read:
Returns: Entity details table. Important here is CampaignUI.EntityTypeSelected().Entity which holds a pointer (e.g. a Character Pointer) that can be used in other functions
VictoryConditions: table
Regions: table
1: table
Name: string:New France
Address: userdata
type: string:Pointer<REGION>
__tostring: function
__eq: function
2: table
Name: string:Georgia
Address: userdata
type: string:Pointer<REGION>
__tostring: function
__eq: function
3: table
Name: string:Leeward Islands
Address: userdata
type: string:Pointer<REGION>
__tostring: function
__eq: function
4: table
Name: string:Ireland
Address: userdata
type: string:Pointer<REGION>
__tostring: function
__eq: function
5: table
Name: string:Gibraltar
Address: userdata
type: string:Pointer<REGION>
__tostring: function
__eq: function
6: table
Name: string:Florida
Address: userdata
type: string:Pointer<REGION>
__tostring: function
__eq: function
7: table
Name: string:Hindustan
Address: userdata
type: string:Pointer<REGION>
__tostring: function
__eq: function
8: table
Name: string:Scotland
Address: userdata
type: string:Pointer<REGION>
__tostring: function
__eq: function
9: table
Name: string:England
Address: userdata
type: string:Pointer<REGION>
__tostring: function
__eq: function
ConquestDescription: string:Capture and hold 25 regions by the end of the year 1750, including the regions shown.
TotalRegionsNeeded: number
PrestigeDescription: string:
WealthRanking: string:Spectacular
Leader: table
ActionPointsPerTurn: number
Flag: string:data\ui\flags\britain/portrait_flags.tga
Title: string:
Traits: table
1: table
ExplanationText: string:This man has invested heavily in the navy.
IconFilename: string:data/ui/campaign ui/pips/effect_characters.tga
Name: string:Likes Uniforms
Effects: table
1: table
Priority: number
Description: string:-10% recruitment cost for all naval units
IconFilename: string:data/ui/campaign ui/pips/effect_navy.tga
ColourText: string:He has taken to wearing ceremonial uniforms at all times, which makes bathing a difficult business.
AttributeEffects: table
RemovalText: string:This trait can be lost by more balanced spending.
2: table
ExplanationText: string:Youthful obsessions are one thing, but they are supposed to be set aside.
IconFilename: string:data/ui/campaign ui/pips/effect_characters.tga
Name: string:Lewd and Loose
Effects: table
1: table
Priority: number
Description: string:-10 to diplomatic relations
IconFilename: string:
ColourText: string:This man's behaviour is boorish and nationally embarrassing, even if the ambassador's wife did have a fantastic arse!
AttributeEffects: table
RemovalText: string:This man's ways are set, unfortunately.
Effects: table
1: table
Icon: string:
Tooltip: string:-10 to diplomatic relations
2: table
Icon: string:data/ui/campaign ui/pips/effect_navy.tga
Tooltip: string:-10% recruitment cost for all naval units
PostEffects: table
diplomacy: table
Value: number
Description: string:+0 to diplomatic relations
prestige: table
Value: number
Description: string:+0 Prestige per turn
FactionColour: table
b: number
g: number
r: number
ShowAsCharacter: boolean
IsMilitary: boolean
Attributes: table
morale_sea: table
Value: number
AttributeName: string:Morale
PipPath: string:PLACEHOLDER
research: table
Value: number
AttributeName: string:Research Skill
PipPath: string:data/ui/campaign ui/pips/skill_research.tga
land_siege_engineering: table
Value: number
AttributeName: string:Siege engineering
PipPath: string:PLACEHOLDER
movement_points_land: table
Value: number
AttributeName: string:movement_points_land_name
PipPath: string:PLACEHOLDER
management: table
Value: number
AttributeName: string:Management Skill
PipPath: string:data/ui/campaign ui/pips/skill_managing.tga
PrimaryAttributePath: string:data/ui/campaign ui/pips/skill_managing.tga
PrimaryAttributeName: string:Management Skill
zeal: table
Value: number
AttributeName: string:Religious Zeal
PipPath: string:data/ui/campaign ui/pips/skill_zeal.tga
subterfuge: table
Value: number
AttributeName: string:Subterfuge Skill
PipPath: string:data/ui/campaign ui/pips/skill_spying.tga
duelling_swords: table
Value: number
AttributeName: string:Sword duelling
PipPath: string:data/ui/campaign ui/pips/skill_swordfighting.tga
duelling_pistols: table
Value: number
AttributeName: string:Pistol duelling
PipPath: string:data/ui/campaign ui/pips/skill_shooting.tga
morale_land: table
Value: number
AttributeName: string:Morale
PipPath: string:PLACEHOLDER
trade: table
Value: number
AttributeName: string:Trade
PipPath: string:PLACEHOLDER
PrimaryLevel: number
land_defence_engineering: table
Value: number
AttributeName: string:Land defence engineering
PipPath: string:PLACEHOLDER
command_sea: table
Value: number
AttributeName: string:Command at Sea
PipPath: string:data/ui/campaign ui/pips/skill_naval.tga
command_land: table
Value: number
AttributeName: string:Command on Land
PipPath: string:data/ui/campaign ui/pips/skill_command.tga
Abilities: table
can_research: boolean
can_assassinate: boolean
can_attack_naval: boolean
can_build_religious: boolean
can_attack_land: boolean
can_receive_duel: boolean
can_build_fort: boolean
can_duel: boolean
can_convert: boolean
can_sabotage: boolean
can_spy: boolean
PostName: string:King
CommanderType: number
ActionPoints: number
Post: string:faction_leader
AgentType: string:Minister
IsNaval: boolean
SmallFlag: string:data\ui\flags\britain/small.tga
UniformColour: table
b: number
g: number
r: number
MaskImage: string:
TechImage: string:
Playable: boolean
CardImage: string:data/ui/portraits/european/cards/king/old/014.tga
InfoImage: string:data/ui/portraits/european/Info/king/old/014.jpg
Address: userdata
type: string:Pointer<CHARACTER>
__tostring: function
__eq: function
Location: string:England
Name: string:William III
Age: number
Ancillaries: table
PrestigeRanking: string:Sublime
FlagPath: string:data\ui\flags\britain
UniformColour: table
B: number
G: number
R: number
Address: userdata
type: string:Pointer<FACTION>
__tostring: function
__eq: function
Name: string:Great Britain
PrimaryColour: table
B: number
G: number
R: number
Key: string:britain
PowerRanking: string:Terrifying
IsPlayersTurn()
IsPlayersTurn returns a boolean stating the obvious
Click to view content:
Returns: true or false depending on whether or not it is the player's turn. Example:
Code:
CampaignUI.IsPlayersTurn()
InitialiseRegionInfoDetails(<Pointer>REGION)
InitialiseRegionInfoDetails returns all info you can get on a certain region. You have to supply a pointer (get it from RegionsOwnedByFaction for example)
UpperOrder: table
1: table
Total: number: 2
Predicted: number: 0
Positive: boolean: true
PredictedTooltip: string: Government type: 2 (Predicted)||Your government type has a positive effect on this class.
Pip: string: data/ui/campaign ui/pips/government-happy.tga
Tooltip: string: Government type: 2||Your government type has a positive effect on this class.
EqualPipPredictedTooltip: string: Government type: 2 / 2 (Predicted)||Your government type has a positive effect on this class.
2: table
Total: number: 4
Predicted: number: 0
Positive: boolean: false
PredictedTooltip: string: Tax burden: 4 (Predicted)||To lessen the tax burden on your population simply lower taxes.||You can do this on the Government panel.
Pip: string: data/ui/campaign ui/pips/taxes-unhappy.tga
Tooltip: string: Tax burden: 4||To lessen the tax burden on your population simply lower taxes.||You can do this on the Government panel.
EqualPipPredictedTooltip: string: Tax burden: 4 / 4 (Predicted)||To lessen the tax burden on your population simply lower taxes.||You can do this on the Government panel.
3: table
Total: number: 5
Predicted: number: 0
Positive: boolean: false
PredictedTooltip: string: People in government: 5 (Predicted) ||This is from your ministers' traits.||You can view all their traits on the Government panel.
Pip: string: data/ui/campaign ui/pips/character_traits-unhappy.tga
Tooltip: string: People in government: 5 ||This is from your ministers' traits.||You can view all their traits on the Government panel.
EqualPipPredictedTooltip: string: People in government: 5 / 5 (Predicted) ||This is from your ministers' traits.||You can view all their traits on the Government panel.
4: table
Total: number: 1
Predicted: number: 0
Positive: boolean: true
PredictedTooltip: string: Government buildings (Repression): 1 (Predicted)||Increase repression in your regions by upgrading government buildings.
Pip: string: data/ui/campaign ui/pips/buildings-repression.tga
Tooltip: string: Government buildings (Repression): 1||Increase repression in your regions by upgrading government buildings.
EqualPipPredictedTooltip: string: Government buildings (Repression): 1 / 1 (Predicted)||Increase repression in your regions by upgrading government buildings.
5: table
Total: number: 3
Predicted: number: 0
Positive: boolean: true
PredictedTooltip: string: People in government (Repression): 3 (Predicted)||This is from your minister's traits.||You can view all their effects on the Government panel.
Pip: string: data/ui/campaign ui/pips/character_traits-repression.tga
Tooltip: string: People in government (Repression): 3||This is from your minister's traits.||You can view all their effects on the Government panel.
EqualPipPredictedTooltip: string: People in government (Repression): 3 / 3 (Predicted)||This is from your minister's traits.||You can view all their effects on the Government panel.
6: table
Total: number: 1
Predicted: number: 0
Positive: boolean: true
PredictedTooltip: string: Town Watch (Repression): 1 (Predicted)||This is an expensive emergency measure to suppress unrest.
Pip: string: data/ui/campaign ui/pips/policing-repression.tga
Tooltip: string: Town Watch (Repression): 1||This is an expensive emergency measure to suppress unrest.
EqualPipPredictedTooltip: string: Town Watch (Repression): 1 / 1 (Predicted)||This is an expensive emergency measure to suppress unrest.
Total: number: -2
IsPercentage: boolean: false
PipValue: number: 1
ReligionKey: string: rel_catholic
WealthChange: number: 2
Settlement: string: Cayenne
Wealth: number: 782
ActiveLowerClass: string: Lower Class
TownWealth: table
1: table
Total: number: 3
Predicted: number: 0
Positive: boolean: true
PredictedTooltip: string: Ports: 3 (Predicted) ||Increase this by developing your trading ports and fisheries.
Pip: string: data/ui/campaign ui/pips/eco-trade_harbour.tga
Tooltip: string: Ports: 3 ||Increase this by developing your trading ports and fisheries.
EqualPipPredictedTooltip: string: Ports: 3 / 3 (Predicted) ||Increase this by developing your trading ports and fisheries.
2: table
Total: number: 8
Predicted: number: 1
Positive: boolean: false
PredictedTooltip: string: Tax: 9 (Predicted) ||Tax rates are slowing economic growth.||Reduce this by lowering tax rates.
Pip: string: data/ui/campaign ui/pips/taxes-unhappy.tga
Tooltip: string: Tax: 8 ||Tax rates are slowing economic growth.||Reduce this by lowering tax rates.
EqualPipPredictedTooltip: string: Tax: 8 / 9 (Predicted) ||Tax rates are slowing economic growth.||Reduce this by lowering tax rates.
3: table
Total: number: 3
Predicted: number: 2
Positive: boolean: true
PredictedTooltip: string: Enlightenment: 5 (Predicted) ||Researching certain technologies increases economic growth.
Pip: string: data/ui/campaign ui/pips/town_research.tga
Tooltip: string: Enlightenment: 3 ||Researching certain technologies increases economic growth.
EqualPipPredictedTooltip: string: Enlightenment: 3 / 5 (Predicted) ||Researching certain technologies increases economic growth.
PipValue: number: 50
Total: number: -2
IsPercentage: boolean: false
Taxed: boolean: true
ReligiousBreakdown: table
1: table
Change: number: 0
Name: string: Animism
Key: string: rel_animist
Icon: string: data/ui/campaign ui/pips/animism.tga
Percentage: number: 15.000000953674
2: table
Change: number: 0
Name: string: Catholicism
Key: string: rel_catholic
Icon: string: data/ui/campaign ui/pips/roman_catholic.tga
Percentage: number: 85.000007629395
RegionWealth: table
1: table
Total: number: 440
LostTooltip: string: Port: 0 (Predicted)
Positive: boolean: true
Tooltip: string: Port: 440
EqualPipPredictedTooltip: string: Port: 440
Predicted: number: 0
Lost: number: 0
PredictedTooltip: string: Port: 440 (Predicted)
Pip: string: data/ui/campaign ui/pips/trade_port.tga
2: table
Total: number: 342
LostTooltip: string: Spice exports: 0 (0 Pounds) (Predicted)
Positive: boolean: true
Tooltip: string: Spice exports: 342 (18 Pounds)
EqualPipPredictedTooltip: string: Spice exports: 342 (18 Pounds)
Predicted: number: 0
Lost: number: 0
PredictedTooltip: string: Spice exports: 342 (18 Pounds) (Predicted)
Pip: string: data/ui/campaign ui/pips/spices.tga
PipValue: number: 50
Total: number: 782
IsPercentage: boolean: false
PopulationGrowth: table
1: table
Total: number: 0.29999998211861
Predicted: number: 0
Positive: boolean: true
PredictedTooltip: string: Subsistence agriculture: 0.3% (Predicted)||This is the background level of food production in the region.
Pip: string: data/ui/campaign ui/pips/population_subsistence.tga
Tooltip: string: Subsistence agriculture: 0.3%||This is the background level of food production in the region.
EqualPipPredictedTooltip: string: Subsistence agriculture: 0.3% / 0.3% (Predicted)||This is the background level of food production in the region.
2: table
Total: number: 0.37000000476837
Predicted: number: 0
Positive: boolean: false
PredictedTooltip: string: Tax burden: 0.37% (Predicted)||To counter this, simply lower taxes for the lower classes.||You can do this on the Government panel.
Pip: string: data/ui/campaign ui/pips/taxes-unhappy.tga
Tooltip: string: Tax burden: 0.37%||To counter this, simply lower taxes for the lower classes.||You can do this on the Government panel.
EqualPipPredictedTooltip: string: Tax burden: 0.37% / 0.37% (Predicted)||To counter this, simply lower taxes for the lower classes.||You can do this on the Government panel.
3: table
Total: number: 5.0099997520447
Predicted: number: 0
Positive: boolean: true
PredictedTooltip: string: Immigration from the home theatre: 5.01% (Predicted)||Unhappiness drives people to seek a better life elsewhere.
Pip: string: data/ui/campaign ui/pips/migration_happy.tga
Tooltip: string: Immigration from the home theatre: 5.01%||Unhappiness drives people to seek a better life elsewhere.
EqualPipPredictedTooltip: string: Immigration from the home theatre: 5.01% / 5.01% (Predicted)||Unhappiness drives people to seek a better life elsewhere.
PipValue: number: 0.0099999997764826
Total: number: 4.9399995803833
IsPercentage: boolean: true
UpperTax: number: 0.16489998996258
Theatre: string: 1
Effects: table
Governor: table
ActionPointsPerTurn: number: 0
Flag: string: data\ui\flags\france/portrait_flags.tga
Title: string:
Traits: table
1: table
ExplanationText: string: This fellow believes that ministers should set the right example.
IconFilename: string: data/ui/campaign ui/pips/effect_characters.tga
Name: string: Honest
Effects: table
ColourText: string: This man believes in truth and honesty, something he pursues through his work.
AttributeEffects: table
1: string: +1 to Management.
RemovalText: string: This trait is permanent and cannot be lost.
2: table
ExplanationText: string: This man has done much for his nation's cultural landscape.
IconFilename: string: data/ui/campaign ui/pips/effect_characters.tga
Name: string: Sybarite
Effects: table
1: table
Priority: number: 9019
Description: string: +1 happiness (lower classes)
IconFilename: string: data/ui/campaign ui/pips/effect_public_order.tga
2: table
Priority: number: 9017
Description: string: -1 happiness (nobility)
IconFilename: string: data/ui/campaign ui/pips/effect_public_order.tga
ColourText: string: Whereas most people can be appeased with cheap whores and gin by the bucket, some of us have more refined tastes.
AttributeEffects: table
RemovalText: string: This character trait cannot be lost, only improved.
3: table
ExplanationText: string: The treasury has remained virtually untouched since he took charge.
IconFilename: string: data/ui/campaign ui/pips/effect_characters.tga
Name: string: Frugal and Thrifty
Effects: table
1: table
Priority: number: 4
Description: string: -2 to Management for treasury administration
IconFilename: string: data/ui/campaign ui/pips/effect_economy.tga
2: table
Priority: number: 9017
Description: string: -1 happiness (nobility)
IconFilename: string: data/ui/campaign ui/pips/effect_public_order.tga
ColourText: string: He keeps a tight rein on the privy purse strings, all expenditure must be justified in writing. In triplicate.
AttributeEffects: table
1: string: +1 to Management.
RemovalText: string: This character trait can be lost by more generous use of tax income.
PostEffects: table
tax_efficiency: table
Value: number: 4
Description: string: +4% bonus to tax income across theatre
repression: table
Value: number: 2
Description: string: +2 to repression across the theatre
land_upkeep_cost: table
Value: number: -4
Description: string: -4% upkeep costs for all army units
FactionColour: table
b: number: 240
g: number: 255
r: number: 255
ShowAsCharacter: boolean: true
Effects: table
1: table
Icon: string: data/ui/campaign ui/pips/effect_public_order.tga
Tooltip: string: +1 happiness (lower classes)
2: table
Icon: string: data/ui/campaign ui/pips/effect_public_order.tga
Tooltip: string: -2 happiness (nobility)
3: table
Icon: string: data/ui/campaign ui/pips/effect_economy.tga
Tooltip: string: -2 to Management for treasury administration
IsMilitary: boolean: false
Attributes: table
morale_sea: table
Value: number: -1
AttributeName: string: Morale
PipPath: string: PLACEHOLDER
research: table
Value: number: -1
AttributeName: string: Research Skill
PipPath: string: data/ui/campaign ui/pips/skill_research.tga
land_siege_engineering: table
Value: number: -1
AttributeName: string: Siege engineering
PipPath: string: PLACEHOLDER
movement_points_land: table
Value: number: -1
AttributeName: string: movement_points_land_name
PipPath: string: PLACEHOLDER
management: table
Value: number: 4
AttributeName: string: Management Skill
PipPath: string: data/ui/campaign ui/pips/skill_managing.tga
PrimaryAttributePath: string: data/ui/campaign ui/pips/skill_managing.tga
PrimaryAttributeName: string: Management Skill
zeal: table
Value: number: -1
AttributeName: string: Religious Zeal
PipPath: string: data/ui/campaign ui/pips/skill_zeal.tga
subterfuge: table
Value: number: -1
AttributeName: string: Subterfuge Skill
PipPath: string: data/ui/campaign ui/pips/skill_spying.tga
duelling_swords: table
Value: number: -1
AttributeName: string: Sword duelling
PipPath: string: data/ui/campaign ui/pips/skill_swordfighting.tga
duelling_pistols: table
Value: number: -1
AttributeName: string: Pistol duelling
PipPath: string: data/ui/campaign ui/pips/skill_shooting.tga
morale_land: table
Value: number: -1
AttributeName: string: Morale
PipPath: string: PLACEHOLDER
trade: table
Value: number: -1
AttributeName: string: Trade
PipPath: string: PLACEHOLDER
PrimaryLevel: number: 5
land_defence_engineering: table
Value: number: -1
AttributeName: string: Land defence engineering
PipPath: string: PLACEHOLDER
command_sea: table
Value: number: -1
AttributeName: string: Command at Sea
PipPath: string: data/ui/campaign ui/pips/skill_naval.tga
command_land: table
Value: number: -1
AttributeName: string: Command on Land
PipPath: string: data/ui/campaign ui/pips/skill_command.tga
Abilities: table
can_research: boolean: false
can_assassinate: boolean: false
can_attack_naval: boolean: false
can_build_religious: boolean: false
can_attack_land: boolean: false
can_receive_duel: boolean: false
can_build_fort: boolean: false
can_duel: boolean: false
can_convert: boolean: false
can_sabotage: boolean: false
can_spy: boolean: false
CommanderType: number: 0
ActionPoints: number: 0
Post: string: governor_america
AgentType: string: Minister
IsNaval: boolean: false
SmallFlag: string: data\ui\flags\france/small.tga
UniformColour: table
b: number: 240
g: number: 255
r: number: 255
MaskImage: string:
TechImage: string:
Playable: boolean: false
CardImage: string: data/ui/portraits/european/Cards/minister/young/077.tga
InfoImage: string: data/ui/portraits/european/Info/minister/young/077.jpg
Address: userdata
type: string: Pointer<CHARACTER>
__tostring: function
__eq: function
Location: string: France
Name: string: Gaston Rousseau
Age: number: 43
Ancillaries: table
OwningFactionKey: string: france
AdministrationCostPercentage: number: -0.029999999329448
GovernorPercentage: number: 0.03999999910593
LowerTax: number: 0.16489998996258
BuildingPercentage: number: 0
UpperTaxPercentage: number: 0.1499999910593
PopulationNumber: number: 4390
Population: string: 4390
LowerTaxPercentage: number: 0.1499999910593
Name: string: French Guyana
Address: userdata
type: string: Pointer<REGION>
__tostring: function
__eq: function
LowerOrder: table
1: table
Total: number: 4
Predicted: number: 0
Positive: boolean: false
PredictedTooltip: string: Tax burden: 4 (Predicted)||To lessen the tax burden on your population simply lower taxes.||You can do this on the Government panel.
Pip: string: data/ui/campaign ui/pips/taxes-unhappy.tga
Tooltip: string: Tax burden: 4||To lessen the tax burden on your population simply lower taxes.||You can do this on the Government panel.
EqualPipPredictedTooltip: string: Tax burden: 4 / 4 (Predicted)||To lessen the tax burden on your population simply lower taxes.||You can do this on the Government panel.
2: table
Total: number: 2
Predicted: number: 0
Positive: boolean: false
PredictedTooltip: string: People in government: 2 (Predicted) ||This is from your ministers' traits.||You can view all their traits on the Government panel.
Pip: string: data/ui/campaign ui/pips/character_traits-unhappy.tga
Tooltip: string: People in government: 2 ||This is from your ministers' traits.||You can view all their traits on the Government panel.
EqualPipPredictedTooltip: string: People in government: 2 / 2 (Predicted) ||This is from your ministers' traits.||You can view all their traits on the Government panel.
3: table
Total: number: 1
Predicted: number: 0
Positive: boolean: true
PredictedTooltip: string: Government buildings (Repression): 1 (Predicted)||Increase repression in your regions by upgrading government buildings.
Pip: string: data/ui/campaign ui/pips/buildings-repression.tga
Tooltip: string: Government buildings (Repression): 1||Increase repression in your regions by upgrading government buildings.
EqualPipPredictedTooltip: string: Government buildings (Repression): 1 / 1 (Predicted)||Increase repression in your regions by upgrading government buildings.
4: table
Total: number: 3
Predicted: number: 0
Positive: boolean: true
PredictedTooltip: string: People in government (Repression): 3 (Predicted)||This is from your minister's traits.||You can view all their effects on the Government panel.
Pip: string: data/ui/campaign ui/pips/character_traits-repression.tga
Tooltip: string: People in government (Repression): 3||This is from your minister's traits.||You can view all their effects on the Government panel.
EqualPipPredictedTooltip: string: People in government (Repression): 3 / 3 (Predicted)||This is from your minister's traits.||You can view all their effects on the Government panel.
5: table
Total: number: 1
Predicted: number: 0
Positive: boolean: true
PredictedTooltip: string: Town Watch (Repression): 1 (Predicted)||This is an expensive emergency measure to suppress unrest.
Pip: string: data/ui/campaign ui/pips/policing-repression.tga
Tooltip: string: Town Watch (Repression): 1||This is an expensive emergency measure to suppress unrest.
EqualPipPredictedTooltip: string: Town Watch (Repression): 1 / 1 (Predicted)||This is an expensive emergency measure to suppress unrest.
IsPercentage: boolean: false
PipValue: number: 1
Total: number: -1
ActiveUpperClass: string: Nobility
ReligionIcon: string: data/ui/campaign ui/pips/roman_catholic.tga
PopulationChange: number: 1
Returns: A table with diplomacy details of the faction. Example:
Code:
RetrieveDiplomacyDetails("france")
Example Returns:
Code:
TradeRights table: 1AD793B8
wurttemberg table: 1AD79518
Flag data\ui\flags\wurttemberg/small.tga
Name Baden-Württemberg
Label wurttemberg
italy_kingdom table: 1AD79458
Flag data\ui\flags\italy_kingdom/small.tga
Name Kingdom of Italy
Label italy_kingdom
netherlands table: 1AD7FF58
Flag data\ui\flags\united_netherlands/small.tga
Name Batavian Republic
Label netherlands
swiss_confederation table: 1AD79478
Flag data\ui\flags\swiss_confederation/small.tga
Name Swiss Confederation
Label swiss_confederation
spain table: 1AD7FDD8
Flag data\ui\flags\spain/small.tga
Name Spain
Label spain
AtWar table: 1AD79378
austria table: 1AD794B8
Flag data\ui\flags\austria/small.tga
Name Austria
Label austria
sicily table: 1AD795B8
Flag data\ui\flags\naples_sicily/small.tga
Name Kingdom of Sicily
Label sicily
naples table: 1AD79558
Flag data\ui\flags\naples/small.tga
Name Kingdom of Naples
Label naples
britain table: 1AD794D8
Flag data\ui\flags\britain/small.tga
Name Great Britain
Label britain
sweden table: 1AD7FDF8
Flag data\ui\flags\sweden/small.tga
Name Sweden
Label sweden
russia table: 1AD79498
Flag data\ui\flags\russia/small.tga
Name Russia
Label russia
Protectorates table: 1AD793F8
ProtectorOf table: 1AD79418
Allies table: 1AD79398
wurttemberg table: 1AD794F8
Flag data\ui\flags\wurttemberg/small.tga
Name Baden-Württemberg
Label wurttemberg
bavaria table: 1AD79578
Flag data\ui\flags\bavaria/small.tga
Name Bavaria
Label bavaria
italy_kingdom table: 1AD79438
Flag data\ui\flags\italy_kingdom/small.tga
Name Kingdom of Italy
Label italy_kingdom
netherlands table: 1AD799B8
Flag data\ui\flags\united_netherlands/small.tga
Name Batavian Republic
Label netherlands
swiss_confederation table: 1AD79538
Flag data\ui\flags\swiss_confederation/small.tga
Name Swiss Confederation
Label swiss_confederation
spain table: 1AD799D8
Flag data\ui\flags\spain/small.tga
Name Spain
Label spain
Returns: Table with a list of region pointers and localised region names
Example:
Code:
CampaignUI.RegionsOwnedByFaction("britain")
Will return a table containing this info:
Code:
1: table
Name: string: Ireland
Address: userdata
type: string: Pointer<REGION>
__tostring: function
__eq: function
2: table
Name: string: England
Address: userdata
type: string: Pointer<REGION>
__tostring: function
__eq: function
3: table
Name: string: Jamaica
Address: userdata
type: string: Pointer<REGION>
__tostring: function
__eq: function
4: table
Name: string: Bahamas
Address: userdata
type: string: Pointer<REGION>
__tostring: function
__eq: function
5: table
Name: string: Rupert's Land
Address: userdata
type: string: Pointer<REGION>
__tostring: function
__eq: function
6: table
Name: string: Scotland
Address: userdata
type: string: Pointer<REGION>
__tostring: function
__eq: function
RetrieveFactionRegionList(<faction_key>)
CampaignUI.RetrieveFactionRegionList() will give you a list of all of a faction's settlements. Similar to RegionsOwnedByFaction but returns settlement pointers instead of region pointers
Spoiler Alert, click show to read:
Parameters: Faction key as string
Returns: Table with a list of settlement pointers
Example:
Code:
CampaignUI.RetrieveFactionRegionList("britain")
Will return a table containing this info:
Code:
1: table
SettlementAddress: userdata
type: string: Pointer<SETTLEMENT>
__tostring: function
__eq: function
2: table
SettlementAddress: userdata
type: string: Pointer<SETTLEMENT>
__tostring: function
__eq: function
3: table
SettlementAddress: userdata
type: string: Pointer<SETTLEMENT>
__tostring: function
__eq: function
4: table
SettlementAddress: userdata
type: string: Pointer<SETTLEMENT>
__tostring: function
__eq: function
5: table
SettlementAddress: userdata
type: string: Pointer<SETTLEMENT>
__tostring: function
__eq: function
6: table
SettlementAddress: userdata
type: string: Pointer<SETTLEMENT>
__tostring: function
__eq: function
1: table
ActionPointsPerTurn: number: 22
Transitioning: boolean: false
Ancillaries: table
Traits: table
Flag: string: data\ui\flags\france/portrait_flags.tga
Effects: table
Abilities: table
can_research: boolean: false
can_assassinate: boolean: false
can_attack_naval: boolean: false
can_build_religious: boolean: false
can_attack_land: boolean: true
can_receive_duel: boolean: false
can_build_fort: boolean: false
can_duel: boolean: false
can_convert: boolean: false
can_sabotage: boolean: false
can_spy: boolean: false
Attributes: table
morale_sea: table
Value: number: -1
AttributeName: string: Morale
PipPath: string: PLACEHOLDER
research: table
Value: number: -1
AttributeName: string: Research Skill
PipPath: string: data/ui/campaign ui/pips/skill_research.tga
land_siege_engineering: table
Value: number: -1
AttributeName: string: Siege engineering
PipPath: string: PLACEHOLDER
movement_points_land: table
Value: number: -1
AttributeName: string: movement_points_land_name
PipPath: string: PLACEHOLDER
management: table
Value: number: -1
AttributeName: string: Management Skill
PipPath: string: data/ui/campaign ui/pips/skill_managing.tga
PrimaryAttributePath: string: data/ui/campaign ui/pips/skill_command.tga
PrimaryAttributeName: string: Command on Land
zeal: table
Value: number: -1
AttributeName: string: Religious Zeal
PipPath: string: data/ui/campaign ui/pips/skill_zeal.tga
subterfuge: table
Value: number: -1
AttributeName: string: Subterfuge Skill
PipPath: string: data/ui/campaign ui/pips/skill_spying.tga
duelling_swords: table
Value: number: -1
AttributeName: string: Sword duelling
PipPath: string: data/ui/campaign ui/pips/skill_swordfighting.tga
duelling_pistols: table
Value: number: -1
AttributeName: string: Pistol duelling
PipPath: string: data/ui/campaign ui/pips/skill_shooting.tga
morale_land: table
Value: number: -1
AttributeName: string: Morale
PipPath: string: PLACEHOLDER
trade: table
Value: number: -1
AttributeName: string: Trade
PipPath: string: PLACEHOLDER
PrimaryLevel: number: 1
land_defence_engineering: table
Value: number: -1
AttributeName: string: Land defence engineering
PipPath: string: PLACEHOLDER
command_sea: table
Value: number: -1
AttributeName: string: Command at Sea
PipPath: string: data/ui/campaign ui/pips/skill_naval.tga
command_land: table
Value: number: 0
AttributeName: string: Command on Land
PipPath: string: data/ui/campaign ui/pips/skill_command.tga
IsMilitary: boolean: true
FactionColour: table
b: number: 240
g: number: 255
r: number: 255
ShowAsCharacter: boolean: false
PosX: number: 16.522933959961
Soldiers: number: 122
Units: number: 3
PosY: number: 347.06695556641
CommanderType: number: 5
ActionPoints: number: 22
Title: string:
AgentType: string: Brigadier
IsNaval: boolean: false
SmallFlag: string: data\ui\flags\france/small.tga
UniformColour: table
b: number: 240
g: number: 255
r: number: 255
MaskImage: string: data/ui/units/icons/Euro_Provincial_Cavalry_icon_cavs_mask.tga
TechImage: string:
Playable: boolean: true
CardImage: string: data/ui/units/icons/Euro_Provincial_Cavalry_icon_cavs.tga
InfoImage: string:
Address: userdata
type: string: Pointer<CHARACTER>
__tostring: function
__eq: function
Location: string: Paris
Name: string: Charles Lagrange
Age: number: 18
CommandedUnit: table
Charge: number: 7
DisplayAsUnit: boolean: true
Reloading: number: 0
FactionColour: table
b: number: 240
g: number: 255
r: number: 255
Firepower: number: 0
Manoeuvrability: string: manoeuverability_medium
InTransit: boolean: false
RecruitCost: number: 975
CommanderType: number: 5
Accuracy: number: 0
Id: string: unit35
Defence: number: 5
knowledge_mask: number: 15
PromotionCost: number: 1950
IsArtillery: boolean: false
Replenished: boolean: false
Men: number: 30
Ammunition: number: 0
Description: string: These locally recruited cavalry are a valuable aid in keeping order.
InfoPic: string: data/ui/units/info/euro_provincial_cavalry
Replenishable: boolean: false
UnitRecord: table
Ammunition: number: 0
RecruitTime: number: 1
UpkeepCost: number: 310
InfoPic: string: data/ui/units/info/euro_provincial_cavalry
Class: string: Cavalry
Range: number: 0
MPCost: number: 650
Key: string: euro_provincial_cavalry_gendarmerie
IsArtillery: boolean: false
IsNaval: boolean: false
Experience: number: 0
RecruitCost: number: 975
Men: number: 60
Defence: number: 5
Reloading: number: 0
Melee: number: 10
Accuracy: number: 0
Firepower: number: 0
DisplayNumber: number: 60
ClassID: number: 9
Charge: number: 7
Guns: number: 0
Description: string: These locally recruited cavalry are a valuable aid in keeping order.
Name: string: Gendarmerie
Morale: number: 7
SiegeUnit: boolean: false
Icon: string: data/ui/units/icons/Euro_Provincial_Cavalry_icon_cavs
LongDescription: string:
These light horsemen are often little more than mounted militia, but with a greater social standing. Cavalry always see themselves as better than footsoldiers, but in this case, it may be true. It is, after all, not cheap to purchase and maintain a decent horse, and this means that men with financial standing make up the majority of recruits.
They are, however, not as disciplined as regular cavalry, simply because they do not have the time or available resources to learn the craft of war as thoroughly. They are, however, extremely useful in policing the rougher, lower orders and keeping the existing social structure intact.
Historically, there are many examples of yeomanry or gendarmes turning on their own citizenry with surprising and horrific violence. They were widely used against the anti-factory Luddites in northern England and, most infamously, were responsible for the Peterloo Massacre in 1819, when the Manchester and Salford Yeomanry charged a mostly peaceful, but excited crowd, and cut down many unarmed protestors.
MPCategory: number: 1
RegimentName: string: 1st Regiment of Horse
LongDescription: string:
These light horsemen are often little more than mounted militia, but with a greater social standing. Cavalry always see themselves as better than footsoldiers, but in this case, it may be true. It is, after all, not cheap to purchase and maintain a decent horse, and this means that men with financial standing make up the majority of recruits.
They are, however, not as disciplined as regular cavalry, simply because they do not have the time or available resources to learn the craft of war as thoroughly. They are, however, extremely useful in policing the rougher, lower orders and keeping the existing social structure intact.
Historically, there are many examples of yeomanry or gendarmes turning on their own citizenry with surprising and horrific violence. They were widely used against the anti-factory Luddites in northern England and, most infamously, were responsible for the Peterloo Massacre in 1819, when the Manchester and Salford Yeomanry charged a mostly peaceful, but excited crowd, and cut down many unarmed protestors.
ExistingUnit: boolean: true
Speed: number: 0
UniformColour: table
b: number: 240
g: number: 255
r: number: 255
Icon: string: data/ui/units/icons/Euro_Provincial_Cavalry_icon_cavs
NeedsRepair: boolean: false
ActionPoints: number: 28
RepairCost: number: 0
Melee: number: 10
IsNaval: boolean: false
ShowAsCharacter: boolean: false
UpkeepCost: number: 298
Portrait: string:
Range: number: 0
HullStrength: number: 0
Morale: number: 7
Experience: number: 0
Address: userdata
type: string: Pointer<UNIT>
__tostring: function
__eq: function
Traits: table
Guns: number: 0
Name: string: Gendarmerie
CommandersName: string: Charles Lagrange
2: table
ActionPointsPerTurn: number: 23
Transitioning: boolean: false
...
I.3 Game Interface
Called by using scripting.game_interface (after requiring the EpisodicScripting package) this is the primary package to allow us to change things in the game. Unfortunately it doesn't have too much content yet.
add_restricted_unit_record(<unit_key>)
add_restricted_unit_record allows you to remove a unit from being available for recruitment world-wide (similar to the SF units)
Spoiler Alert, click show to read:
Parameters: Unit key as string (as it appears in the units table)
remove_restricted_unit_record(<unit_key>)
remove_restricted_unit_record removes the restriction on a unit record that was previously set with add_restricted_unit_record
Spoiler Alert, click show to read:
Parameters: Unit key as string (as it appears in the units table)
I.5 Events
This is a list of hookable events as shown in the events.lua file in the data pack and certain patch packs. Events are not explicitly documented as they are mostly self-explanatory. If you have any questions on any of them just ask.
Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell
To tie some code into an event you need to add a function onto the end of the event table needed (remember all events are tables) as follows:
Code:
events.EventName[#events.EventName+1] = function(context)
code
end
So the following code adds some cash to a faction at the start of it's turn.
Code:
events.FactionTurnStart[#events.FactionTurnStart+1] = function(context)
effect.adjust_treasury(100000, context)
end
This method of event hooking saves filling functions such as OnFactionTurnStart() up with your own code (thus possibly confusing you) and is more reliable for people not too familiar with scripting.
Just remember not to place the code chunk inside another function. Code that relies on a region starting it's turn will never fire off if placed inside the OnFactionTurnStart function, as the faction and the region both start their turns at different times.
Getting the game to write logs is by far the easiest way of narrowing down bugs and telling you that certain things are working in a script. The following code chunks are functions for (i) Creating a log and (ii) Writing to the log. To understand some of the operators used, I would advise you to look at the basics section (I.1) which explains them in detail.
Spoiler Alert, click show to read:
Code:
function TCS_Create_Log ()
local DateAndTime = os.date()
local TCSLog = io.open("data/Logs/log.txt","w")
TCSLog:write("[Log Created] "..DateAndTime.."\n\n")
TCSLog:close()
end
Code:
function TCS_Log_Update(update_arg)
local DateAndTime1 = os.date("%H:%M.%S")
local TCSLogU = io.open("data/Logs/log.txt","a")
TCSLogU:write("\n["..DateAndTime1.."]\t\t"..tostring(update_arg))
TCSLogU:close()
end
These functions may not make sense to anyone unfamiliar with Lua, so I've included some with comments below.
Spoiler Alert, click show to read:
Code:
--create a function that takes no arguments
function TCS_Create_Log ()
--sets a variable to the time and date
local DateAndTime = os.date()
--opens the text file in the directory supplied. Set to write mode ("w"), so if the text file
--exists it will be overwritten, if it doesn't it will be created.
local TCSLog = io.open("data/Logs/log.txt","w")
--write a header tith the date to the log, so you know when it's been updated.
TCSLog:write("[Log Created] "..DateAndTime.."\n\n")
--Close the log
TCSLog:close()
end
Code:
--create a function that takes only one argument
function TCS_Log_Update(update_arg)
--set the date in HMS format to the variable
local DateAndTime1 = os.date("%H:%M.%S")
--open the log in the supplied path. Opened in append mode ("a") which will append to
--the file rather than overwrite it
local TCSLogU = io.open("data/Logs/log.txt","a")
--write the date in HMS format before each log entry
TCSLogU:write("\n["..DateAndTime1.."]\t\t"..tostring(update_arg))
--close the log
TCSLogU:close()
end
Usage of the functions:
The functions must both be defined, so I'd advise you to do that at the top of your script. Remember that scripts are read logically (mostly) so you must define the function before attempting to call it. I would then advise that you call the function to create the log only once, as it overwrites any logs that already exist. So it is done as follows:
Code:
TCS_Create_Log ()
Then you can use the log updater as often as you wish. Here is an example of basic usage:
Code:
TCS_Log_Update("hello World!")
Which will output the following to the log file:
Code:
[12:46.13] Hello World!
If you supply an argument to the function that doesn't exist, it will most likely catch it out as it uses the tostring() converter.
So this code:
Code:
TCS_Log_Update(hello World!)
Outputs this:
Code:
[12:46.13] nil
Keep in mind that I've left out the error catching I would use on my own logging functions so as to keep the code simple - it may not handle all incorrect syntax values the same.
Another excellent use of this is to log the output of functions. The following code logs the output of a CampaignUI function.
Code:
local Logvariable = CampaignUI.RetrieveDiplomaticStanceString("france", "britain")
TCS_Log_Update(Logvariable)
To edit UI components the most effective way is to get a decompiled file, fix it, edit it and recompile it. This obviously isn't an option for most people, so what follows is a basic example of how to do it via scripting.lua and episodicscripting.
First things first, you need to know the name of your component to edit. There's no simple way to do this, you just have to crawl through game files and find somewhere else where it is referenced globally (i.e. not locally). When you know the name of your component to edit, you need to add an entry to the table m_features table of episodicscripting. This is done by adding some code as follows to the end of the table:
And here it is with some comments to make it easier to understand:
Code:
--set the feature name
["disable_end_turn"] = {
--define the enable function
["Enable"] = function()
--code that will be executed when the enable function is called
out.ting("End turn disabled")
UIComponent(m_root:Find("button_end_turn")):SetVisible(false)
UIComponent(m_root:Find("button_end_turn")):SetDisabled(true)
end,
--define the disable function
["Disable"] = function()
--code that will be executed when the disable func is called
out.ting("End turn re-enabled")
UIComponent(m_root:Find("button_end_turn")):SetVisible(true)
UIComponent(m_root:Find("button_end_turn")):SetDisabled(false)
end
},
To actually edit the UI components you need to use the UIComponent() function. This is documented as follows:
Code:
UIComponent(m_root:Find(<<Name of component>>)):<<function to call on component>>
I've only seen SetDisabled or SetVisible used in episodicscripting but here are other commands used in luacs:
SetStateText(<<string>>)
SetState(<<string>>) (Only useable if you can compare to UI xmls)
SetTooltipText(<<string>>)
There are lots more, but those are the most relevant.
So now you've added your feature to the table, you'll need to call it. That's pretty simple to do - from scripting.lua (or anywhere else where the episodicscripting module is loaded) just use the following code:
Saving the game
Note: this is for my own reference, if you don't understand it don't bother
For saving, three types should be distinguished:
- Save via the save-load dialog
- Autosave
- Quicksave via shortcut
If you need a savegame list, the savegame will be missing during save - that's a way to know the filename of the game that was just saved. Unfortunately we then need an event that we can use after saving and that can be enabled by a bool flag.
For the saving via save-load, use PanelOpenedCampaign, if you want with context.string == dialogue_box (this is called by the "Save successful" dialog).
For saving via auto-save, use FactionTurnEnd or somesuch
For saving via quicksave we can get a problem if the player hits alt+f4 so we need to use FactionTurnEnd along with the auto-save and UIDestroyed
Here is a link to a resource with all of NTW's conditions, effects and other functions.
I've built a usable function to check against a region's name (usable in that it doesn't require a pointer or address). It may be of use to those of you who have noticed there is no "RegionName()" condition, or anything much like it available.
Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell
Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell
Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell
Perhaps i'll apply event and unit spawn/uprising scripting some day in future.
Thanks
If anyone has any questions or wants functions documented, shout here. I'll do my best to help. And if anyone wants to know how to start documenting functions, get in contact with me - I can show people how to use pcall() (for getting info on funcs) if they are interested
Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell
Great work taking all the time to post your knowledge but I think there is something missing in the "Basic" section like:
1. What file(s) are you manipulating
2. Where do you type the scripts inside the file? Is it a table that you add to the last blank line? Pics would be nice.
Great work taking all the time to post your knowledge but I think there is something missing in the "Basic" section like:
1. What file(s) are you manipulating
2. Where do you type the scripts inside the file? Is it a table that you add to the last blank line? Pics would be nice.
Thanks
1. The scripting.lua
2. Inside the desired function/event. I don't really have time to write an "introduction to scripting" tutorial right now. I suggest you Google Garry's Mod lua tutorials, they are very beginner friendly and will teach you some basics about scripting - enough to see what is going on inside scripting.lua.
Edit: Here you go. You'll just have to apply practical sense to pick out the bits relevant to Garrys Mod.
Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell
So, I would like to track the population of a certain town... Or the populations of all towns that belong to a specific clan (STW2). Any ideas?
Is there a list of Character/Town etc. details/tags/parameters that has been published by CA? Something similar in NTW?
Thanks for the replies
I don't know your level of competency with Lua, but here is a function I use in EiC for manpower calculations.
Code:
function FindTotalPopulation(faction)
local regions = CampaignUI.RegionsOwnedByFactionOrByProtectorates(faction)
local population = 0
for i = 1, #regions do
local Region_details = CampaignUI.InitialiseRegionInfoDetails(regions[i].Address)
local Region_population = Region_details["PopulationNumber"]
population = population + Region_population
end
return population
end
You can see how I've queried that information from the tables by looking at the function output documented in my OP (InitialiseRegionInfoDetails() and RegionsOwnedByFactionOrByProtectorates())
Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell
Alright, so you call the 'properties/variables' within quotations.
So, if I wanted to get the information on effect of ports on town wealth for example;
-- Initialize the object A
local A = CampaignUI.InitialiseRegionInfoDetails(region.Address)
local B = A["TownWealth"]
- now since B is a table
local C = B[1]
- one corresponding to first table in TownWealth table
local D = C[1] -- the actual value for the wealth from town
Am I right?
And could you please tell where we should place this script function for the program to check it all the time? If I use an event function that fires, can I do it in any script file, or do I use my own script file or what?
Your answer was very helpful, thank you!
Edit: Can we do the above in one sentence, so that
local A = CampaignUI.InitialiseRegionInfoDetails(region.Address)["TownWealth"][1][1]
or something similar?
Last edited by Seikales; May 23, 2011 at 01:30 PM.
Do you know if they have functions other then the effects you mentioned above? Can I for example, following the discussion above, change the population of a city?
Alright, so you call the 'properties/variables' within quotations.
So, if I wanted to get the information on effect of ports on town wealth for example;
-- Initialize the object A
local A = CampaignUI.InitialiseRegionInfoDetails(region.Address)
local B = A["TownWealth"]
- now since B is a table
local C = B[1]
- one corresponding to first table in TownWealth table
local D = C[1] -- the actual value for the wealth from town
Am I right?
And could you please tell where we should place this script function for the program to check it all the time? If I use an event function that fires, can I do it in any script file, or do I use my own script file or what?
Your answer was very helpful, thank you!
Edit: Can we do the above in one sentence, so that
local A = CampaignUI.InitialiseRegionInfoDetails(region.Address)["TownWealth"][1][1]
or something similar?
Your on your way there for sure.
First thing I'd say is don't use variables like "A" and "B", you will lose track of them and what they are, name them appropriatly.
For your script, you pretty much wrote it almost.
local A = CampaignUI.InitialiseRegionInfoDetails(region.Address)
"A" now holds the details of the region.
local B = A["TownWealth"]
"B" now holds the TownWealth details of "A", "A" being the region. B isn't a table like you suggested, its just a plain old variable.
You don't need any of the B = C = D extra stuff.
Now B has the town wealth of the region you can do whatever you want. If you need more help just ask.
As for doing it in one line, the correct syntax could be:
local A = (CampaignUI.InitialiseRegionInfoDetails(region.Address))["TownWealth"]
But you'd need to place the CampaignUI bit within some operators, and I don't know the standard operators for LUA. In Visual Basic you'd place the campaignUI bit within () to make sure that it does that first then it will apply the TownWealth bit to the variable in the brackets, tbh, its easier just to do another line.
Alright, so you call the 'properties/variables' within quotations.
No, in that case the table key was a string rather than a number.
Originally Posted by .Mitch.
As for doing it in one line, the correct syntax could be:
local A = (CampaignUI.InitialiseRegionInfoDetails(region.Address))["TownWealth"]
I see what you both are trying to do, but I think you've both flown a little wide of the mark. For syntax safety reasons I'd store the return value (a table in this case) in a variable - if nothing else it's easier on the eye. Once you have it in a variable, say RegionDetails, you can cut out as many lines as you like :
Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell
Thanks for the answers people. Yeah, I use A and B here for simplicity of discussion. Sound advice on your part though Mitch.
Would you have any answers on the questions below?
And could you please tell where we should place this script function for the program to check it all the time? If I use an event function that fires, can I do it in any script file, or do I use my own script file or what?
Do you know if they have functions other then the effects you mentioned above? Can I for example, following the discussion above, change the population of a city?
Thanks for the answers people. Yeah, I use A and B here for simplicity of discussion. Sound advice on your part though Mitch.
Would you have any answers on the questions below?
Cheers
@Question 1 - it depends what you want to do, you could tie it into an event such as OnPanelOpenedCampaign or something like that, but that's liable to cause lag if the script is large.
@Question 2 - that's about the most interesting stuff. There's more stuff in CUI but I haven't documented it here yet.
Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell
For your question 1: The 'On Turn Start' event would be the best, thats the event in which townwealth will have changed for the player or the AI, it will remain a constant throughout the turn, so using the panels like topcat suggested is being overly complicated for this imo.
So you'd be looking to use:
local function OnFactionTurnStart(context)
your script here
end
Alright. So, I place this at any script file? Or the campaign one? Or the events one? Does it really matter? I assume they all get regularly checked out whether any of them fire or no?
Or do they get stored in some memory and tracked all the time? I guess what I am asking is, when an event is fired, the program will go read all the script files for the proper action, or just look at the events script file?
Man, even I lost track of my thought. Kinda tired. Need to prepare a large poster for a conference Cheers!