Results 1 to 30 of 116

Thread: An Intermediate Guide to Scripting

Hybrid View

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

    Default An Intermediate Guide to Scripting

    AN INTERMEDIATE GUIDE TO SCRIPTING
    BACKGROUND SCRIPTS

    By Epistolary Richard & Myrddraal
    ___________________________


    In A Beginner Guide to Scripting we identified two different types of scripts: campaign scripts and show_me scripts, and went further to divide show_me scripts into event scripts and background scripts.

    The Beginner Guide taught us the basics of using the event script – which is a script that runs only for a moment, making a change to the game world. These must be manually activated when their trigger event occurs.

    This guide takes us a little deeper into the world of the background script – this is a script that is running constantly in the background of the game. It must be activated at the start of the game, and then manually reactivated each time the game is reloaded.


    The Benefits of a Background script

    There are two major limitations to the use of event scripts. The first is that it requires the player to click on the show_me button each and every time you want to make a change to the game environment.

    The second, more importantly, is that the event script trigger can only ever be something that will happen in the player’s own turn. If it occurs outside of the player’s turn then the player will never get the chance to click on the show_me button as the advisor will appear and disappear during the AI turn.

    This is why modders use background scripts as the main driver for their scripting features as they require the player only to make a single click each time the game is reloaded to run all their features and it gives them complete flexibility as to when and how their features are implemented.

    In fact, the very first scripts that Myrddraal released – the Multiple Turns per Year script and the Hot Seat Beta script – were both background scripts.

    In truth, every mod with significant scripting features will end up making use of all of the different types of script – background, event and campaign – as they all compliment each other.


    What is a Background script?

    As all show_me scripts, the background script is activated through the advisor. It must have all the components of a show_me script as listed in the Beginner Guide, namely trigger, advice thread and script.

    The fundamental difference between an event script and a background script is that a background script is supposed to keep running and not terminate until the game is quit.

    This is accomplished with the addition of a simple piece of code to the script – a While loop:

    Code:
    script
    declare_counter loop
    set_counter loop 0
    ; Insert your background script here
    while I_CompareCounter loop = 0
    end_while
    end_script
    Once activated, this script will never terminate as when it reaches the end_while it will loop back to the I_CompareCounter.

    Now we have the script working all the time, however, we have to incorporate the triggers we want to use into the script itself, instead of the export_descr_advice file. To do that, we need to use new syntax:

    Monitors, If statements and While loops

    The monitor event/monitor conditions/if/while commands are very much like the triggers for advice threads.

    Basically they are for checking conditions.

    If statements

    Like for example if you have a counter called no

    Code:
    script
    declare_counter no
    set_counter no 1
     
    If I_CompareCounter no 1
    Insert code here
    end_if
     
    end_script
    What this will do is at the stage at which it reaches the If line, it will check counter no, if counter no is 1 then it will run the code, if not it will skip to the end_if.

    While loops

    A while loop will repeat itself whilst its conditions are true.

    Code:
    script
    declare_counter no
    set_counter no 0
     
    While I_CompareCounter no = 0
    Insert code here
    end_while
     
    end_script
    When the script runs through, everytime it reaches and end_while, it will check the conditions, and if they are still true, it will jump back to the while statement. Basically looping that bit of code. In this example, the script will keep running forever, because the condition is that no is zero, and there is no code to stop this.

    While monitors can be extreemly usefull for pausing the script until something happens.

    Code:
    While I_TurnNumber = 0
    end_while
    This will pause the script until the player ends the first turn (turn 0)

    It can also be very helpfull if you do not want a script to end before a monitor is triggered. (see below)

    Monitors

    Condition monitors
    Code:
    script
    declare_counter loop
    set_counter loop 1
    declare_counter no
    set_counter no 0
     
    monitor_conditions I_CompareCounter no = 1
    Insert code here
    terminate_monitor
    end_monitor
     
    campaign_wait 10
     
    set_counter no 1
     
    while I_CompareCounter loop = 1
    end_while
    end_script
    The difference between a Monitor and an If statement is that the conditions for an if statement are checked when the if statement is reached, and not again. A monitor can be declared at the beginning of the script and will then be checked continuously.
    In the example above, the monitor is declared, but the counter no is not 1. As soon as no changes to 1 (after waiting 10) the monitor is triggered and the code inside it is run.

    Event monitors
    Code:
    script
    declare_counter loop
    set_counter loop 1
     
    monitor_event buttonpressed buttonpressed end_turn TrueCondition
    Insert code here
    terminate_monitor
    end_monitor
     
    while I_CompareCounter loop = 1
    end_while
    end_script
    An event monitor is basically a trigger using certain conditions. For example the pressing of a button. In this case, on the pressing of the end turn button, the code inside the monitor will be run.

    The difference between terminate_monitor and end_monitor

    With some monitors, you will see both terminate_monitor and end_monitor at the end. This basically determines whether the monitor can be triggered more than once. If you include both, the monitor can only be triggered once, then it cannot be used again. If you only include the end_monitor, then the monitor can be enabled several times.

    And statements

    And statments can be used with monitors, if statements and while loops. This is for multiple conditions. For example:

    Code:
    script
    declare_counter noone
    declare_counter notwo 
    declare_counter nothree
     
    set_counter noone 1
    set_counter notwo 1
    set_counter nothree 1
     
    monitor_conditions I_CompareCounter noone = 1
    and I_CompareCounter notwo = 1
    and I_CompareCounter nothree = 1
    Insert code here
    terminate_monitor
    end_monitor
     
    if I_CompareCounter noone = 1
    and I_CompareCounter notwo = 1
    and I_CompareCounter nothree = 1
    Insert code here
    end_if
     
    end_script
    A full list of events, conditions & commands can be found here:
    https://forums.totalwar.org/vb/showthread.php?t=54299




    Now, that’s all a lot to take in. So let’s try some examples:

    More More Money
    Here we give the player a little monetary boost each turn. It’ll happen automatically, no need for him to manually activate it.

    For the event to trigger it, I’m going to choose FactionTurnStart and I want it only at the start of the player’s turn so I’m going to use the FactionIsLocal conditional.

    Code:
    script
    declare_counter loop
    set_counter loop 0
    
    monitor_event FactionTurnStart FactionIsLocal
    console_command add_money 100
    end_monitor
    
    while I_CompareCounter loop = 0
    end_while
    end_script
    Now, at the beginning of each turn, the player’s treasury will increase by 100.

    Simple enough. Let’s make it more complicated.

    Here is a script that will make it considerably harder for a player to amass a huge treasury:
    Code:
    script
    declare_counter loop
    set_counter loop 0
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;; Creosote remover
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    
    monitor_event FactionTurnStart FactionIsLocal
    and not LosingMoney
    and Treasury > 10000
    
    console_command add_money -1000
    
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
    and not LosingMoney
    and Treasury > 20000
    
    console_command add_money -3000
    
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
    and not LosingMoney
    and Treasury > 30000
    
    console_command add_money -6000
    
    end_monitor
    while I_CompareCounter loop = 0
    end_while
    end_script
    At the beginning of each turn, the script will check the player’s treasury and then, if it above a certain amount and the player is not losing money, it will reduce it by the specified amount eg, 1,000 if it is above 10,000.

    Note that all of these monitors will be triggered at the start of the player’s turn. Therefore if his treasury has gone higher than 30,000 he will not be docked 6,000 but 10,000 (1,000 + 3,000 + 6,000).

    Here’s a very different script (from the late, unlamented Client Kingdoms 2 which will never be), one designed to give a non-player controlled faction a helping hand if things start going bad for them.
    Code:
    script
    declare_counter loop
    set_counter loop 0
    
    monitor_event FactionTurnStart FactionType britons
    and I_NumberOfSettlements britons < 4
    and RandomPercent < 15
    
    console_command create_unit Londinium "warband sword briton" 1
    console_command create_unit Londinium "warband hurler briton" 1
    console_command create_unit Eburacum "warband sword briton" 1
    console_command create_unit Eburacum "warband hurler briton" 1
    console_command create_unit Deva "warband sword briton" 1
    console_command create_unit Deva "warband hurler briton" 1
    
    end_monitor
    while I_CompareCounter loop = 0
    end_while
    end_script
    Let’s take it step by step, first of all, the initial event:
    Code:
     monitor_event FactionTurnStart FactionType Britons
    and not FactionIsLocal
    and I_NumberOfSettlements britons < 4
    and RandomPercent < 26
    Means that it will be triggered when:
    1) At the start of the Britons turn
    2) When the player is _not_ playing the Britons
    3) When the number of settlements the Britons own is less than 4
    4) And if the computer picks a random number between 1 and 25 – this means that even when all the other conditions are satisfied it will only happen on average 1 time in 4.

    If all those conditions are satisfied, then the game will run the script within the monitor, creating the units within those settlements. The problem with it at present is that script will create the unit its told to, irrespective of whether it is the Britons or another faction who control that settlement, and assign it to that faction which controls the settlement. We therefore need to check to make sure we only create the unit in a settlement if the Britons control that settlement, for example:
    Code:
     if I_SettlementOwner Londinium = britons
    console_command create_unit Londinium "warband sword briton" 1
    console_command create_unit Londinium "warband hurler briton" 1
    end_if
    So our full script would look like the following:

    Code:
    script
    declare_counter loop
    set_counter loop 0
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;; britons in danger - Dads Army
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    monitor_event FactionTurnStart FactionType britons
    and I_NumberOfSettlements britons < 4
    and RandomPercent < 15
    
    if I_SettlementOwner Londinium = britons
    console_command create_unit Londinium "warband sword briton" 1
    console_command create_unit Londinium "warband hurler briton" 1
    end_if
    
    if I_SettlementOwner Eburacum = britons
    console_command create_unit Eburacum "warband sword briton" 1
    console_command create_unit Eburacum "warband hurler briton" 1
    end_if
    
    if I_SettlementOwner Deva = britons
    console_command create_unit Deva "warband sword briton" 1
    console_command create_unit Deva "warband hurler briton" 1
    end_if
    
    end_monitor
    while I_CompareCounter loop = 0
    end_while
    end_script

    Triggers

    We’re now beginning to understand what a background script is, however the script is only one of the three elements listed in the Beginner Guide – we also need an advice thread and, more importantly, a trigger. These are done in the same way as in the Beginner Guide, so rather than go through them again, I’ll just show you an example.

    The F1 trigger
    This is the trigger used by Myrddraal in the first scripts that he released. It’s great benefit is that the trigger is not activated by normal play, it is therefore ideal for testing purposes and mods where the player can be relied upon to follow the process each time.

    It is, in fact the exact same trigger that was used in the Beginner Guide. But here it is again
    This is the advice thread (NB, all this already exists, only the Script line has been added)
    Code:
     ;------------------------------------------
    AdviceThread Help_Campaign_Keyboard_Shortcuts_Scroll_Thread
        GameArea Campaign
    
        Item Help_Campaign_Keyboard_Shortcuts_Scroll_Text_01
            Uninhibitable
            Verbosity  0 
            Threshold  1 
            Attitude Normal
            Presentation Default
            Title Help_Campaign_Keyboard_Shortcuts_Scroll_Text_01_Title
            Script scripts\show_me\background_script.txt ; This is the added line
            Text Help_Campaign_Keyboard_Shortcuts_Scroll_Text_01_Text1
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;------------------------------------------
    Trigger 2137_Help_Campaign_Keyboard_Shortcuts_Scroll_Trigger
        WhenToTest ScrollAdviceRequested
    
        Condition ScrollAdviceRequested help_scroll
    
        AdviceThread Help_Campaign_Keyboard_Shortcuts_Scroll_Thread  0
    To activate your background script (placed in the data\scripts\show_me folder, of course), you must press F1 – then click on the ? – then the advisor should pop up and you can click on the Show Me How button at the beginning of the campaign and after each reload.

    Now more and more mods are developing background scripts, scripters have been looking into ways to make activation and reactivated more user friendly. Eventually, once a certain number of mods have been released, I imagine that a community standard will develop as mod-users become accustomed with a specific method. More sophisticated triggers (and their consequences) will be the topic of the further portion of this guide which will be a series of modules focusing on various advanced scripting techniques to which all are invited to contribute.


    Scripting links
    CA's list of commands, events and conditions
    Scripting research thread
    Hot Seat Mod - Beta Release
    More than two turns a year - release
    Epistolary Richard's modding Rules of Cool
    Cool modders make their mods with the :mod command line switch
    If they don't, then Cool mod-users use the Mod Enabler (JSGME)
    Cool modders use show_err
    Cool modders use the tutorials database Cool modders check out the Welcome to the Modding Forums! thread Cool modders keep backups Cool modders help each other out

  2. #2
    Ja mata, TosaInu Forum Administrator edyzmedieval's Avatar
    Join Date
    May 2005
    Location
    Fortress of the Mountains
    Posts
    11,439

    Default Re: An Intermediate Guide to Scripting

    You're a scripting god. Thanks very much!!!
    Ja mata, TosaInu. You will forever be remembered.

    Proud

    Been to:

    Swords Made of Letters - 1938. The war is looming in France - and Alexandre Reythier does not have much time left to protect his country. A novel set before the war.

    A Painted Shield of Honour - 1313. Templar Knights in France are in grave danger. Can they be saved?

  3. #3
    J-23 Member Hans Kloss's Avatar
    Join Date
    Oct 2003
    Location
    Richmond upon Thames
    Posts
    245

    Default Re: An Intermediate Guide to Scripting

    Quick question Richard

    With use of script would that be possible to spawn mercenary unit for hire only for non-Roman factions (playable and non playable one) for example "Roman deserters".Obviously such a unit would not be available for Romans.Is that at all possible ?

  4. #4

    Default Re: An Intermediate Guide to Scripting

    Yes, perfectly possible - but obviously not through the existing mercenary mechanism. Look at the Client Kingdoms mod for one way of doing it for the player. For non-player factions you would have to do it in a background script using a monitor_event with whatever conditionals you want and a create_unit console command inside.
    Epistolary Richard's modding Rules of Cool
    Cool modders make their mods with the :mod command line switch
    If they don't, then Cool mod-users use the Mod Enabler (JSGME)
    Cool modders use show_err
    Cool modders use the tutorials database Cool modders check out the Welcome to the Modding Forums! thread Cool modders keep backups Cool modders help each other out

  5. #5

    Default Re: An Intermediate Guide to Scripting

    a wonderful Thread...

    I'm posting for very first time in this forum but i'm not reading in this section for first time...my english is not very good..please forgive me some grammar faults!

    A quick question:
    has anybody checked the disable_ai console command if it works?
    I would like to make a script that disable all the ai_actions and combine this with the faction switcher script! I have some problems with this matter because in the faction switcher script the ai make some stuff at the end of every turn...
    i would like to execute this...

    could it be that the command terminate_script?

    here is the script:
    HTML Code:
    script
    
    declare_counter player_faction
    
    	if I_LocalFaction romans_julii
    		set_counter player_faction 1
    	end_if
    	if I_LocalFaction macedon
    		set_counter player_faction 2
    	end_if
    	if I_LocalFaction egypt
    		set_counter player_faction 3
    	end_if
    	if I_LocalFaction seleucid
    		set_counter player_faction 4
    	end_if
    	if I_LocalFaction carthage
    		set_counter player_faction 5
    	end_if
    	if I_LocalFaction parthia
    		set_counter player_faction 6
    	end_if
    	if I_LocalFaction pontus
    		set_counter player_faction 7
    	end_if
    	if I_LocalFaction gauls
    		set_counter player_faction 8
    	end_if
    	if I_LocalFaction germans
    		set_counter player_faction 9
    	end_if
    	if I_LocalFaction britons
    		set_counter player_faction 10
    	end_if
    	if I_LocalFaction armenia
    		set_counter player_faction 11
    	end_if
    	if I_LocalFaction dacia
    		set_counter player_faction 12
    	end_if
    	if I_LocalFaction greek_cities
    		set_counter player_faction 13
    	end_if
    	if I_LocalFaction numidia
    		set_counter player_faction 14
    	end_if
    	if I_LocalFaction scythia
    		set_counter player_faction 15
    	end_if
    	if I_LocalFaction spain
    		set_counter player_faction 16
    	end_if
    	if I_LocalFaction thrace
    		set_counter player_faction 17
    	end_if
    
    ;---------------------------------------------
    
    	if I_CompareCounter player_faction = 1
    		console_command disable_ai thrace
    	end_if
    	if I_CompareCounter player_faction = 2
    		console_command disable_ai romans_julii
    	end_if
    	if I_CompareCounter player_faction = 3
    		console_command disable_ai egypt
    	end_if
    	if I_CompareCounter player_faction = 4
    		console_command disable_ai seleucid
    	end_if
    	if I_CompareCounter player_faction = 5
    		console_command disable_ai carthage
    	end_if
    	if I_CompareCounter player_faction = 6
    		console_command disable_ai parthia
    	end_if
    	if I_CompareCounter player_faction = 7
    		console_command disable_ai pontus
    	end_if
    	if I_CompareCounter player_faction = 8
    		console_command disable_ai gauls
    	end_if
    	if I_CompareCounter player_faction = 9
    		console_command disable_ai germans
    	end_if
    	if I_CompareCounter player_faction = 10
    		console_command disable_ai britons
    	end_if
    	if I_CompareCounter player_faction = 11
    		console_command disable_ai armenia
    	end_if
    	if I_CompareCounter player_faction = 12
    		console_command disable_ai dacia
    	end_if
    	if I_CompareCounter player_faction = 13
    		console_command disable_ai greek_cities
    	end_if
    	if I_CompareCounter player_faction = 14
    		console_command disable_ai numidia
    	end_if
    	if I_CompareCounter player_faction = 15
    		console_command disable_ai scythia
    	end_if
    	if I_CompareCounter player_faction = 16
    		console_command disable_ai spain
    	end_if
    	if I_CompareCounter player_faction = 17
    		console_command disable_ai thrace
    	end_if
    
    ;----------------------------------------------
    	
    	console_command control slave
    if I_LocalFaction romans_julii
    	console_command control macedon
    	terminate_script
    end_if
    if I_LocalFaction macedon
    	console_command control egypt
    	terminate_script
    end_if
    if I_LocalFaction egypt
    	console_command control seleucid
    	terminate_script
    end_if
    if I_LocalFaction seleucid
    	console_command control carthage
    	terminate_script
    end_if
    if I_LocalFaction carthage
    	console_command control parthia
    	terminate_script
    end_if
    if I_LocalFaction parthia
    	console_command control pontus
    	terminate_script
    end_if
    if I_LocalFaction pontus
    	console_command control gauls
    	terminate_script
    end_if
    if I_LocalFaction gauls
    	console_command control germans
    	terminate_script
    end_if
    if I_LocalFaction germans
    	console_command control britons
    	terminate_script
    end_if
    if I_LocalFaction britons
    	console_command control armenia
    	terminate_script
    end_if
    if I_LocalFaction armenia
    	console_command control dacia
    	terminate_script
    end_if
    if I_LocalFaction dacia
    	console_command control greek_cities
    	terminate_script
    end_if
    if I_LocalFaction greek_cities
    	console_command control numidia
    	terminate_script
    end_if
    if I_LocalFaction numidia
    	console_command control scythia
    	terminate_script
    end_if
    if I_LocalFaction scythia
    	console_command control spain
    	terminate_script
    end_if
    if I_LocalFaction spain
    	console_command control thrace
    	terminate_script
    end_if
    if I_LocalFaction thrace
    	console_command control romans_julii
    	terminate_script
    end_if
    
    end_script

  6. #6
    J-23 Member Hans Kloss's Avatar
    Join Date
    Oct 2003
    Location
    Richmond upon Thames
    Posts
    245

    Default Re: An Intermediate Guide to Scripting

    Quote Originally Posted by Epistolary Richard
    Yes, perfectly possible - but obviously not through the existing mercenary mechanism. Look at the Client Kingdoms mod for one way of doing it for the player. For non-player factions you would have to do it in a background script using a monitor_event with whatever conditionals you want and a create_unit console command inside.
    Thx for your reply Richard

    Would something like this make any sens ?

    HTML Code:
    script
    if I_SettlementOwner Tarsus =(probably list of all non roman factions or is that another way ?)
    console_command create_unit Tarsus "merc roman deserters" 1
    end_if
    end_script
    Last edited by Hans Kloss; 11-28-2005 at 22:47.

  7. #7

    Default Re: An Intermediate Guide to Scripting

    pilatus I remember Myrddraal saying something about the disable_ai command when putting together the Hot Seat Mod. He certainly used halt_ai for that.

    Maly Jacek If that's an event script then you're better off putting the conditionals in the trigger. If that's a background script you need a loop to keep it running and a monitor event in there to tell the game when to check the conditionals.
    Epistolary Richard's modding Rules of Cool
    Cool modders make their mods with the :mod command line switch
    If they don't, then Cool mod-users use the Mod Enabler (JSGME)
    Cool modders use show_err
    Cool modders use the tutorials database Cool modders check out the Welcome to the Modding Forums! thread Cool modders keep backups Cool modders help each other out

  8. #8

    Default Re: An Intermediate Guide to Scripting

    I put command line to export_descr_advise.txt, but when I press F1 and activate advisor, the <show me> button did not highlighted so I cannot click it to start scripts. What is wrong?

  9. #9

    Default Re: An Intermediate Guide to Scripting

    Did the correct advisor speech bubble appear? The Show Me How button doesn't become available until the speech bubble appears.

    Post the advice thread that you added the script line to in export_descr_advice.
    Epistolary Richard's modding Rules of Cool
    Cool modders make their mods with the :mod command line switch
    If they don't, then Cool mod-users use the Mod Enabler (JSGME)
    Cool modders use show_err
    Cool modders use the tutorials database Cool modders check out the Welcome to the Modding Forums! thread Cool modders keep backups Cool modders help each other out

  10. #10
    J-23 Member Hans Kloss's Avatar
    Join Date
    Oct 2003
    Location
    Richmond upon Thames
    Posts
    245

    Default Re: An Intermediate Guide to Scripting

    Richard
    As I have got not experience whatsover in scripting I have copy edited your your script:

    HTML Code:
    script
    declare_counter loop
    set_counter loop 0
    monitor_event FactionTurnStart FactionType sassanids
    
    if I_SettlementOwner Dumatha = sassanids
    console_command create_unit Dumatha "merc cata" 1
    console_command create_unit Dumatha "merc veteranii" 1
    end_if
    
    if I_SettlementOwner Erewan = sassanids
    console_command create_unit Erewan "elite cata" 1
    end_if
    terminate_monitor
    end_monitor
    while I_CompareCounter loop = 0
    end_while
    end_script
    That works but despite press F1 button it only works once.When I remove terminate_monitor I get new units created on every turn.Could you kindly tell me what line needs to be change for the unit to be created only upon pressing F1.I guess that could be also way of having message appearing advising player he can get new units.Also is there a line that could replace "Sassanids" with something like "all except Romans"

  11. #11

    Default Re: An Intermediate Guide to Scripting

    Quote Originally Posted by dzsagon
    I put command line to export_descr_advise.txt, but when I press F1 and activate advisor, the <show me> button did not highlighted so I cannot click it to start scripts. What is wrong?
    I solved the problem. If a script has any syntax error, the <show me how> button did not highlighted, not allows to run a script. Now my scripts run, but not wery well:(

    script
    declare_counter state
    set_counter state 0
    declare_counter loop
    set_counter loop 0

    console_command add_money -100; just for test to scripts really runs

    monitor_event FactionTurnStart FactionType Egypt
    and FactionIsLocal
    and FactionHasAllies

    if DiplomaticStanceFromFaction pontus >= Hostile
    set_counter state 1
    console_command add_money 2000; just for test to scripts really runs
    end_if

    if DiplomaticStanceFromFaction pontus < Hostile
    set_counter state 0
    console_command add_money -2000; just for test to scripts really runs
    end_if

    end_monitor

    monitor_event FactionTurnStart EgyptFactionType Numidia
    and not FactionIsLocal
    and DiplomaticStanceFromFaction pontus <= Hostile
    and I_CompareCounter state = 1

    console_command diplomatic_stance numidia pontus war

    end_monitor

    while I_CompareCounter loop = 0
    end_while

    end_script

    My allies is Nubidia. If I declare war with pontus I want to Nubidia declares war to. But the script not doing this.

  12. #12
    Simulation Monkey Member The_Mark's Avatar
    Join Date
    Dec 2004
    Location
    Helsinki, Finland
    Posts
    2,613

    Default Re: An Intermediate Guide to Scripting

    If that is a direct copy&paste from your script then this line is part of the problem:
    Code:
    monitor_event FactionTurnStart EgyptFactionType Numidia
    Then, there are the if lines in the first monitor.
    Code:
     monitor_event FactionTurnStart FactionType Egypt
    and FactionIsLocal
    and FactionHasAllies
    
    if DiplomaticStanceFromFaction pontus >= Hostile
    DiplomaticStanceFromFaction requires exported parametres from a monitor, so it will no work if it is not tied to the monitor with ands. You'll have to split the monitor in two. This is how the other monitor should begin:
    Code:
    monitor_event FactionTurnStart FactionType Egypt
    and FactionIsLocal
    and FactionHasAllies
    and DiplomaticStanceFromFaction pontus >= Hostile
    As a rule of thumb, if a condition doesn't start with I_ it requires to be used as an event monitor condition.

  13. #13

    Default Re: An Intermediate Guide to Scripting

    Thanks a lot! It works now!
    Another question. What is the proper command to give money to other fraction?
    add_money <amount> <fraction name> not works.

  14. #14

    Default Re: An Intermediate Guide to Scripting

    From what other people have posted, you need a comma in there:

    console_command add_money faction, how_much
    Epistolary Richard's modding Rules of Cool
    Cool modders make their mods with the :mod command line switch
    If they don't, then Cool mod-users use the Mod Enabler (JSGME)
    Cool modders use show_err
    Cool modders use the tutorials database Cool modders check out the Welcome to the Modding Forums! thread Cool modders keep backups Cool modders help each other out

  15. #15
    Member Member VirtualWolf's Avatar
    Join Date
    Jun 2006
    Location
    Canada near Toronto
    Posts
    7

    Default Re: An Intermediate Guide to Scripting

    Just a quick note to say thankyou for your guides I am new to modding and they have been invaluable... A great Help .. and because of your writing style I found them easy to understand...
    May the Forest shelter you
    May the wind protect you
    &
    May your packmates
    always answer
    to your call

  16. #16

    Default Re: An Intermediate Guide to Scripting

    I'm new to scripting, so bear with me.

    I want a script that gives the other factions (non player) money every turn, extra depending on the state of their economy.

    Would this work? (I'm having troubles getting mods to work at the moment, so I cant test it)
    Code:
    script
    declare_counter loop
    set_counter loop 0
    
    monitor_event FactionTurnStart 
    and not FactionIsLocal
    
    console_command add_money 2000
    
    end_monitor
    
    monitor_event FactionTurnStart 
    and not FactionIsLocal
    and Treasury < 2000
    
    console_command add_money 2000
    
    end monitor
    
    monitor_event FactionTurnStart 
    and not FactionIsLocal
    and Treasury < 5000
    
    console_command add_money 2000
    
    end monitor
    
    while I_CompareCounter loop = 0
    end_while
    end_script
    Thanks
    Last edited by Psyco; 01-16-2007 at 06:26.
    Anyone who has no fear of death himself can succeed in inflicting it.
    The Prince,
    Machiavelli

  17. #17
    Bibliophilic Member Atilius's Avatar
    Join Date
    Oct 2005
    Location
    America Medioccidentalis Superior
    Posts
    3,837

    Post Re: An Intermediate Guide to Scripting

    Your script won't work as you intend. When no faction is specified, the add_money console command puts the specified funds in the player's treasury.

    You need to repeat each of your monitors for every faction and specify the faction name in the add_money console command:

    Code:
    monitor_event FactionTurnStart FactionType seleucid
                        and not FactionIsLocal
    
    console_command add_money seleucid, 2000
    
    end_monitor
    
    monitor_event FactionTurnStart FactionType spain
                        and not FactionIsLocal
    
    console_command add_money spain, 2000
    
    end_monitor
    
    ...(et cetera)
    This need for duplication is responsible for the EB background script running to over 165,000 lines of code.
    The truth is the most valuable thing we have. Let us economize it. - Mark Twain



  18. #18

    Default Re: An Intermediate Guide to Scripting

    Thanks for the help.

    Is there any list that shows which versions of the names I should be using? I would assume the ones at the top of descr_strat.txt, but it never hurts to ask.

    I'm doing this for Medieval II, but I've heard the architecture is nearly identical, so it shouldn't matter.
    Last edited by Psyco; 01-17-2007 at 03:31.
    Anyone who has no fear of death himself can succeed in inflicting it.
    The Prince,
    Machiavelli

  19. #19
    Bibliophilic Member Atilius's Avatar
    Join Date
    Oct 2005
    Location
    America Medioccidentalis Superior
    Posts
    3,837

    Default Re: An Intermediate Guide to Scripting

    Quote Originally Posted by Psyco
    ... which versions of the names I should be using? I would assume the ones at the top of descr_strat.txt...
    Yes, that's right. M2TW has the faction names in descr_strat.txt too.
    The truth is the most valuable thing we have. Let us economize it. - Mark Twain



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO