Page 4 of 4 FirstFirst 1234
Results 91 to 116 of 116

Thread: An Intermediate Guide to Scripting

  1. #91
    Member Member Stuie's Avatar
    Join Date
    Aug 2001
    Location
    Upper Gwynedd, PA
    Posts
    406

    Default Re: An Intermediate Guide to Scripting

    Quote Originally Posted by Stuie
    No - something else. If/when I get it to work I'll report back.

    Coming back to this now that the most current beta version of TFT is public, I figured out how to *mostly* force automerge units - I'm sure people will find work-arounds but whatever.

    Here's the code - obviously needed for every faction playable:

    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;   AUTOMERGE UNITS CODE      ;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    monitor_event CharacterSelected FactionType romans_brutii
         and FactionIsLocal          
         call_object_shortcut campaign_hud automerge_units
    end_monitor
    
    monitor_event SettlementSelected FactionType romans_brutii          
         and FactionIsLocal          
         call_object_shortcut campaign_hud automerge_units
    end_monitor
    
    monitor_event CharacterSelected FactionType gauls          
         and FactionIsLocal          
         call_object_shortcut campaign_hud automerge_units
    end_monitor
    
    monitor_event SettlementSelected FactionType gauls          
         and FactionIsLocal          
         call_object_shortcut campaign_hud automerge_units
    end_monitor
    etc.

  2. #92

    Default Re: An Intermediate Guide to Scripting

    Hi!
    I'm trying make a script to reduce settlement population.
    Here best what I can do
    Code:
    script
    	declare_counter loop
    	set_counter loop 1
    	monitor_conditions Carthago SettlementPopulationMaxedOut
    	if Carthago SettlementPopulationMaxedOut
    	console_command add_population Carthago -7000
    	end_if
    	end_monitor
    	while I_CompareCounter loop = 1
    	end_while
    end_script
    With this Carthago population decreased from 30000 to 400 men, and growth bonus become 12,5%, but on the next turn there are no growth bonus at all. Population freezes on mark with 400 man.
    Can someone tell me what should I do if I need that population checks and reduced only if it's more then 24000,and it happened after turn end

    Sorry for my bad english.

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

    Default Re: An Intermediate Guide to Scripting

    We have been trying to script sacking Rome by Alaric's troops in 410 AD for new version of IBFD mod

    monitor_event FactionTurnStart FactionType goths
    and I_TurnNumber = 1
    console_command sack_settlement Rome
    console_command add_money 10000
    terminate_monitor
    end_monitor

    monitor_event FactionTurnStart empire_west
    and I_TurnNumber = 2
    console_command capture_settlement Rome
    console_command create_unit Rome comitatenses 2 2 1 1
    terminate_monitor
    end_monitor
    I understand line "monitor_event FactionTurnStart empire_west" is incorrect and should be replaced to get script working for AI factions and I would very much appreciate if someone could suggest possible solution

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

    Default Re: An Intermediate Guide to Scripting

    anyone?

  5. #95

    Default Re: An Intermediate Guide to Scripting

    Hi,

    it's possible to use a script for this:

    - Simulate every year a migration from little city to big city/capital in order to give a legion/horde/army recruitement possible only in determined settlement (with particolar recruit's buildind)

    - the same above but only if requested by the player (like the legio raise from Res Gestae mod Script)

    - Simulate the Romanization (or others culture assimilation) by using Loyalty/Religion setting of every city? so we can trigger to add a Roman Citizenship building when we get a >=50% of loyalty/romanized civilian and this building can make possible different recuit sistem..

    - import the Horde army mechanism from BI to RTW 1.5 and modify it to simulate a "Legion recuitment calling" that minus the people from near city in order to get the coscrict legionaire?

    Sorry 4 my bad english.. i'm from Italy

  6. #96
    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

  7. #97

    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

  8. #98
    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



  9. #99

    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

  10. #100
    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



  11. #101

    Default Re: An Intermediate Guide to Scripting

    Thanks for all the help. I appreciate it.
    Anyone who has no fear of death himself can succeed in inflicting it.
    The Prince,
    Machiavelli

  12. #102

    Default Re: An Intermediate Guide to Scripting

    Hi all. I want to write a script to achieve this result: Every time I press the "disband unit" button, it will create a certain unit in a certain city.



    Code:
    script
    
    declare_counter loop
    set_counter loop 1
     
    monitor_event ButtonPressed ButtonPressed disband_unit
    console_command create_unit  Bordeaux "Dismounted Feudal Knights80" 1
    end_monitor
     
    while I_CompareCounter loop = 1
    end_while
    
    end_script
    As you can see, the problem is I don't know what the real button ID of "disband unit". The CA docudemon says it can be found in a file called available_ui_elements.txt. But where can I find it?

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

    Default Re: An Intermediate Guide to Scripting

    You were very close: it's disband_unit_button. Jerome Grasdyke from CA was kind enough to post the contents of this file here.
    The truth is the most valuable thing we have. Let us economize it. - Mark Twain



  14. #104

    Default Re: An Intermediate Guide to Scripting

    Thank u so much! It helps a lot!

  15. #105

    Default Re: An Intermediate Guide to Scripting

    Hello everyone. I m'essaye scripting and hope poster to the right place. That is my problem.
    I managed (with the help of another modder of TWcenter) to a script that damages the shrine battleforge and built a shrine fun when you take the city of genua. Here is the script

    script
    declare_counter loop
    set_counter loop 0

    monitor_event GeneralCaptureSettlement SettlementName Genua
    and CharacterIsLocal
    and not SettlementBuildingExists = shrine_fun

    console_command set_building_health Genua battleforge 0
    console_command create_building Genua shrine_fun

    end_monitor
    while I_compareCounter loop = 0
    end_while
    end_script

    I wish now that the shrine battleforge damage and fun shrine built for all cities that I will take. Do you have any idea?

    Sorry for my English, I am french

  16. #106
    Anything that isn't 'member' Member Squid's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    596

    Default Re: An Intermediate Guide to Scripting

    Replacing the condition SettlementName Genua with TrueCondition should do the trick. You do realise that the script as currently written will give you a shrine_fun even if a settlement doesn't have a battleforge shrine?
    Last edited by Squid; 11-17-2007 at 13:57.

    -Trait/Ancillary/Building Editor

    "Two things are infinite: the universe and human stupidity;
    and I'm not sure about the universe." -----Albert Einstein

  17. #107

    Default Re: An Intermediate Guide to Scripting

    Yes, I know and that troubles me. But in console_command I replaces genua by what?

  18. #108

    Default Re: An Intermediate Guide to Scripting

    excues me? does this command exist here?

    "I_settlement_besiege"??

  19. #109
    Anything that isn't 'member' Member Squid's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    596

    Default Re: An Intermediate Guide to Scripting

    You have now asked this question in three different locations, two here at the org, and one at twcenter. The answer doesn't change no matter how many times you ask, it is still no.

    -Trait/Ancillary/Building Editor

    "Two things are infinite: the universe and human stupidity;
    and I'm not sure about the universe." -----Albert Einstein

  20. #110

    Default Re: An Intermediate Guide to Scripting

    Now that I'm finishing my work with the scripts for lotr-tw, I would like to thank to Epistolary Richard and Myrddraal for all their reseraching about scripts and for this awesome guide. And I would like to share some info that I missed in this guide and could have saved me a lot of time.
    Most of the info is already known by most of the scripters, it is just my list of notes about scripting. I know it is a bit late, and few people still seems working with rtw scripts, but just in case...
    Maybe this post encourage to someone with more knowledge to make a "complete guide to scripting", or at least that other scripters share their tips here.

    IMPLEMENTING
    -The most important when you implement a "monitor_event" is to check the "Trigger requirements:" of the condition you want to use (docudemon_conditions.txt),
    and verify that it is included in the "Exports:" of the event used to trigger the monitor (docudemon_events.txt).
    Conditions starting by "I_" do not need requeriments from the event and so they can be used with if and while statements.
    -The condition RandomPercent can be used without any requeriments, like all conditions starting by I_
    -WorldwideAncillaryExists does not need any Trigger requirements (even when the docudemon_conditions.txt says character_record). I use the next syntaxis and it works as expected (I'm sure):
    Code:
    monitor_event PreBattlePanelOpen WorldwideAncillaryExists one_ring true
       and not WorldwideAncillaryExists lost_ring true
       ;code here
    end_monitor
    -The condition that triggers a "monitor_conditions" can not be changed inside the monitor, so it needs the command "terminate_monitor" to avoid being executed for ever.
    If you want the monitor to be triggered more than once you need to use a "monitor_event".
    Code:
    monitor_conditions I_CompareCounter no = 1
       ;code here executed up to one time until you reload the script
       terminate_monitor
    end_monitor
    -The condition SettlementName uses the Name showed in the strat map (look at ...\text\region and settlement names.txt), not the internal name of the settlement like other commands related to settlements.
    Note it does work with CharacterTurnEnd but does not with CharacterTurnStart (the later does not export the settlement)
    -The event GeneralCaptureSettlement is triggered no matter the type of character: general, named character or family.
    -Moving characters:
    1) move: it uses the standard movement points of the character to try to reach the destiny. So it has to be used during the turn of the character you want to move, and it will not work if the character is far from the target possition (it is equal to select the character and click the right button over the target coordinates). If the character is the commander of his army, all the army will be moved, if not, only the character will move.
    This is the only command that allows you to move a character in and out of a settlement or an army.
    2) console_command move_character: In this case the character is teleported to the target possition, no matter the movement points or the availability of a path, but it does nothing if the character is not the commander of his army, or if the character is inside a settlement.
    If the character is moved over an occupied tile (or over a city), the armies do not merge (nor enter into the city). In stead the moved army stand over them, and then you have to select them using the character browser, because sometimes it is not possible to click them directly.
    This command sometimes makes the moved character invisible. It seems random, but related to characters teleported when they are sieging or hidden in forests, or in a occupied tile. However, this effect dissapears after reload and it do not cause ctds (that I know).
    3) reposition_character: the same than move_character, but it could cause ctds if the character does not exist, and probably in some other cases too, I do not use it.

    SUGGESTIONS
    -When you are at the console command interface, if you press up-arrow you can see all the commands that have been executed previously, in the order they have been launched.
    By using this with a script, you can check if monitors containing a console_command are working, and when they are triggered.
    -use console_command toggle_fow and toggle_perfect_spy to view all the info about armies and settlements in the strat map.

    CTD CAUSES
    People think that scripts causes a lot of ctds and they are sometimes afraid to use them, but in fact there are very few scripting commands that can cause ctds, and most of them are related to mistakes in other files related to advices, buildings, units, trais...
    These are the only ctd causes that I have ever found in my scripts:

    1- advance_advice_thread Advice_Thread: when the thread name is wrong
    2- spawn_army or spawn_character: with a wrong character name or wrong unit name
    3- console_command create_unit Settlement "unit name" 1
    if there is something wrong with the unit
    4- console_command create_building Settlement building_name
    if there is something wrong whit the building
    5- console_command give_ancillary Character ancillary
    if there is something wrong whit the ancillary
    6- console_command give_trait Character Trait 1
    if there is something wrong whit the trait
    7- move or reposition_character cause ctds if the character does not exist (or is died). Better use console_command move_character that can not cause ctds.
    8- to spawn admirals (with ships) could cause ctds when other ships try to attack them, because they are created as if they where land units, in stead of naval units.

    That I know, it does not matter if you use a name that does not exist with other commands like kill_character or move_character, or if the name of the faction is wrong using diplomatic_stance, control, or add_money or the settlement name is wrong when you use add_population, capture_settlement... Only the commands listed above seems to cause ctds when they are wrong.
    However, there are many commands I have never used, so other known ctd causes will be welcome.

    NOT WORKING
    -Prebattle event is not implemented
    -I have been unable to use the console command "event <event_type> <opt:position>", as well as all console commands starting by list_ or test_ (at least using AlexanderTW)

    DESIGNING
    Since counters are not stored when you save and reload the game, we need some workarround to save script's state upon reloads. There are several options, both with pros and cons:
    1)Buildings/plugins: condition checked from an event that exports the settlement. They can be created but not destroyed by script. They can be permanent if hinterland_buildings.
    (console_command set_building_health Settlement building -1 does not destroy it)
    2)Traits: condition checked from an event that exports the character_record. They can be created and removed by script, but they are not permanent since the characters can die.
    3)Ancillaries: can be checked from ANY event using WorldwideAncillaryExists (except from trait triggers). They can be created by script, but the only way to destroy them is to kill the character. As traits, non permanent.

    In our mod, we use a hidden city in the top-right corner with a special character who we can use to save a lot of info about the scripts: using buildings with the city, traits and ancillaries with the character (since we know his name we can kill and respawn him), and even changing and checking his possition in the map.
    Very useful, but only recomended for heavy scripted mods :P

    -To detect the owner for a certain retinue: the retinue should affect one Attribute of the character not affected by any other aspect of the game,
    usually "SenateStanding", "PopularStanding", "Electability" (without senate) or "NavalCommand".
    -The console_command "diplomatic_stance faction1 faction2 allied" does not change the attitude of one faction against the other, just the alliance agreement, so it is a bit useless to avoid attacks from the ai factions.
    -To check that a certain character is placed near a certain position, without using settlements: you can try to move the target character to the target possition in the map, then wait for the movement, and then to check if the character has arrived to the destination, by using "not I_CharacterTypeNearTile" before the movement, and "I_CharacterTypeNearTile" after the movement. If the character has not arrive in this time is because he was not near that tile.
    -The commands "wait" or "campaign_wait" do not stop the campaign, just the scripts, and they should not be used inside a monitor, nor during AI turn.
    Also, it seems that script's variables are not updated correctly while the "wait" is called from the inside of an "if" sentence.


    Some examples from our scripts, that could be useful for someone else

    Code:
    ;**********************************************
    ; FORCE OCCUPY
    ; Avoid the human player to exterminate/enslave while playing certain factions: seleucid, macedon and thrace in this case
    ;**********************************************
    
    script
    
    declare_counter player
    set_counter player 1
    declare_counter scroll
    set_counter scroll 0
    
    monitor_event FactionTurnStart FactionIsLocal
       set_counter player 1
    end_monitor
    monitor_event FactionTurnEnd FactionIsLocal
       set_counter player 0
    end_monitor
    
    monitor_event ScrollOpened ScrollOpened loot_settlement_scroll
       if I_LocalFaction seleucid
          set_counter scroll 1
       end_if
       if I_LocalFaction macedon
          set_counter scroll 1
       end_if
       if I_LocalFaction thrace
          set_counter scroll 1
       end_if
    end_monitor
    
    monitor_conditions I_CompareCounter player = 1
       and I_CompareCounter scroll = 1
       set_counter scroll 0
       select_ui_element loot_settlement_occupy_button
       simulate_mouse_click lclick_down
       simulate_mouse_click lclick_up
    end_monitor
    
    while TrueCondition
    end_while
    
    script
    Code:
    ;**********************************************
    ; GARRISON SCRIPT
    ;**********************************************
    
    script
    
    declare_counter City1Besiged
    set_counter City1Besiged 0
    declare_counter City2Besiged
    set_counter City2Besiged 0
    ;...per settlement
    
    monitor_event FactionTurnEnd FactionType [faction1]
    and I_LocalFaction [faction1]
    
       if I_CompareCounter City1Besiged = 0
          and not I_SettlementOwner [city1] = [faction1]
          if I_CharacterTypeNearTile [faction1] general,  2 x1,y1
             set_counter City1Besiged 1
          end_if
          if I_CharacterTypeNearTile [faction1] family,  2 x1,y1
             set_counter City1Besiged 1
          end_if
       end_if
       if I_CompareCounter City1Besiged = 2
          and not I_CharacterTypeNearTile [faction1] family, 2 x1,y1
          and not I_CharacterTypeNearTile [faction1] general, 2 x1,y1
          set_counter City1Besiged 0
       end_if
    
       if I_CompareCounter City2Besiged = 0
          and not I_SettlementOwner [city2] = [faction1]
          if I_CharacterTypeNearTile [faction1] general,  2 x2,y2
             set_counter City2Besiged 1
          end_if
          if I_CharacterTypeNearTile [faction1] family,  2 x2,y2
             set_counter City2Besiged 1
          end_if
       end_if
       if I_CompareCounter City2Besiged = 2
          and not I_CharacterTypeNearTile [faction1] family, 2 x2,y2
          and not I_CharacterTypeNearTile [faction1] general, 2 x2,y2
          set_counter City2Besiged 0
       end_if
       ;...per settlement
    
    end_monitor
    ;...a monitor per possible local faction
    
    monitor_event SettlementTurnEnd SettlementName [city1-mapname]
       and I_CompareCounter City1Besiged = 1
       and GarrisonSettlementRatio < 0.5
          if I_SettlementOwner [city1] = [faction1]
             console_command create_unit [city1] "unit name" 4
             console_command add_money -2000       
             console_command add_population City -1500
          end_if
          if I_SettlementOwner [city1] = [faction2]
             console_command create_unit [city1] "unit name" 4
             console_command add_money -2000       
             console_command add_population City -1500
          end_if
          set_counter City1Besiged 2
          ;...an if per faction
    end_monitor
    
    monitor_event SettlementTurnEnd SettlementName [city2-mapname]
       and I_CompareCounter City2Besiged = 1
       and GarrisonSettlementRatio < 0.5
          if I_SettlementOwner [city2] = [faction1]
             console_command create_unit [city1] "unit name" 4
             console_command add_money -2000       
             console_command add_population City -1500
          end_if
          if I_SettlementOwner [city2] = [faction2]
             console_command create_unit [city1] "unit name" 4
             console_command add_money -2000       
             console_command add_population City -1500
          end_if
          ;...an if per faction
          set_counter City2Besiged 2
    end_monitor
    ;...a monitor per settlement
    
    
    while TrueCondition
    end_while
    
    end_script
    Code:
    ;**********************************************
    ; CHECK CHARACTER POSSITION
    ; show_me script
    ;**********************************************
    
    ;(This script does work:)
    script 
    
    declare_counter Character_moved
    set_counter Character_moved 0
    
       if not I_CharacterTypeNearTile faction named_character, 0 116,154
          set_counter Character_moved 1
          move Character, 116,154
       end_if
    
       campaign_wait 5
    
       if I_CharacterTypeNearTile germans named_character, 0 116,154
          and I_CompareCounter Character_moved = 1
          console_command give_ancillary Character ancillary
       end_if
    
    end_script
    
    
    ;(This script do the same, but does not work when the wait is placed inside the if... weird)
    script
    
       if not I_CharacterTypeNearTile faction named_character, 0 116,154
          set_counter Character_moved 1
          move Character, 116,154
    
          campaign_wait 5
    
          if I_CharacterTypeNearTile germans named_character, 0 116,154
             console_command give_ancillary Character ancillary
          end_if
       end_if
    
    end_script

    You can find all my scripts into this patch, so people do not need the whole mod if just interested in the scripts:
    http://www.mediafire.com/?uzzwg0nemmz
    Last edited by Bardo; 10-01-2009 at 21:52.

  21. #111
    Axebitten Modder Senior Member Dol Guldur's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,550

    Default Re: An Intermediate Guide to Scripting

    Brilliant addendum Bardo. Thank you for posting - so many discover little things or find the best way of doing things and never both to post their findings which results in much lost time for those who follow the same path.

    Kudos!

    I hope someone does write a "Complete Scripting" guide - though it certainly will not be me ;)
    "One of the most sophisticated Total War mods ever developed..."

  22. #112

    Default Re: An Intermediate Guide to Scripting

    Great addition, indeed. Thx Bardo for that compilation of info!

    Norman Invasion - The fate of England lies in your hands...

    Viking Invasion II - Unite Britain in the best TW campaign ever!

    Gods and Fighting Men: Total War - Enter the Mists of Myth in Ancient Ireland

  23. #113
    CeltiberoRamiroI Member Monkwarrior's Avatar
    Join Date
    Apr 2004
    Location
    Salduie/Caesaraugusta/ Sarakusta/Saragossa
    Posts
    828

    Default Re: An Intermediate Guide to Scripting

    Quote Originally Posted by Bardo
    In our mod, we use a hidden city in the top-right corner with a special character who we can use to save a lot of info about the scripts: using buildings with the city, traits and ancillaries with the character (since we know his name we can kill and respawn him), and even changing and checking his possition in the map.
    Very useful, but only recomended for heavy scripted mods :P
    I use the same system, the hidden city in one corner, but I found some little problems when saving and reloading the saved game. I've solved them (I think so) by using a "tricky" method that requires a double building system.

    I use mainly scripts to issue missions for human player. But in some cases missions are simultaneous, and hence some type of selective detection method had to be implemented.

    The problem was the succession of facts:
    - Event in the player turn: counter signal 1
    - Creation of building in the hidden city: rebel turn, counter signal 2
    - New player turn: message to player and counter signal 3
    - Reloading: detection of the buildings present in hidden city and messaged issued to the player to remember him/her the present mission.

    If game was saved in between those three facts, there were problems with reloaded games, as the player didn't get the reward, or the message for the new mission was missing, etc because in some turn changes the only mark was the counter (lost in saving).

    I don't know if this subject is interesting enough to post the method. If so, I will look for it (I have not the files in this computer) and post it here.

  24. #114

    Default Re: An Intermediate Guide to Scripting

    Since counters can not be saved (this is something very important I missed in my notes...), I try to use them only between events where the player can not save the game, like between FactionTurnStart-CharacterTurnStart, or CharacterTurnEnd-FactionTurnEnd.

    In your case, why don't you create the building in the player's turn:
    - Event in the player turn: counter signal 1 = Creation of building in the hidden city during player turn
    - New player turn: message to player and counter signal 3

    I guess there are some other reason that forces you to have 3 events, in this case I'm interesting in your solution, just paste the code here if you find it.

  25. #115
    CeltiberoRamiroI Member Monkwarrior's Avatar
    Join Date
    Apr 2004
    Location
    Salduie/Caesaraugusta/ Sarakusta/Saragossa
    Posts
    828

    Default Re: An Intermediate Guide to Scripting

    Ok, I will try to explain the question in my poor English.

    My scripts are based in a succession of missions and rewards. But it is important that missions are accomplished in the right order.

    An example of the first mission in the carthaginian campaign.

    I have a counter named switch, that serves only to show the game in which moment we are.
    It starts at 100 (turn 0 or when reloaded)
    Code:
    declare_counter switch
    set_counter switch 100
    but it will be changed in the next turn when the first mission is issued.

    Code:
    	if I_TurnNumber = 0
    
    		wait 1
    		advance_advice_thread Mision1_Cartago_Thread no_dismiss
    				wait 1
    				select_ui_element advisor_portrait_button
    				simulate_mouse_click lclick_down
    				simulate_mouse_click lclick_up
    		set_counter switch 0
    		settlement_flash_start Saguntum
    
    	end_if
    Then we have the conditions for mission success. A first fake building is created at the moment. Because of the overlapping of messages, the success message is issued to the player when the loot settlement scroll is closed.
    Code:
    	monitor_event GeneralCaptureSettlement FactionType carthage
    		and SettlementName Saguntum
    
    		settlement_flash_stop Saguntum
    		console_command add_money 30000
     		console_command diplomatic_stance romans_julii carthage war
    		console_command create_building Aquincum monument_victory_minor1
    		set_counter switch 1
    
    		terminate_monitor
    	end_monitor
    
    	monitor_event ScrollClosed loot_settlement_scroll
    		and I_CompareCounter switch = 1
    
    		advance_advice_thread Exito_Mision1_Cartago_Thread no_dismiss
    			wait 1
    			select_ui_element advisor_portrait_button
    			simulate_mouse_click lclick_down
    			simulate_mouse_click lclick_up
    		set_counter switch 0
    
    		terminate_monitor
    	end_monitor
    In this way it will be sure that we have a fixed point if player saves game in that moment.
    If he follows playing, the script checks if this building exists to issue the message for the second mission.
    Code:
    	monitor_event SettlementTurnStart SettlementName Aquincum
    		and SettlementBuildingExists = monument_victory_minor1
    		and not SettlementBuildingExists = milestone1
    		and not SettlementBuildingExists = monument_victory_minor2
    		and not SettlementBuildingExists = monument_victory_minor3
    		and not SettlementBuildingExists = monument_victory_minor4
    		and not SettlementBuildingExists = monument_victory_major
    		and I_CompareCounter switch = 0
    
    		set_counter switch 11
    
    		terminate_monitor
    	end_monitor
    
    	monitor_event FactionTurnStart FactionType carthage
    		and I_CompareCounter switch = 11
    
    		advance_advice_thread Mision2_Cartago_Thread no_dismiss
    				wait 1
    				select_ui_element advisor_portrait_button
    				simulate_mouse_click lclick_down
    				simulate_mouse_click lclick_up
    		console_command create_building Aquincum milestone1
    		set_counter switch 0
    
    		terminate_monitor
    	end_monitor
    The second fake building prevents this messsage to be issued for a second time.

    Let's see now what happens if the player loads a saved game. The switch counter will be at 100, and in the slave turn the presence of the fake buildings will be checked.
    Code:
    	monitor_event SettlementTurnStart SettlementName Aquincum
    		and not SettlementBuildingExists = monument_victory_minor1
    		and not SettlementBuildingExists = monument_victory_minor2
    		and not SettlementBuildingExists = monument_victory_minor3
    		and not SettlementBuildingExists = monument_victory_minor4
    		and I_CompareCounter switch = 100
    		and I_TurnNumber > 1
    
    		set_counter switch 101
    
    	end_monitor
    
    	monitor_event FactionTurnStart FactionType carthage
    		and I_CompareCounter switch = 101
    
    		advance_advice_thread Recuerdo_Mision1_Cartago_Thread no_dismiss
    				wait 1
    				select_ui_element advisor_portrait_button
    				simulate_mouse_click lclick_down
    				simulate_mouse_click lclick_up
    		settlement_flash_start Saguntum
    		set_counter switch 0
    
    	end_monitor
    As no building is present, the script launches a message to remember the first mission to human player.

    Perhaps there would be a simpler method to do it, but it was the only way I found to prevent missing messages to the human player.

  26. #116

    Default Re: An Intermediate Guide to Scripting

    If there is an easier way, I don't know it. Afaik,The only way to prevent a message from being showed again is to remember it with a building/trait. The same for the mission success, so you need the 2 fake buildings.
    Thank you for explain it, it is very useful to understand how to use buildings to save scripting information.
    Last edited by Bardo; 04-23-2008 at 09:18.

Page 4 of 4 FirstFirst 1234

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