Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: Lesson 2 - Difficulty/Spawning Army Scripts

  1. #1

    Default Lesson 2 - Difficulty/Spawning Army Scripts

    Scripting Lesson 2

    I would like to start this lesson with Difficulty scripting, first to recap over our first lesson. An Event is an instruction that is fired when a condition is meet, this it turn fires a command.

    the basics of a script

    Spoiler Alert, click show to read: 


    monitor_event <event> logical operator <condition>
    logical operator <condition>

    command

    end_monitor



    at the the top of our script we are going to declare some counters, now remember what i said about counters Medieval II or any other TW game for that

    matter does not allow us to define variables, so the best we have is a counter which are strings (a fancy word for characters) a string can be made up of letters or numbers.

    so lets set our that counter up

    type:

    declare_counter difficulty
    declare_counter difficulty_easy
    declare_counter difficulty_medium
    declare_counter difficulty_hard
    declare_counter difficulty_very_hard

    Spoiler Alert, click show to read: 




    These will be set into the memory when the campaign as started, now with our counters we will need to set up an event, so lets type

    monitor_event FactionTurnStart FactionIsLocal
    and CampaignDifficulty = easy

    set_event_counter difficulty_easy 1
    set_event_counter difficulty_medium 0
    set_event_counter difficulty_hard 0
    set_event_counter difficulty_very_hard 0

    terminate_monitor
    end_monitor

    so lets run thought what we have so far we have declared 5 counters, and we have an Event set to trigger on a factions turn start
    but this is not just any faction the condition will wait for the local faction (human player) to take control, hence "FactionIsLocal" and the second

    condition is that the game difficulty at the start of the campaign where set to easy.

    if both of these conditions are to be true then our counters are set notice the keyword "set_event_counter" this is always follow by a declared counter.

    difficulty_easy counter will be set to the value of one, the others to zero.
    now we have our counter we can use this to influence how the game runs

    If you need help on where to place the script it would go under Mointers
    Spoiler Alert, click show to read: 




    to do this we are going to expand our script some more we will add a new event with a condition of checking if the the local player is england
    if the player is england this event will be fired and then a check is made by the IF statement. The IF will return true if the difficulty is set on easy

    and in turn will increment the Kings purse with an extra 500 bigs ones so hows that!

    monitor_event FactionTurnStart FactionIsLocal
    and CampaignDifficulty = easy


    set_event_counter difficulty_easy 1
    set_event_counter difficulty_medium 0
    set_event_counter difficulty_hard 0
    set_event_counter difficulty_very_hard 0

    terminate_monitor
    end_monitor

    monitor_event FactionTurnStart FactionIsLocal
    and FactionType england

    if I_CompareCounter difficulty_easy = 1

    increment_kings_purse england 500

    end_if

    terminate_monitor
    end_monitor


    another thing to noticed here here is the terminate moniter why is this here? well we only want the script to fire once in the game
    if you did remove this on every turn of england would receive a bonus of 500! now we cannot have that can we =D

    End_monitor as expalined before tells the game this moniter as finished and is awaiting for the next one to be triggered.

    this what your campaign script should look like now.
    Spoiler Alert, click show to read: 





    if you have any questions at this point please ask!

    spawn Characters and armies

    I now attempt to explain and show you how to spawn an army, the syntax is faction type <faction> and <character description> which
    describes the units which are to be spawned much like in the desrc_strat.

    spawn_army <faction> <character description>

    spawn_army

    faction england
    character Edward Cracker, named character, age 25, x 73, y 28
    traits GoodCommander 2
    unit NE Bodyguard exp 1 armour 0 weapon_lvl 0
    end

    the X, Y are the coordinates of where the army will be spawned its perfectly illegal to spawn an army into the ocean, so don't worry to much about conditions if you want to find the coordinates on the map bring up the console window and type in show_cursorstat and press
    enter.

    a note spawning generals here will no be placed into a family tree its not possible in case anybody where wondering...

    now to put the theory into practice will write an event which will spawn the AI some reinforcements when a settlement is captured

    start with the usual monitor_event and the condition is settlementName < settlement> is Paris and the second
    condition the human player must be england.

    monitor_event GeneralCaptureSettlement SettlementName Paris
    and FactionType england

    spawn_army

    faction france
    character Godfrey Mauvoisin, named character, age 35, x 99, y 124
    traits GoodCommander 2
    unit NE Bodyguard exp 1 armour 0 weapon_lvl 0
    end

    terminate_monitor
    end_monitor

    Spoiler Alert, click show to read: 





    Faction debt money scripts


    This weeks assignment

    Basic:

    The Assignment task is to spawn an army anywhere on the map and then increment that factions Kings purse to support the newly spawned army.

    Advanced:

    based on the basic question modifily your existing code to give more units if the game is set to easy or hard.

    I.E

    if the game is set to easy spawn 5 units if the game is set to normal spawn 3 units, if the game is set to hard 1 unit. The best scripts will be placed into the TWC-U gallery.


    if you need help getting started pm me.
    Last edited by J@mes; August 04, 2008 at 01:24 PM.


  2. #2
    Y_filip's Avatar Tiro
    Join Date
    Mar 2008
    Location
    in the galaxy far-far away
    Posts
    212

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Great tutorial !!!!!!!!!!
    [SIGPIC][/SIGPIC]

  3. #3

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Cool beans. I'll print this out and get started on it Monday.

    Devoirs The Empress
    The Lordz Modding Collective
    "The LMC expects every modder to do his Duty" - not by Lord Nelson
    "Blow it out your arse." - Halie Satanus
    The Eagle Standard

  4. #4
    sinople's Avatar These Romans are crazy!
    Join Date
    Apr 2007
    Location
    France
    Posts
    2,447

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    I'm reading this looong tutorial

  5. #5
    sinople's Avatar These Romans are crazy!
    Join Date
    Apr 2007
    Location
    France
    Posts
    2,447

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Sorry for the dubble post
    if you have any questions at this point please ask!
    Yes I have one.
    Here is my script :
    Code:
    ;------------------- SCRIPTING CLASS EVENTS LESSON 2 -------------------;    
            ;-- Difficulty Script --
     
        monitor_event FactionTurnStart FactionIsLocal
            and CampaignDifficulty = very_hard
                    set_event_counter difficulty_easy 0
                    set_event_counter difficulty_medium 0
                    set_event_counter difficulty_hard 0
                    set_event_counter difficulty_very_hard 1
    
                terminate_monitor
        end_monitor
    
        monitor_event FactionTurnStart FactionIsLocal
            if I_CompareCounter difficulty_very_hard = 1
                    increment_king_purse france 500
                    increment_king_purse scotland 500
            end_if
                terminate_monitor
        end_monitor
     
    ;END---------------- SCRIPTING CLASS EVENTS -------------------;
    I want to give all factions (except the faction played) 500. Can I use a command like this :
    Code:
                     increment_king_purse NotFactionIsLocal 500
    Thanks


    Edit :
    the X, Y are the coordinates of where the army will be spawned its perfectly illegal to spawn an army into the ocean, so don't worry to much about conditions if you want to find the coordinates on the map bring up the console window and type in show_cursorstat and press
    enter.

    Even in a ship ?


    Last question is it possible to put a command :

    and FactionIsMiddleEastern ?
    Or Not Catholic

    For instance :
    Code:
        monitor_event FactionTurnStart FactionIsLocal
            and FactionIsMiddleEastern
    or

    Code:
        monitor_event FactionTurnStart FactionIsLocal
            and Not Catholic
    Thanks
    Last edited by sinople; August 06, 2008 at 12:26 PM.

  6. #6
    sinople's Avatar These Romans are crazy!
    Join Date
    Apr 2007
    Location
    France
    Posts
    2,447

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Another question : I tried to put my script on vanilla, with io.file_first, but it doesn't work (although it works on retrofit). Do you have an idea ?

  7. #7

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Quote Originally Posted by sinople View Post
    Sorry for the dubble post


    Yes I have one.
    Here is my script :
    Code:
    ;------------------- SCRIPTING CLASS EVENTS LESSON 2 -------------------;    
            ;-- Difficulty Script --
     
        monitor_event FactionTurnStart FactionIsLocal
            and CampaignDifficulty = very_hard
                    set_event_counter difficulty_easy 0
                    set_event_counter difficulty_medium 0
                    set_event_counter difficulty_hard 0
                    set_event_counter difficulty_very_hard 1
    
                terminate_monitor
        end_monitor
    
        monitor_event FactionTurnStart FactionIsLocal
            if I_CompareCounter difficulty_very_hard = 1
                    increment_king_purse france 500
                    increment_king_purse scotland 500
            end_if
                terminate_monitor
        end_monitor
     
    ;END---------------- SCRIPTING CLASS EVENTS -------------------;
    I want to give all factions (except the faction played) 500. Can I use a command like this :
    Code:
                     increment_king_purse NotFactionIsLocal 500
    Thanks
    no the only parameters it will take is a faction.

    Quote Originally Posted by sinople View Post
    Edit :



    Even in a ship ?
    yes ships like any other object will have an x,y you can also place an arm onto a spawned scripting giving the same X/Y

    Quote Originally Posted by sinople View Post

    Last question is it possible to put a command :

    and FactionIsMiddleEastern ?
    Or Not Catholic

    For instance :
    Code:
        monitor_event FactionTurnStart FactionIsLocal
            and FactionIsMiddleEastern
    or

    Code:
        monitor_event FactionTurnStart FactionIsLocal
            and Not Catholic
    Thanks
    you can use Religion catholic condition.


  8. #8
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Sorry for not responding here yet, I'll submit mine tomorrow once I (hopefully) have access to internet on my computer again, depending on if the new power supply fixes the issue. Seems with a two week deadline, would be the 16th(PST), so hopefully can meet that if no issues later tonight with this power supply.

    Cheers,
    Augustus

  9. #9

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    no problem AL.


  10. #10

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Indeed, sorry Professor,

    I will try to get it to you this evening without too many bugs. :S Good thing it is only one text file we are messing with thus far.

    Devoirs The Empress
    The Lordz Modding Collective
    "The LMC expects every modder to do his Duty" - not by Lord Nelson
    "Blow it out your arse." - Halie Satanus
    The Eagle Standard

  11. #11

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Empress Meg I know how busy you are doing a good job with the ES No to worry i will not be able to test assignment work until Monday anyway, if you need help with the script you can PM or post it here and i will help you with it.


  12. #12

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Has anyone been able to get their scripts working?
    Last edited by Empress Meg; August 15, 2008 at 11:19 PM.
    The Lordz Modding Collective
    "The LMC expects every modder to do his Duty" - not by Lord Nelson
    "Blow it out your arse." - Halie Satanus
    The Eagle Standard

  13. #13
    GrnEyedDvl's Avatar Liberalism is a Socially Transmitted Disease
    Artifex Technical Staff

    Join Date
    Jan 2007
    Location
    Denver CO
    Posts
    23,844
    Blog Entries
    10

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    I am going to jump in here with a few comments.

    Empress Meg:
    Does your mod folder work? If it does then simple scripts should run just fine. Copy and paste a working script from above to test. If it works ok then yours probably has a typo somewhere. Start a game as England, and put this in your script all by itself.

    Code:
    monitor_event FactionTurnEnd FactionIsLocal
    add_money england 20000
    end_monitor
    This should add 20k to England at the end of every turn, if it does then your mod folder and campaign_script are working fine. The above is for Kingdoms, if you are using M2 then use:
    Code:
    monitor_event FactionTurnEnd FactionIsLocal
    console_command add_money england, 20000
    end_monitor

    Sinople:
    You cannot make up your own conditions. You have to use the ones from the docudemons, and you have to use them with the export and trigger requirements they are designed for. When you need a condition such as a religion, do a text search inside the docudemons for "religion". You will find the FactionReligion condition, so the answer to the question you asked J@mes looks like this:
    Code:
    monitor_event FactionTurnStart FactionIsLocal
         and not FactionReligion catholic
    other code
    end_monitor


    Exports and Trigger Requirements explained:
    First I suggest all of you either download the official docudemons or my Ultimate Docudemons.

    A sample Event, check the Exports line:
    Identifier: CharacterTurnEnd
    Event: A Character has finished its turn
    Exports: nc_character_record, character_record, faction, region_id, character_type, settlement
    Class: ET_CHARACTER_TURN_END


    A sample Condition, check the Trigger Requirements line:
    Identifier: IsRegionOneOf
    Trigger requirements: region_id
    Parameters: list of regions given by label or number
    Sample use: IsRegionOneOf 0 Caribbean_Isles
    Description: Test is a region in given region list?
    Battle or Strat: Strat
    Class: IS_REGION_ONE_OF
    In order to use a condition, the event that you are using must export the trigger_requirement. For example if you use the FactionTurnEnd event and inside that event you try to check if a character HasAncType, your script will fail because HasAncType has a trigger requirement of character_record and FactionTurnEnd does not export this.

    The I_Conditions are the exception to this rule, they do not have trigger_requirements, so you can use them inside any event as long as you get the syntax correct.
    Last edited by GrnEyedDvl; August 16, 2008 at 01:19 AM.

  14. #14

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Hi there GrnEyedDvl

    I had the first lesson's work going no problem a few weeks ago. I don't recall using a mod folder last time, but then again I have everything unpacked so I might have used one without knowing in all of the clutter.

    I did install a couple of things in between now and then so who knows what I broke. I've deleted everything last night in a fit of rage ( ) and am slowly re-installing M2TW and Kingdoms. Just to be sure, I need to put the script text in the mod folder (like your barebones one for instance) or in the unmodded imperial_camp folder? Do I need to "unpack" before I do this?

    Thanks!
    The Lordz Modding Collective
    "The LMC expects every modder to do his Duty" - not by Lord Nelson
    "Blow it out your arse." - Halie Satanus
    The Eagle Standard

  15. #15
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Quote Originally Posted by Empress Meg View Post
    Hi there GrnEyedDvl

    I had the first lesson's work going no problem a few weeks ago. I don't recall using a mod folder last time, but then again I have everything unpacked so I might have used one without knowing in all of the clutter.

    I did install a couple of things in between now and then so who knows what I broke. I've deleted everything last night in a fit of rage ( ) and am slowly re-installing M2TW and Kingdoms. Just to be sure, I need to put the script text in the mod folder (like your barebones one for instance) or in the unmodded imperial_camp folder? Do I need to "unpack" before I do this?

    Thanks!
    Yes, you need to unpack the files because when the game checks the mod folder it will then look for the unpacked files in the main folder. I could be wrong, it could still work, but unpacking shouldn't hurt your installation if you're adding the proper .cfg parameters.

    You also need to insure that the campaign_script.txt is in the mod folder, because the base folder won't let you make changes to the preferences, so from my experience any script changes don't take effect. It needs to be in the same location as in the main folder, within the mod folder. So...

    Medieval II Total War\mods\BareBones\data\world\maps\campaign\imperial_campaign\campaign_script.txt

    (That's from memory, any typos to file directory name, use the vanilla names)

    I also believe you need all of the files in maps\base and maps\campaign\imperial_campaign in the mod folder for it to work. And if you are using kingdoms, you need the files retrofit provides(or barebones, unsure) which allow kingdoms features in the main campaign. I believe the maps and the kingdoms revert files are the bare minimum needed in the mod folder in order to run the campaign_script. For me it seems to work by just editing the one in Retrofit, so that setup is suitable for script variation.

    Cheers,
    Augustus

  16. #16
    GrnEyedDvl's Avatar Liberalism is a Socially Transmitted Disease
    Artifex Technical Staff

    Join Date
    Jan 2007
    Location
    Denver CO
    Posts
    23,844
    Blog Entries
    10

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Meg, you can make changes without using a mod folder, but I caution against it. If you are going to use the vanilla files, be sure to make backups of them.

    Retrofit or barebones either one are acceptable.

  17. #17

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Okay, I got barebones installed and am unpacking M2TW now. I hope to have something to show shortly, that is if it works even.

    Edit_ Okay I have the simple add money code working and even add money when a building is built but if I try anything else it seems to do nothing. For instance:

    Code:
    ;
    ; Campaign script
    ;
    script
            ; ---------------------
            ; counters
    		
            declare_counter Opened_Faction_Overview_Scroll
    		declare_counter Opened_Settlement_Scroll
    		declare_counter mongols_sarkel
    		declare_counter mongols_yerevan
    		declare_counter mongols_baghdad
    		declare_counter timurids_sarkel
    		declare_counter timurids_yerevan
    		declare_counter timurids_baghdad
    		
    		declare_counter difficulty
    		declare_counter difficulty_easy
    		declare_counter difficulty_medium
    		declare_counter difficulty_hard
    		declare_counter difficulty_very_hard
    
            
            ; ---------------------
            ; start up
    
            freeze_faction_ai aztecs	
    
    	;-----------------Class------------------------
    	;monitors
    
    	;--Difficulty Script|
    	monitor_event FactionTurnStart FactionIsLocal
    		and CampaignDifficulty = easy
    
    		set_event_counter difficulty_easy 1
    		set_event_counter difficulty_medium 0
    		set_event_counter difficulty_hard 0
    		set_event_counter difficulty_very_hard 0
    
    	terminate_monitor
    	end_monitor
    
    	monitor_event FactionTurnStart FactionIsLocal
    		and FactionType england
    
    		if I_CompareCounter difficulty_easy = 1
    
    		increment_kings_purse england 15000 
    
    		end_if
    
    	terminate_monitor
    	end_monitor
    	
    
    
    	;-----------------Class Finis------------------
    That does nothing. Yes I selected E/E on the selection screen.
    I've tried different cash amounts like the shown 500, but nothing.
    I have the 4 Kingdoms mods installed.
    I'm using the Barebones mod with the camp_script inside that mod folder.
    As an aside, how do I get this cool colour-coded log ingame?
    Last edited by Empress Meg; August 16, 2008 at 11:37 PM.
    The Lordz Modding Collective
    "The LMC expects every modder to do his Duty" - not by Lord Nelson
    "Blow it out your arse." - Halie Satanus
    The Eagle Standard

  18. #18
    GrnEyedDvl's Avatar Liberalism is a Socially Transmitted Disease
    Artifex Technical Staff

    Join Date
    Jan 2007
    Location
    Denver CO
    Posts
    23,844
    Blog Entries
    10

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Simple mistake Meg. Dont worry we all make em

    Here you set an event_counter:
    set_event_counter difficulty_easy 1

    And here you are checking a normal counter:
    if I_CompareCounter difficulty_easy = 1

    You need to check an event_counter not a counter:
    if I_EventCounter difficulty_easy = 1

    EDIT: Forgot to add something. That color coding you see is something I built for Notepad++. The thread is here:
    http://www.twcenter.net/forums/showt...hlight=Notepad
    Last edited by GrnEyedDvl; August 17, 2008 at 11:19 AM.

  19. #19

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Oh thank you.

    Gosh, this is not like proofreading at all. My literary training has nothing on this. Thanks GrnEyedDvl!
    The Lordz Modding Collective
    "The LMC expects every modder to do his Duty" - not by Lord Nelson
    "Blow it out your arse." - Halie Satanus
    The Eagle Standard

  20. #20
    GrnEyedDvl's Avatar Liberalism is a Socially Transmitted Disease
    Artifex Technical Staff

    Join Date
    Jan 2007
    Location
    Denver CO
    Posts
    23,844
    Blog Entries
    10

    Default Re: Lesson 2 - Difficulty/Spawning Army Scripts

    Welcome, and no its not like proofreading. A logic class helps more. Each step has to be done properly, or the entire script fails.

    Also another suggestion is that when you are learning to script, emtpy the entire campaign_script (make a backup) and start with a blank sheet.

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

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