Results 1 to 20 of 20

Thread: script question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default script question

    i have a question on how to:

    make and event_counter trigger another counter but i am very confuse at the moment , so maybe some bright mind can help me out:

    Spoiler Alert, click show to read: 
    Code:
    monitor_event SettlementTurnEnd SettlementIsLocal
        and SettlementBuildingExists = farms
        and SettlementTaxLevel >= tax_high
                inc_counter timber 50
                inc_counter grain 15
                inc_counter cattle 5
        if I_EventCounter stockready_food = 1
            if I_LocalFaction jerusalem
                inc_counter timber 200
                inc_counter grain 100
                inc_counter cattle 50
                add_money jerusalem -500
            end_if
         if I_EventCounter stockready_food = 0
            if I_LocalFaction jerusalem
                inc_counter timber 100
                inc_counter grain 50
                inc_counter cattle 20
                add_money jerusalem -250
            end_if
    end_if
    end_monitor

    what i am looking for is to make the farm to inc_counter (timber, grain, cattle) straight after being build, but to increase the production after the event_counter required has been triggered and and to also increase with tax levels. i know that this script will only add inc_counter (timber, grain, cattle) with tax level high, but can you suggest me another script idea?

    EDITED:
    i have set up another possible way, but i really want the possibility of adding money and removing money to control the brothel and upgrades increase and decrease production: think of as if, less tax more lost more tax less lost.
    Spoiler Alert, click show to read: 
    Code:
    monitor_event SettlementTurnStart SettlementIsLocal
    and SettlementBuildingExists >= brothel     
    and SettlementTaxLevel >= tax_high 
    inc_counter ale 30    
    set_event_counter stock_ale 1         
    set_event_counter stock_ale1 1        
     set_event_counter stock_ale2 1        
     set_event_counter stock_ale3 1 
    end_monitor 
    monitor_event SettlementTurnStart SettlementIsLocal     
    and SettlementBuildingExists >= brothel     
    and SettlementTaxLevel <= tax_normal        
     set_event_counter stock_ale 0        
     set_event_counter stock_ale1 0        
     set_event_counter stock_ale2 0         
    set_event_counter stock_ale3 0         
    inc_counter ale -30 ; less due to higher demand but low cost.
    end_monitor 
    monitor_event SettlementTurnEnd SettlementIsLocal    
     and SettlementBuildingExists = brothel     
     if I_EventCounter stock_ale = 1             
    inc_counter ale 20    
     end_if    
     if I_EventCounter stock_ale = 0            
     inc_counter ale 1     
    end_if 
    end_monitor 
    monitor_event SettlementTurnEnd SettlementIsLocal     
    and SettlementBuildingExists = inn    
     if I_EventCounter stock_ale1 = 1             
    inc_counter ale 30     
    end_if    
     if I_EventCounter stock_ale1 = 0             
    inc_counter ale 1    
     end_if 
    end_monitor


    any input is appreciated.
    Last edited by Icedie El Guaraní; August 01, 2012 at 06:27 PM.
    Contribuitor IBIICB-WOTN-Modeler-Scripter


  2. #2
    TMK's Avatar BC Local Moderator
    Join Date
    Jun 2010
    Location
    England
    Posts
    1,606

    Default Re: script question

    Double If statements? Do they work?




  3. #3
    Aikanár's Avatar no vaseline
    Join Date
    Mar 2009
    Location
    Sanctuary
    Posts
    12,516
    Blog Entries
    3

    Default Re: script question

    Yes, you can include if statements into if statements, same goes out for while, but in each case you've to close all those statements before ending the monitor which the first script example clearly is missing.

    Concerning the OP:
    Code:
    monitor_event SettlementTurnEnd SettlementIsLocal
        and SettlementBuildingExists = farms
        and SettlementTaxLevel >= tax_high
                inc_counter timber 50
                inc_counter grain 15
                inc_counter cattle 5
        if I_EventCounter stockready_food = 1
            if I_LocalFaction jerusalem ;you only need this if, if you want to have other factions included in this script as well
                inc_counter timber 200
                inc_counter grain 100
                inc_counter cattle 50
                add_money jerusalem -500
            end_if
         end_if ; this was missing, take care of closing all statements.
         if I_EventCounter stockready_food = 0
            if I_LocalFaction jerusalem ; see above, if you only want to have this for this one faction, use "and" instead of "if"
                inc_counter timber 100
                inc_counter grain 50
                inc_counter cattle 20
                add_money jerusalem -250
            end_if
    end_if
    end_monitor
    Last edited by Aikanár; August 01, 2012 at 03:53 PM.


    Son of Louis Lux, brother of MaxMazi, father of Squeaks, Makrell, Kaiser Leonidas, Iskar, Neadal, Sheridan, Bercor and HigoChumbo, house of Siblesz

    Not everything that counts can be counted, and not everything that can be counted counts.

  4. #4

    Default Re: script question

    Quote Originally Posted by Aikanár View Post
    Yes, you can include if statements into if statements, same goes out for while, but in each case you've to close all those statements before ending the monitor which the first script example clearly is missing.

    Concerning the OP:
    Code:
    monitor_event SettlementTurnEnd SettlementIsLocal
        and SettlementBuildingExists = farms
        and SettlementTaxLevel >= tax_high
                inc_counter timber 50
                inc_counter grain 15 ( are these counters being triggered always with out the if I_EventCounter? and added to the total amount added by the if I_EventCounter?
                inc_counter cattle 5
        if I_EventCounter stockready_food = 1
            if I_LocalFaction jerusalem ;you only need this if, if you want to have other factions included in this script as well
                inc_counter timber 200
                inc_counter grain 100
                inc_counter cattle 50
                add_money jerusalem -500
            end_if
         end_if ; this was missing, take care of closing all statements.
         if I_EventCounter stockready_food = 0
            if I_LocalFaction jerusalem ; see above, if you only want to have this for this one faction, use "and" instead of "if"
                inc_counter timber 100
                inc_counter grain 50
                inc_counter cattle 20
                add_money jerusalem -250
            end_if
    end_if
    end_monitor
    thanks for that, and yes i am using this script for all the crusader´s playable factions.
    concerning the second script:
    Code:
    if I_EventCounter stockready_food = 0        
     if I_LocalFaction jerusalem             
    inc_counter timber 100            
     inc_counter grain 50             
    inc_counter cattle 20             
    add_money jerusalem -250         
    end_if         
    end_if
    this part of the script is the one that confuses me the most; SettlementTurnStart : and include
    Code:
    and SettlementTaxLevel >= tax_high
    and add the if I_LocalFaction jerusalem( and the other 4 factions )
    Code:
    monitor_event SettlementTurnEnd SettlementIsLocal      
    and SettlementBuildingExists = brothel       
    if I_EventCounter stock_ale = 1              
    inc_counter ale 20      
    end_if      
    if I_EventCounter stock_ale = 0              
    inc_counter ale 1      
    end_if  
    end_monitor
    so that the end result is
    Code:
    monitor_event SettlementTurnStart SettlementIsLocal
    
    and SettlementBuildingExists >= brothel ( will the >= logic token will see from brothel to all the other upgrades? does it work? )
    
    and SettlementTaxLevel >= tax_high
    
     set_event_counter stock_ale 1
     set_event_counter stock_ale1 1
     set_event_counter stock_ale2 1
     set_event_counter stock_ale3 1
    end_monitor
    Code:
    monitor_event SettlementTurnEnds SettlementIsLocal
    and SettlementBuildingExists = brothel ( and this way i set different upgrades names and each will increase the resource under the if statement)
    if I_EventCounter stock_ale = 1         
     if I_LocalFaction jerusalem   ( and yes i have the if statement because i use it in other factions, same goes for when the event_counter is set to = 0, to decrease resources )          
     inc_counter timber 100              
    inc_counter grain 50              
    inc_counter cattle 20             
     add_money jerusalem -250          
    end_if          
    end_if
    end_monitor
    can a inc_counter have an and statement under and above of it?
    like for instance :
    monitor_event SettlementTurnEnds SettlementIsLocal
    inc_counter xxxx 100
    and SettlementBuildingExists = brothel
    if I_EventCounter stock_ale = 1
    inc_counter xxxx 200
    end_if
    end_monitor ?
    any missleading typos is pure accident, they will be spotted eventually.

    thanks for any feed backs...rep granted
    Last edited by Icedie El Guaraní; August 01, 2012 at 06:24 PM.
    Contribuitor IBIICB-WOTN-Modeler-Scripter


  5. #5
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: script question

    Quote Originally Posted by Icedie El Guaraní View Post
    can a inc_counter have an and statement under and above of it?
    like for instance :
    monitor_event SettlementTurnEnds SettlementIsLocal
    inc_counter xxxx 100
    and SettlementBuildingExists = brothel
    if I_EventCounter stock_ale = 1
    inc_counter xxxx 200
    end_if
    end_monitor
    No. All conditions must be together: you can't put the red one there.

    The format must be:
    Code:
    monitor_event {event type} {condition1}
      and {condition2}
      and {condition3}
      and ...
    
      {body}
    
    end_monitor
    (The blue ones are optional but you must have at least one condition.)

    {body} is where the commands go. Within that you can also use - with IFs or WHILEs - any conditions that don't have any trigger requirements. These are mostly the I_xxx conditions but there are a couple of others such as RandomPercent.

    And yes, ">= brothel" means a brothel or any other building higher than it on that building tree. So this is equivalent to saying "brothel OR inn OR tavern OR ... and so on"

    If you want different counter amounts for different building levels then you could do something like this...

    Code:
    monitor_event SettlementTurnEnds SettlementIsLocal
      and SettlementBuildingExists = brothel
      
      inc_counter ale 100
    end_monitor
    
    monitor_event SettlementTurnEnds SettlementIsLocal
      and SettlementBuildingExists = inn
      
      inc_counter ale 200
    end_monitor
    
    monitor_event SettlementTurnEnds SettlementIsLocal
      and SettlementBuildingExists = tavern
      
      inc_counter ale 300
    end_monitor
    
    monitor_event SettlementTurnEnds SettlementIsLocal
      and SettlementBuildingExists = coaching_house
      
      inc_counter ale 400
    end_monitor
    
    monitor_event SettlementTurnEnds SettlementIsLocal
      and SettlementBuildingExists = pleasure_palace
      
      inc_counter ale 500
    end_monitor
    
    monitor_event SettlementTurnEnds SettlementIsLocal
      and SettlementBuildingExists >= brothel
      
      ;this settlement has a brothel or higher...
      
      ;the rest of the script, now that "ale" has been set according to the tavern level
      
    end_monitor
    I'm not sure I understand how you're going to use this though. I take it that the event counters will be used in EDB? So you're trying to sum up the total "ale" across the entire faction or just per settlement? Because you can't do per-settlement stuff in the EDB like that: event counters are faction wide.

    Also, you might have already done so but I couldn't see it, at some point you would need to reset the "ale" counter back to zero. e.g. At faction turn start. Otherwise inc_counter will just keep adding onto the value every turn.

  6. #6

    Default Re: script question

    No. All conditions must be together:
    Yeah I thought so
    And yes, ">= brothel" means a brothel or any other building higher than it on that building tree
    sweet, this means my script has to work.

    I'm not sure I understand how you're going to use this though
    yeah i get that a lot, i not good at explaining in english, i ´ll try my best.

    this is part of the VLL version of the trade and supply script, currently a dead mod, but i am making my own version of it with what was left of it for the crusade campaign, so little has been done for that campaign if you ask me, but currently the T&S mod is Tsarsies mod, this is a non related version to that one, he implements the t&S mod with population control, money script and other very unique stuff, which to be honest are far from my understanding, he is a pro and a good tutor.

    coming back to topic; the brothel needs to be able to produce more ale when tax_is high because the idea is that when tax is high, the population has little money left to expend in beverages so the brothel has many in stock, that stock of ale is intended for a much larger purpose, combine with other stock(timber, stone, iron, cattle, fish etc) the I_Faction will be able to train units , agents, and buildings.
    it work in a different way for farm, roads, markets and sea trade, it has its own event_counter within the EDB and is triggered by the amount of those resources, so the brothel is the only one that is affected so far by tax level. keep in mind i have 5 factions to code, and so far i only got 7k lines of code working properly but needs balancing, that is left for when is ready for beta testing.
    So you're trying to sum up the total "ale" across the entire faction
    yes i couldn´t find a way around it to make it as per settlement, so it has to be as faction wide.

    coming back to the brothel script, so i have it set up this way, the script fires, but i am not sure if is properly set:
    event_counter stock_ale 1, 2 3 in EDB to provide happiness bonuses. and they are triggered by tax level at TurnStart(here is where i am not sure if i have implemented the TurnStart/TurnEnds Event correctly):
    Code:
    monitor_event SettlementTurnStart SettlementIsLocal
        and SettlementBuildingExists >= brothel
        and SettlementTaxLevel >= tax_high
            set_event_counter stock_ale 1
            set_event_counter stock_ale1 1
            set_event_counter stock_ale2 1
            set_event_counter stock_ale3 1
    end_monitor
    monitor_event SettlementTurnStart SettlementIsLocal
        and SettlementBuildingExists >= brothel
        and SettlementTaxLevel <= tax_normal
            set_event_counter stock_ale 0
            set_event_counter stock_ale1 0
            set_event_counter stock_ale2 0
            set_event_counter stock_ale3 0
            inc_counter ale -30
    end_monitor
    than they are the codes for TurnEnd:
    Code:
    monitor_event SettlementTurnEnd SettlementIsLocal
        and SettlementBuildingExists = brothel
        if I_EventCounter stock_ale = 1
            if I_LocalFaction jerusalem
                inc_counter ale 100
                add_money jerusalem -100 ( the brothel is not giving me free ale barrels , i am buying to keep population happy) 
            end_if
            if I_LocalFaction antioch
                inc_counter ale 100
                add_money antioch -100
            end_if
            if I_LocalFaction byzantium
                inc_counter ale 100
                add_money byzantium -100
            end_if
            if I_LocalFaction turks
                inc_counter ale 100
                add_money turks -100
            end_if
            if I_LocalFaction egypt
                inc_counter ale 100
                add_money egypt -100
            end_if
        end_if
        if I_EventCounter stock_ale = 0
            if I_LocalFaction jerusalem
                inc_counter ale -10
                add_money jerusalem -10
            end_if
            if I_LocalFaction antioch
                inc_counter ale -10
                add_money antioch -10
            end_if
            if I_LocalFaction byzantium
                inc_counter ale -10
                add_money byzantium -10
            end_if
            if I_LocalFaction turks
                inc_counter ale -10
                add_money turks -10
            end_if
            if I_LocalFaction egypt
                inc_counter ale -10
                add_money egypt -10
            end_if
        end_if
    end_monitor
    and lastly
    at some point you would need to reset the "ale" counter back to zero
    yes i have a script that checks the resources amount for each resource and is available to the player by hitting the settlement help button, it triggers an historic event that let the player know if it has > than xxx and i have set it up up to >= than 900 and has a monitor that prevents this to go over 1000, and its stays in 1000 if they are not being spend. but another question pops up there:
    should i use here the PreFactionTurnStart monitor for this?

    am i explaining myself?
    thanks.
    Last edited by Icedie El Guaraní; August 02, 2012 at 07:52 AM.
    Contribuitor IBIICB-WOTN-Modeler-Scripter


  7. #7
    Aikanár's Avatar no vaseline
    Join Date
    Mar 2009
    Location
    Sanctuary
    Posts
    12,516
    Blog Entries
    3

    Default Re: script question

    Concerning the PreFactionTurnStart, that depends on what you want to do after your script has fired.
    If you want to set up a chain of scripts firing in the same turn, dependend on eachother without the use of monitor_conditions -which I suggest to avoid as the plage as often as you can- then it could very well be usefull to start the initial script in the PreFactionTurnStart phase enabling you to start another in the FactionTurnStart and then another in the SettlementTurnStart.

    It all comes down to what you want to achieve.


    Son of Louis Lux, brother of MaxMazi, father of Squeaks, Makrell, Kaiser Leonidas, Iskar, Neadal, Sheridan, Bercor and HigoChumbo, house of Siblesz

    Not everything that counts can be counted, and not everything that can be counted counts.

  8. #8

    Default Re: script question

    PreFactionTurnStart; basically what i need to know for sure is , if are there any rules that makes the following irrelevant? for instance:
    is it better to prepare a counter that will fire another group of counters at PreFactionTurnStart? and what is exactly PreFactionTurnStart that makes it different than FactionTurnStart, what happens at "Pre"?
    see this code:
    Code:
    monitor_event PreFactionTurnStart FactionIsLocal
            if I_CompareCounter jewl < 80
                set_counter jewlstockFood_available 0
            end_if                    Counters being prepare to fire another group of counters.
            if I_CompareCounter jewl >= 80
                set_counter jewlstockFood_available 1
            end_if
    end_monitor
    Code:
    monitor_event PreFactionTurnStart FactionIsLocal
                if I_CompareCounter jewlstockFood_available = 0
                set_counter stockJewl_available 0
              end_if
    Is it the same if i set up in this event FactionTurnStart? or is it has to be FactionTurnStart only after the first PreFactionTurnStart event?

    and finally the counter that needs to be met in EDB to trigger recruitment.
    Code:
    monitor_event ButtonPressed ButtonPressed recruitment_button
            if I_CompareCounter stockJewl_available = 0
                set_event_counter AgentAvailable 0
            end_if
            if I_CompareCounter stockJewl_available = 1
                set_event_counter AgentAvailable 1
            end_if
    end_monitor
    I have prepare another event that allows AI to have all event-counters in EDB set to 1 at FactionTurnEnd FactionIsLocal.

    ah another thing, what is the difference between = and == : if I_CompareCounter stockJewl_available == 1 or if I_CompareCounter stockJewl_available = 1?
    Last edited by Icedie El Guaraní; August 02, 2012 at 02:24 PM.
    Contribuitor IBIICB-WOTN-Modeler-Scripter


  9. #9
    Aikanár's Avatar no vaseline
    Join Date
    Mar 2009
    Location
    Sanctuary
    Posts
    12,516
    Blog Entries
    3

    Default Re: script question

    The sequence of phases as I remember them: PreFactionTurnStart, FactionTurnStart, SettlementTurnStart, CharacterTurnStart, This is the time & place where the player's action takes place, CharacterTurnEnd, SettlementTurnStart, FactionTurnEnd.

    That being said, it's rather possible that STS and CTS have to be swapped, don't remember that exactly really. it's been a while

    In regards to your purpose it's irrelevant whether you use PreFactionTurnStart or FactionTurnStart since the player will push a the recruitment button only when his faction has loaded which includes all of the above mentioned Starts.


    Son of Louis Lux, brother of MaxMazi, father of Squeaks, Makrell, Kaiser Leonidas, Iskar, Neadal, Sheridan, Bercor and HigoChumbo, house of Siblesz

    Not everything that counts can be counted, and not everything that can be counted counts.

  10. #10

    Default Re: script question

    The sequence of phases as I remember them: PreFactionTurnStart, FactionTurnStart, SettlementTurnStart, CharacterTurnStart, This is the time & place where the player's action takes place, CharacterTurnEnd, SettlementTurnEnd, FactionTurnEnd.
    that makes a lot of sense actually. thanks

    EDITED:
    i am having a parsing error with the end_if token,
    : error :
    20:53:03.419 [game.script] [error] Script parsing error at line 497, column 9 in mods/Crusader_tradeandsupplymod/data/world/maps/campaign/imperial_campaign/campaign_script.txt
    don't recognise this token: end_if
    20:53:03.419 [game.script] [error] Script parsing error at line 499, column 13 in mods/Crusader_tradeandsupplymod/data/world/maps/campaign/imperial_campaign/campaign_script.txt
    Couldn't create a script from file mods/Crusader_tradeandsupplymod/data/world/maps/campaign/imperial_campaign/campaign_script.txt
    Code:
    monitor_event SettlementTurnStart SettlementIsLocal
        and SettlementBuildingExists >= brothel
        and SettlementTaxLevel >= tax_high
            set_event_counter stock_ale 1
            set_event_counter stock_ale1 1
            set_event_counter stock_ale2 1
            set_event_counter stock_ale3 1
    end_monitor
    monitor_event SettlementTurnStart SettlementIsLocal
        and SettlementBuildingExists >= brothel
        and SettlementTaxLevel <= tax_normal
            set_event_counter stock_ale 0
            set_event_counter stock_ale1 0
            set_event_counter stock_ale2 0
            set_event_counter stock_ale3 0
            inc_counter ale -30
    end_monitor
    monitor_event SettlementTurnEnd SettlementIsLocal
        and SettlementBuildingExists == brothel
        if I_EventCounter stock_ale = 1
            if I_LocalFaction jerusalem
                inc_counter ale 100
                add_money jerusalem 100
            end_if   this is the token in line 497
            if I_LocalFaction antioch
                inc_counter ale 100   and here is the parsing error at 499
                add_money antioch 100
            end_if
            if I_LocalFaction byzantium
                inc_counter ale 100
                add_money byzantium 100
            end_if
            if I_LocalFaction turks
                inc_counter ale 100
                add_money turks 100
            end_if
            if I_LocalFaction egypt
                inc_counter ale 100
                add_money egypt 100
            end_if
        end_if
        if I_EventCounter stock_ale = 0
            if I_LocalFaction jerusalem
                inc_counter ale -10
                add_money jerusalem -100
            end_if
            if I_LocalFaction antioch
                inc_counter ale -10
                add_money antioch -100
            end_if
            if I_LocalFaction byzantium
                inc_counter ale -10
                add_money byzantium -100
            end_if
            if I_LocalFaction turks
                inc_counter ale -10
                add_money turks -100
            end_if
            if I_LocalFaction egypt
                inc_counter ale -10
                add_money egypt -100
            end_if
        end_if
    end_monitor
    i have change the monitor event to this one and still the same error at the same line: i have add the ; to the if I_LocalFaction jerusalem part and it goes and skips one end_if and goes to the third end_if statement... any guess?

    @Withwnar
    So you're trying to sum up the total "ale" across the entire faction or just per settlement? Because you can't do per-settlement stuff in the EDB like that: event counters are faction wide.
    i guess i did not pay attention to this: so you are saying that a SettlementTurn event will not trigger any I_EventCounter that is placed in the EDB, if i understand correctly, this could be the reason why the unknown error in the end_if part of the script, i also notice that the eventCounter set up in EDB stock_ale is not giving the happines_bonuses in the brothel tree...it was giving it before though, i am not so sure which monitor is the one that messes all of it up, dump me i didn´t back up.

    i will try to come up with a solution ..... any feedback is appreciated.
    Last edited by Icedie El Guaraní; August 02, 2012 at 05:00 PM.
    Contribuitor IBIICB-WOTN-Modeler-Scripter


  11. #11

    Default Re: script question

    There is no difference between = and == in M2TW scripting.

    in regards to the EDB on per-settlement basis, withwnar was referring to the event counter itself. It is set across the board. The only way you can have it effect individual settlements is changing it when the building browser or recruitment browser is opened (so never for the AI). But you have to set precautions in that it is possible to change settlements from 'within' the browsers. At that point the settlement is no longer 'selected'

    I am not to sure why the token 'end_if' is not recognized. The script looks like it should be fine. There could be something awry elsewhere in the script. I have had similar situations happen in my scripting where the log does not tell me what is actually wrong. Check the entire log (and script) for additional errors.

    PreFactionTurnStart i find is a great time to reset any counters. I usually set counters to 0 on turn end and then reset on PreFactionTurnStart with TurnStart (Faction, Settlement and Character) being when i have any effects take place. Of course it does depend on a script to script basis and what you are trying to achieve. Remember also that there is no PreFactionTurnStart on the first turn for the player. Another thing to keep in mind is the Slave turn (start and end), if ur script is not going to effect them then they are useful for resetting counters.

    Another thing also is that a single settlement can have multiple turns in the one turn if its control passes to another faction. But from what u are trying to do it should not affect your script, unless a settlement is given, at which point, that settlement wont have a turn end for that faction.

    I will be doing a preview of my Trade and Supply script soon for my Defender of the Crown mod, you are free to rip that script to pieces and use whatever you like. You are just having the T&S affect the player faction arent you? Mine effects all factions so i have had to take a different approach in some regards to how the script plays out, usually in that event counters are set and reset every faction turn.
    ...longbows, in skilled hands, could reach further than trebuchets...

  12. #12

    Icon1 Re: script question

    Icedie El Guaraní: Have you declared the ‘ale’ counter somewhere in your scripting?

    If you are using the ‘add_money’ command to give money to the local faction, you don't actually need to identify the factions’ individual. All you need to do is this ‘add_money -100’. that should make your script a bit shorter.

    It's important to realise that if your script is changing the value of event counters that are integrated with your ‘export_descr_buildings’ file, that change will not be picked up until the faction in question starts its next turn. That’s why such event counters are usually changed at ‘CharacterTurnEnd’, ‘SettlementTurnStart’, and ‘FactionTurnEnd’.

    Though you can, as has been pointed out, put an ‘if’ statement within an ‘if’ statement it occasional more trouble than it's worth. especially since, in this case, you will most likely need to have individual counters for each possible local faction, and that would remove the need for those double ‘if’ statements.

  13. #13
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: script question

    Quote Originally Posted by Aikanár View Post
    The sequence of phases as I remember them: PreFactionTurnStart, FactionTurnStart, SettlementTurnStart, CharacterTurnStart, This is the time & place where the player's action takes place, CharacterTurnEnd, SettlementTurnStart, FactionTurnEnd.
    I have been corrected on this myself on more than one occasion. The order is:

    PreFactionTurnStart
    CharacterTurnStart
    SettlementTurnStart
    FactionTurnStart
    {local player makes his moves}
    CharacterTurnEnd
    SettlementTurnEnd
    FactionTurnEnd

    So that's the difference between PFTS and FTS, Icedie: FTS happens after the all other TurnStart events have fired. It might be the place to put your 1000 limit script but from what I can see from your scripts I don't think it would make any difference whether it was here or in PTFS, as Aikanar said, as this limit only affects the historic event message and that message can only be seen in response to the user performing an action (and performing actions can only be done after both PFTS and FTS have fired).

    But it might depend on what that 1000 script is actually doing. If it is using any of the stock_aleXXX event counters then it won't work correctly in PFTS because those counters are set in SettlementTurnStart which happens after PFTS.

    Personally I would make it the last step in the chain (FTS) to be sure.

    Quote Originally Posted by Tsarsies View Post
    I am not to sure why the token 'end_if' is not recognized. The script looks like it should be fine. There could be something awry elsewhere in the script.
    It could be that somewhere before that script there is an IF that does not have an END_IF. Or a missing end_monitor. These errors can be hard to track down. At least your script is nicely formatted (indented) which makes finding a missing end_if much easier.

    Quote Originally Posted by Tsarsies View Post
    there is no PreFactionTurnStart on the first turn for the player
    I have heard this before but it does fire. In Kingdoms anyway. Maybe this was a RTW thing? Or vanilla M2TW?

    Quote Originally Posted by Tsarsies View Post
    Another thing also is that a single settlement can have multiple turns in the one turn if its control passes to another faction.
    Ah! I always wondered about that.

    Quote Originally Posted by TNZ View Post
    if your script is changing the value of event counters that are integrated with your ‘export_descr_buildings’ file, that change will not be picked up until the faction in question starts its next turn.
    This would explain why you're not seeing the effects I think Icedie. Oh, wait, another reason could be this...

    Both of those SettlementTurnStart monitors will fire for each settlement in turn. If the last settlement in the sequence has
    SettlementBuildingExists >= brothel
    and SettlementTaxLevel <= tax_normal
    then the event counters will be set to 0 - and remain at 0 for that turn - even though they might have previously been set to 1 by other settlement(s).

    So when should the bonuses be active? When:
    ANY >=brothel settlement has high taxes?
    ALL >=brothel settlements have high taxes?

    Maybe I'm still not quite following but shouldn't the happiness only happen when your ale stocks are above a certain level?

    so you are saying that a SettlementTurn event will not trigger any I_EventCounter that is placed in the EDB
    As Tsarsies said. It isn't really relevant here because you're not trying to do any such thing but I meant: even though you can set up monitors to set an event counter based on the properties of one particular settlement (e.g. the tax level of London) you can't apply that event counter to just one settlement in EDB. e.g. The event counter might be named london_low_tax and used as a condition in a happiness bonus in EDB, but ALL settlements will get that bonus if london_low_tax = 1, not just London. (Although it can be done to an extent by using hidden resources as well.) But anyway, like I said, not relevant to this so forget I mentioned it.

  14. #14
    Aikanár's Avatar no vaseline
    Join Date
    Mar 2009
    Location
    Sanctuary
    Posts
    12,516
    Blog Entries
    3

    Default Re: script question

    Quote Originally Posted by Withwnar View Post
    I have been corrected on this myself on more than one occasion. The order is:

    PreFactionTurnStart
    CharacterTurnStart
    SettlementTurnStart
    FactionTurnStart
    {local player makes his moves}
    CharacterTurnEnd
    SettlementTurnEnd
    FactionTurnEnd
    Hehe, thanks for correcting my mess

    Quote Originally Posted by Withwnar View Post
    I have heard this before but it does fire. In Kingdoms anyway. Maybe this was a RTW thing? Or vanilla M2TW?
    Confirmed, PFTS definitely fires for the players first turn with Kingdoms just don't add the redundant turn 0 condition.


    Son of Louis Lux, brother of MaxMazi, father of Squeaks, Makrell, Kaiser Leonidas, Iskar, Neadal, Sheridan, Bercor and HigoChumbo, house of Siblesz

    Not everything that counts can be counted, and not everything that can be counted counts.

  15. #15

    Default Re: script question

    ok thanks every one i think i found what was the unknow error, i am not 100% sure but i can only use 5 rows of "if" statements when i am using several Conditions before it, other wise i have a not recognized "end_monitor" error, i try using 6 " if " statements and the error is back....maybe somebody had figure this out before, because i have other scripts running with at least 70 if statements but they only have 2 conditions unlike the other that has about 6 conditions before the if statements begin.....anyways thanks to all that help and rep+
    Last edited by Icedie El Guaraní; August 19, 2012 at 08:57 AM.
    Contribuitor IBIICB-WOTN-Modeler-Scripter


  16. #16
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: script question

    That doesn't sound right. Can you post a script example of the one that doesn't work?

  17. #17

    Default Re: script question

    @Withwnar
    thanks mate but i have already change the entire script and have no record of that script, so there is no need to waste time on that one.....yeah it was weird but i moved on

    but i do have a question on another script, is the same script but with the new changes, this time i dont know why it spawns 4 armies on the resource in the first if statement.... can´t seem to figure out what might be the problem.

    you need to put them on your crusade campaign_script.txt as part of it not alone, back up the file in case.

    it suppose to fire when a local faction´s merchant is near a resource that is situated in a local region that has a enemy merchant on the resource or near it. but it only spawns armies on the first resource x98, y5 four times, because it only should spawn an army with 2 troops of Bedouin Camel Riders....what happens is that if an enemy merchant is on another resource and my merchant is near it the army spawns back 4 times on 98, 5 resource. ahh i almost forgot, the resources are glass, silver, gold. the other resources don´t fire this event, they are 35 resources.

    any advice?



    EDITED: any one?
    Last edited by Icedie El Guaraní; August 26, 2012 at 07:29 AM.
    Contribuitor IBIICB-WOTN-Modeler-Scripter


  18. #18
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: script question

    The problem might be due to multiple egypt merchants. Just taking the first two monitors as an example...

    They both fire for all of egypt's merchants, so long as they are in an egypt region. During the first merchant's turn end the script sets egypt_raider_jerus=1 if any of those "near resource" conditions are true. Then it spawns an army if egypt_raider_jerus=1 and sets egypt_raider_jerus=0.

    Then the whole process is repeated for the second merchant, including setting the counter back to 1 if any "near resource" conditions are true (which they still will be if no merchants have moved since the previous merchant's turn end).

    I didn't look deeply enough at the script to fully understand what is supposed to be happening but if you only want one of these spawns to happen per turn (not per merchant) then you might need another counter that is set to 0 at turn start and to 1 when a spawn happens and use that counter as an additional condition for your spawns.

    Alternatively perhaps you could move this script out of the CharacterTurnEnd monitors and put it in one FactionTurnEnd monitor. It seems to me that you don't need this to happen during the merchants' turns, you just need to know whether egypt and jerusalem merchants are near each other (which are I_xxx tests and so can be tested anytime) and whether the factions are at war (again, only one test per turn is needed here: a single monitor to test just that).

    Having said that though, there is also the RegionIsLocal condition which your script is using but my proposal can not. But... its use in your script is not necessarily 'accurate' anyway. It is saying "if this egypt merchant is in an egypt region and any egypt merchant is near resource X and any jerusalem merchant is near that same resource then set the counter to 1". That's the limitation of this I_NearXXX condition: it isn't testing whether this merchant is near tile X, only that a merchant is. A very frustrating limitation.

    If you really need this "in egypt region" condition then perhaps instead of RegionIsLocal you could use I_SettlementOwner: the appropriate settlement for the region in which the particular resource lies.

    e.g. Something like...

    Code:
    declare_counter spawned_this_turn
    declare_counter egypt_jerus_atwar
    
    monitor_event FactionTurnEnd FactionType egypt
      set_counter spawned_this_turn 0
      set_counter egypt_jerus_atwar 0
    end_monitor
    
    monitor_event FactionTurnEnd FactionType egypt
      and DiplomaticStanceFromCharacter jerusalem == AtWar
      set_counter egypt_jerus_atwar 1
    end_monitor
    
    monitor_event FactionTurnEnd FactionType egypt
      and I_LocalFaction jerusalem
      and I_CompareCounter egypt_jerus_atwar == 1
      and I_CompareCounter spawned_this_turn == 0
    
      ;resource 1
      if I_CharacterTypeNearTile egypt merchant, 2 101, 2
        and I_CharacterTypeNearTile jerusalem merchant, 2 101, 2
        and I_SettlementOwner {this resource's region's settlement} == egypt jerusalem
    
        spawn_army...
    
      end_if
    
      ;likewise for resource2, 3, etc.
    
    end_monitor
    The one-spawn-per-turn (spawned_this_turn) limitation is optional.

    Actually it can be further simplified: no need for a separate monitor or counter for the AtWar test...

    Code:
    declare_counter spawned_this_turn
    
    monitor_event FactionTurnEnd FactionType egypt
      set_counter spawned_this_turn 0
    end_monitor
    
    monitor_event FactionTurnEnd FactionType egypt
      and I_LocalFaction jerusalem
      and DiplomaticStanceFromCharacter jerusalem == AtWar
      and I_CompareCounter spawned_this_turn == 0
    
      ;resource 1
      if I_CharacterTypeNearTile egypt merchant, 2 101, 2
        and I_CharacterTypeNearTile jerusalem merchant, 2 101, 2
        and I_SettlementOwner {this resource's region's settlement} == egypt jerusalem
    
        spawn_army...
    
      end_if
    
      ;likewise for resource2, 3, etc.
    
    end_monitor
    By the way, is this a typo..?
    Code:
    declare_counter agypt_raider_jerus
    No such counter is used anywhere in that script and the egypt_raider_jerus is not declared.
    Last edited by Withwnar; September 03, 2012 at 03:32 AM. Reason: Fixed script error

  19. #19

    Default Re: script question

    They both fire for all of egypt's merchants, so long as they are in an egypt region. During the first merchant's turn end the script sets egypt_raider_jerus=1 if any of those "near resource" conditions are true. Then it spawns an army if egypt_raider_jerus=1 and sets egypt_raider_jerus=0.

    Then the whole process is repeated for the second merchant, including setting the counter back to 1 if any "near resource" conditions are true (which they still will be if no merchants have moved since the previous merchant's turn end).
    thanks Withwnar, brilliantly spotted , i was having hard time figuring that out, i will write the script keeping all that in mind.

    Alternatively perhaps you could move this script out of the CharacterTurnEnd monitors and put it in one FactionTurnEnd monitor.
    i guess i am too stubborn so a simple code like that gets away that easy.

    If you really need this "in egypt region" condition then perhaps instead of RegionIsLocal you could use I_SettlementOwner:
    well this is where i started to really love you, but one thing though, egypt is the raider so the region has to be local not AI, but that script idea works both ways.

    Code:
    declare_counter spawned_this_turn  
    monitor_event FactionTurnEnd FactionType egypt   
    set_counter spawned_this_turn 0 
    end_monitor
    this is where you knock me off, i don´t see why i have to set "
    spawned_this_turn" again to 0, i thought declaring it set it to 0, i know i am wrong but i thought that was the case.

    Code:
    declare_counter spawned_this_turn
    declare_counter egypt_jerus_atwar  
    monitor_event FactionTurnStart FactionType egypt   
    set_counter spawned_this_turn 1   
    set_counter egypt_jerus_atwar 0 
    end_monitor  
    monitor_event FactionTurnEnd FactionType egypt  
    and DiplomaticStanceFromCharacter jerusalem == AtWar   
    set_counter egypt_jerus_atwar 1 
    end_monitor  
    monitor_event FactionTurnEnd FactionType egypt   
    and I_LocalFaction jerusalem   
    and I_CompareCounter egypt_jerus_atwar == 1   
    and I_CompareCounter spawned_this_turn == 4        
    set_counter spawned_this_turn 0   
    ;resource 1   
    if I_CharacterTypeNearTile egypt merchant, 2 101, 2     
    and I_CharacterTypeNearTile jerusalem merchant, 2 101, 2     
    and I_SettlementOwner {this resource's region's settlement} == egypt      
    
    spawn_army...    
    end_if    
    ;likewise for resource2, 3, etc.  
    end_monitor
    wouldn´t this script spawn only every 4 turns?

    By the way, is this a typo..?
    Code:
    declare_counter agypt_raider_jerus
    indeed it was, and the counters had been declare, maybe i forgot to add it to the txt uploaded.

    many thanks, i will keep this thread posted with more............+rep
    Contribuitor IBIICB-WOTN-Modeler-Scripter


  20. #20
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: script question

    You're welcome.

    Quote Originally Posted by Icedie El Guaraní View Post
    egypt is the raider so the region has to be local not AI, but that script idea works both ways.
    Oops. That should have been...

    Code:
    and I_SettlementOwner {this resource's region's settlement} == jerusalem
    (I'll edit my script.)

    The monitor that contains this test has an "I_LocalFaction jerusalem" condition. Therefore the monitor will only fire when jerusalem is the local faction which implies that any "I_SettlementOwner XXX = jerusalem" test within that monitor means "I_SettlementOwner XXX = local faction jerusalem". If you see what I mean. Another way to do it would be...

    Code:
      if I_CharacterTypeNearTile egypt merchant, 2 101, 2
        and I_CharacterTypeNearTile jerusalem merchant, 2 101, 2
        and I_SettlementOwner {this resource's region's settlement} == jerusalem
        and I_LocalFaction jerusalem
    
        spawn_army...
    
      end_if
    Quote Originally Posted by Icedie El Guaraní View Post
    i don´t see why i have to set "spawned_this_turn" again to 0, i thought declaring it set it to 0, i know i am wrong but i thought that was the case.
    declare_counter is just saying "let there be a counter named XXX". It lies outside of any monitors so is therefore only executed once: at campaign start. Declaring it does set it to zero, yes, but after the end of the first turn (or any turn) it might now be 1, so you need to reset it back to 0 ready for the next turn.

    Quote Originally Posted by Icedie El Guaraní View Post
    Code:
    declare_counter spawned_this_turn
    declare_counter egypt_jerus_atwar  
    monitor_event FactionTurnStart FactionType egypt   
    set_counter spawned_this_turn 1   
    set_counter egypt_jerus_atwar 0 
    end_monitor  
    monitor_event FactionTurnEnd FactionType egypt  
    and DiplomaticStanceFromCharacter jerusalem == AtWar   
    set_counter egypt_jerus_atwar 1 
    end_monitor  
    monitor_event FactionTurnEnd FactionType egypt   
    and I_LocalFaction jerusalem   
    and I_CompareCounter egypt_jerus_atwar == 1   
    and I_CompareCounter spawned_this_turn == 4        
    set_counter spawned_this_turn 0   
    ;resource 1   
    if I_CharacterTypeNearTile egypt merchant, 2 101, 2     
    and I_CharacterTypeNearTile jerusalem merchant, 2 101, 2     
    and I_SettlementOwner {this resource's region's settlement} == egypt      
    
    spawn_army...    
    end_if    
    ;likewise for resource2, 3, etc.  
    end_monitor
    wouldn´t this script spawn only every 4 turns?
    No. At the start of every turn you are setting spawned_this_turn to 1. It will never reach 4. You need to increment (add 1 to) the counter each turn, not set it to 1 each turn. So instead of:

    set_counter spawned_this_turn 1

    use:

    inc_counter spawned_this_turn 1

    In this case "spawned_this_turn" is a poor name for the counter, of course. Not that it really matters but it would better be named "turns_since_last_spawn" or something like that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •