You're welcome. Always happy to help those who appreciate it.
I forgot to mention this...
You're saying that rangers
are recruitable until
all of those resources are too low. Should it not be: recruitable until
at least one resource is too low?
Also, your script wasn't handling the case of iron being between 30,000 and 35,000.
Yes, I would be worried about that too.
Six (resource) duplicates is not so bad but [6 x faction_count] duplicates is 78 in vanilla. Personally I would probably not attempt it for AI factions, for that reason, not to mention that no xxxSelected events can be used for the AI.
You could do it with script like that but a major problem is that "this" can only be used with CharacterSelected which doesn't fire when the character is inside anything (settlement, fort, ship, another's army). So the traits won't refresh until the leader is outside.
Your stock levels are adjusted by end-of-turn things so using CharacterTurnStart instead would do the trick. i.e. The traits only need refreshing once per turn anyway, at the start of a new turn. As "this" can't be used with CharacterTurnStart, and we don't know his name either, the only solution is to use trait triggers for giving him and refreshing his traits ... not script.
Counters can't be used with trait/anc triggers but
event counters can. So the "available" counters will need to be changed into event counters. Or, keep them as counters and use them to set some new event counters which in turn are used by the triggers.
And if script needs to adjust the "available" counters in any way (e.g. increasing them) and those changes need to be reflected in the traits this turn then make sure it is done before CharacterTurnStart, i.e. in
PreFactionTurnStart.
Example...
For Iron and Wood. I'm only showing for the cases of 48, 72, 96, 30000 and "maxed" (above 30000), with "..." or "...others..." where the other levels need to be added.
Code:
;============= Iron Resource ==============
;------------------------------------------
Trait Iron_00048
Characters family
Level Iron_00048
Description Iron_00048_desc
EffectsDescription Iron_00048_effects_desc
Threshold 1
;------------------------------------------
Trait Iron_00072
Characters family
Level Iron_00072
Description Iron_00072_desc
EffectsDescription Iron_00072_effects_desc
Threshold 1
;------------------------------------------
Trait Iron_00096
Characters family
Level Iron_00096
Description Iron_00096_desc
EffectsDescription Iron_00096_effects_desc
Threshold 1
;------------------------------------------
;...others...
;------------------------------------------
Trait Iron_30000
Characters family
Level Iron_30000
Description Iron_30000_desc
EffectsDescription Iron_30000_effects_desc
Threshold 1
;------------------------------------------
Trait Iron_maxed
Characters family
Level Iron_maxed
Description Iron_maxed_desc
EffectsDescription Iron_maxed_effects_desc
Threshold 1
;============= Wood Resource ==============
;------------------------------------------
Trait Wood_00048
Characters family
Level Wood_00048
Description Wood_00048_desc
EffectsDescription Wood_00048_effects_desc
Threshold 1
;------------------------------------------
Trait Wood_00072
Characters family
Level Wood_00072
Description Wood_00072_desc
EffectsDescription Wood_00072_effects_desc
Threshold 1
;------------------------------------------
Trait Wood_00096
Characters family
Level Wood_00096
Description Wood_00096_desc
EffectsDescription Wood_00096_effects_desc
Threshold 1
;------------------------------------------
;...others...
;------------------------------------------
Trait Wood_30000
Characters family
Level Wood_30000
Description Wood_30000_desc
EffectsDescription Wood_30000_effects_desc
Threshold 1
;------------------------------------------
Trait Wood_maxed
Characters family
Level Wood_maxed
Description Wood_maxed_desc
EffectsDescription Wood_maxed_effects_desc
Threshold 1
;==========================================
;============= Triggers ===================
;==========================================
;------------------------------------------
Trigger Resources_clear_all_trigger
WhenToTest CharacterTurnStart
Condition IsFactionLeader
and FactionIsLocal
;remove all resource traits
Affects Iron_00048 -1 Chance 100
Affects Iron_00072 -1 Chance 100
Affects Iron_00096 -1 Chance 100
;...
Affects Iron_30000 -1 Chance 100
Affects Iron_maxed -1 Chance 100
Affects Wood_00048 -1 Chance 100
Affects Wood_00072 -1 Chance 100
Affects Wood_00096 -1 Chance 100
;...
Affects Wood_30000 -1 Chance 100
Affects Wood_maxed -1 Chance 100
;============= Iron Resource ==============
;------------------------------------------
Trigger Iron_00048_trigger
WhenToTest CharacterTurnStart
Condition IsFactionLeader
and FactionIsLocal
and I_EventCounter iron_level = 48
Affects Iron_00048 1 Chance 100
;------------------------------------------
Trigger Iron_00072_trigger
WhenToTest CharacterTurnStart
Condition IsFactionLeader
and FactionIsLocal
and I_EventCounter iron_level = 72
Affects Iron_00072 1 Chance 100
;------------------------------------------
Trigger Iron_00096_trigger
WhenToTest CharacterTurnStart
Condition IsFactionLeader
and FactionIsLocal
and I_EventCounter iron_level = 96
Affects Iron_00096 1 Chance 100
;------------------------------------------
;...others...
;------------------------------------------
Trigger Iron_30000_trigger
WhenToTest CharacterTurnStart
Condition IsFactionLeader
and FactionIsLocal
and I_EventCounter iron_level = 30000
Affects Iron_30000 1 Chance 100
;------------------------------------------
Trigger Iron_maxed_trigger
WhenToTest CharacterTurnStart
Condition IsFactionLeader
and FactionIsLocal
and I_EventCounter iron_level = 99999
Affects Iron_maxed 1 Chance 100
;============= Wood Resource ==============
;------------------------------------------
Trigger Wood_00048_trigger
WhenToTest CharacterTurnStart
Condition IsFactionLeader
and FactionIsLocal
and I_EventCounter wood_level = 48
Affects Wood_00048 1 Chance 100
;------------------------------------------
Trigger Wood_00072_trigger
WhenToTest CharacterTurnStart
Condition IsFactionLeader
and FactionIsLocal
and I_EventCounter wood_level = 72
Affects Wood_00072 1 Chance 100
;------------------------------------------
Trigger Wood_00096_trigger
WhenToTest CharacterTurnStart
Condition IsFactionLeader
and FactionIsLocal
and I_EventCounter wood_level = 96
Affects Wood_00096 1 Chance 100
;------------------------------------------
;...others...
;------------------------------------------
Trigger Wood_30000_trigger
WhenToTest CharacterTurnStart
Condition IsFactionLeader
and FactionIsLocal
and I_EventCounter wood_level = 30000
Affects Wood_30000 1 Chance 100
;------------------------------------------
Trigger Wood_maxed_trigger
WhenToTest CharacterTurnStart
Condition IsFactionLeader
and FactionIsLocal
and I_EventCounter wood_level = 99999
Affects Wood_maxed 1 Chance 100
Script:
Code:
monitor_event PreFactionTurnStart FactionIsLocal
;default to "maxed"
set_event_counter iron_level 99999
set_event_counter wood_level 99999
;iron...
if I_CompareCounter iron_available < 30000
set_event_counter iron_level 30000
end_if
;...others...
if I_CompareCounter iron_available < 96
set_event_counter iron_level 96
end_if
if I_CompareCounter iron_available < 72
set_event_counter iron_level 72
end_if
if I_CompareCounter iron_available < 48
set_event_counter iron_level 48
end_if
;wood...
if I_CompareCounter wood_available < 30000
set_event_counter wood_level 30000
end_if
;...others...
if I_CompareCounter wood_available < 96
set_event_counter wood_level 96
end_if
if I_CompareCounter wood_available < 72
set_event_counter wood_level 72
end_if
if I_CompareCounter wood_available < 48
set_event_counter wood_level 48
end_if
end_monitor
The first trait trigger removes all resource traits from the leader, by subtracting 1 from every trait to bring it back to 0 (and therefore hidden). Most will already be 0 anyway but that's okay: trait values never go below 0, so using -1 on a trait that is currently 0 will not make it -1; it will stay at 0. A very handy shortcut.
The script sets an event counter (e.g. iron_level) based on what the "available" counter is. e.g. "iron_level = 48" represents "iron_available < 48", and that is how the triggers interpret it. 99999 represents "maxed" (>=30000).
Alternatively you could make the "available" counters
event counters instead (as I said before) and use them directly in the triggers:
Code:
;------------------------------------------
Trigger Iron_00072_trigger
WhenToTest CharacterTurnStart
Condition IsFactionLeader
and FactionIsLocal
and I_EventCounter iron_available >= 48
and I_EventCounter iron_available < 72
Affects Iron_00072 1 Chance 100
It's probably easier to follow that way. But if you were to use this for multiple factions at once (i.e. the AI as well, or hotseat) then my way is better because all of those trait triggers can be used for all factions; no need to duplicate for each faction (the script will need to be, though).
Notice in the script I only did this...
Code:
if I_CompareCounter wood_available < 72
set_event_counter wood_level 72
end_if
...not this...
Code:
if I_CompareCounter wood_available < 72
and I_CompareCounter wood_available >= 48
set_event_counter wood_level 72
end_if
...and that I put the IFs in descending order (30000 at the top, 48 at the bottom). It's just another shortcut to reduce script length. I can explain further if necessary.
For trait names I used e.g. Iron_00072 instead of Iron_72. It doesn't need to be that way.
EDIT: one flaw: if your leader dies in your own turn (i.e. in a battle) then the new leader won't have the traits until next turn so you'll be in the dark until then. Also, if the leader was ever sent off map then naturally you won't have this resource info at all until he comes back. I don't think that happens in TATW and no idea how common it is in submods but in DCI: Last Alliance it is possible to have an off-map leader.
Actually, there's no need to limit this to just the leader. You could remove the IsFactionLeader condition from the triggers; every general would have the info then, though I wonder if that might add some end of turn lag. Or you could give it to just diplomats, for example.