Results 1 to 17 of 17

Thread: Lesson 4

  1. #1
    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 Lesson 4

    Sorry this is so late guys, I have really had a tough time the last 2 weeks and my house is being destroyed by contractors after that monster hail storm.


    This lesson focuses on the user interface, and how to detect when buttons have been pressed or scrolls have been opened or closed. You can then use this to give the player more control over the game. I use methods like this in several of my scripts, most notably my Banking script and my Hire Ancillaries script, but you can use them for anything. Although you can only use the Accept/Decline scroll in Kingdoms, you can still use other scrolls to set counters and and give the player yes/no choices by detecting which buttons they push. As your scripts get more complicated, you will probably be using historic_events yo give the player instructions and choices. However popping that event every time a player clicks TurnEnd gets annoying. Players will get tired of seeing the same message over and over and over. If we tie that to a button press that the player can call anytime he wants we will avoid some of that.

    The first one I will demonstrate is steal_esc_key. We will use that function to pop a historic_event. I have used this a few times to give players instructions on how certain parts of a mod runs. For example if you tie a command to other buttons, you want a place the player can view instructions on how to use your script without having to look it up in your posts about your mod, or reading a manual. Once we write this script, all the player has to do to get instructions for other parts of your script is press the Esc key.
    If you read the Docudemons, you will see the command for steal_esc_key, and you will notice that once the event has happened, it returns the Esc keys default function. This is done so that the player can use the Esc key to bring up the normal options such as Save and Exit. We have to keep this in mind and reset the key a maximum of once per turn. If we reset the Esc key every time someone presses it then we will remove the ability of the player to get to the normal function of the key, which we do not want to do. This script will show the instructions the first time the Esc key is pressed, the second time the Esc key is pressed the player will get the normal options scroll. The script looks like this:

    Code:
    monitor_event FactionTurnStart FactionIsLocal
     steal_esc_key on
    end_monitor
    monitor_event EscPressed
     historic_event instructions
    end_monitor
    Inside our historic event we can write instructions on how the other scroll/buttons are used.



    Now we will do something with the buttons inside the settlement scroll. If we have "Always show settlement details" enabled then there are 6 buttons we can use for custom scripting, and you can also detect when the tax rate is changed. The available buttons are:

    Show Trade Summary - advanced_stats_show_trade_button
    Set capital - advanced_stats_set_as_capital_button
    Locate Settlement - garrison_info_zoom_to_button
    Building Browser - building_browser_button
    Ask Advisor - show_construction_advice_button OR show_recruitment_advice_button depending which tab is selected
    Show Settlement Details - settlement_stats_button

    For other buttons and scrolls check the UI Elements tab of the Ultimate Docudemons. I have written a script and historic_events for each of these buttons that will detect when they are pressed. Put this in your campaign_script and your historic_events file and run the game to make sure everything works and the events fire when you press the buttons.
    historic_events;
    Code:
    {INSTRUCTIONS_BODY}Instructions will go here.
    {INSTRUCTIONS_TITLE}Custom Script Instructions
    {SETTLEMENT_ZOOM_BODY}Settlement Zoom button pressed
    {SETTLEMENT_ZOOM_TITLE}Settlement Zoom
    {SHOW_TRADE_BODY}Show Trade stats button pressed
    {SHOW_TRADE_TITLE}Trade Stats Button
    {SET_CAPITAL_BODY}Set Capital button pressed
    {SET_CAPITAL_TITLE}Set Capital
    {BUILDING_BROWSER_BODY}Building Browser button pressed
    {BUILDING_BROWSER_TITLE}Building Browser
    {ASK_ADVISOR_BODY}Ask Advisor button pressed
    {ASK_ADVISOR_TITLE}Ask Advisor
    {SETTLEMENT_DETAILS_BODY}Show settlement details pressed
    {SETTLEMENT_DETAILS_TITLE}Settlement Details

    And in campaign_script:
    Code:
    monitor_event FactionTurnStart FactionIsLocal
     steal_esc_key on
    end_monitor
    monitor_event EscPressed
     historic_event instructions
    end_monitor
     
    monitor_event ButtonPressed ButtonPressed garrison_info_zoom_to_button
     historic_event settlement_zoom
    end_monitor
    monitor_event ButtonPressed ButtonPressed advanced_stats_show_trade_button
     historic_event show_trade
    end_monitor
    monitor_event ButtonPressed ButtonPressed advanced_stats_set_as_capital_button
     historic_event set_capital
    end_monitor
     
    monitor_event ButtonPressed ButtonPressed building_browser_button
     historic_event building_browser
    end_monitor
    monitor_event ButtonPressed ButtonPressed settlement_stats_button
     historic_event settlement_details
    end_monitor
    monitor_event ButtonPressed ButtonPressed show_construction_advice_button
     historic_event ask_advisor
    end_monitor

    Now for the hard part, figuring out something to do with the buttons. This I will leave largely up to you, as there are so many options, but I will give you some ideas. You can use this to borrow money, for instance you can add_money when the Zoom to settlement button is pressed, and subtract money when building_browser button is pressed. To do something like this your script would look similar to this:

    button pressed Zoom to settlement - add_money 20000
    and I_CompareCounter money_borrowed = 0
    set_counter money_borrowed 1

    button pressed Building Browser
    and I_CompareCounter money_borrowed = 1
    add_money -20000
    set_counter money_borrowed 0
    This would allow the player to borrow money as long as he didnt already have outstanding debt, and allow him to repay the loan. Obviously I didnt fully flesh that out, but you should be able to figure out the rest from there.

    Or you could use it to hire emergency troops, at an outrageous cost.
    settlement under siege
    button pressed Zoom to settlement
    create_unit
    add_money -5000

    Or you could use a combination of buttons pressed in a specific order to do something like create a building. This would help prevent someone from doing something by accident.

    monitor event SettlementSelected
    set_counter stage 0
    button pressed Zoom to settlement
    set_counter stage 1

    button pressed Building Browser
    and I_CompareCounter stage = 1
    set_counter stage 2

    button pressed Settlement Stats Button
    and I_CompareCounter stage = 2
    create building MegaBuilding


    Your task is figure out something cool to do with at least two buttons, and to have instructions on how the script runs tied to the Esc key. This is very open ended and limited only by your imagination and the scripting engine. You can use the buttons on the settlement scroll, or the buttons on the character scroll, or even the buttons on the strat map such as the Finances buttons or mini map zoom in/out buttons.

  2. #2

    Default Re: Lesson 4

    Looks great , and not too hard ! Only 1 question though : How do you let the player make a yes/no choice script ? Or is that something for 'The Kingdoms lesson' ?
    Last edited by Killerbee; August 02, 2009 at 04:45 PM.

  3. #3

    Default Re: Lesson 4

    Alright , i have an idea that i'll also use in a mini-mod of mine the mini-mod will be called Age of Empires 2 : Total War , and i'll use this stuff the implement the Age system (dark age , feudal age , imperial age , ..) I'll try to implement this by letting the player make a yes/no choice , after they pressed 'The Age Button' (will probably be a key that's not used often)

    EDIT : I have just added a way to enable the or disable the 'Esc' feature (i tested it and it works)

    Spoiler Alert, click show to read: 
    Code:
    script
    
    declare_counter disable
    declare_counter ins
    
    monitor_event ScrollAdviceRequested help_scroll
       and I_CompareCounter disable = 0
       and I_CompareCounter ins = 0
    
    historic_event instructionsdis
    set_counter disable 1
    set_counter ins 1
    
    end_monitor
    
    monitor_event FactionTurnEnd FactionIsLocal
       and I_CompareCounter ins = 1
    
    set_counter ins 0
    
    end_monitor
    
    monitor_event ScrollAdviceRequested help_scroll
       and I_CompareCounter disable = 1
       and I_CompareCounter ins = 0
    
    historic_event instructionsen
    set_counter disable 0
    set_counter ins 1
    
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
       and I_CompareCounter disable = 0
    
    steal_esc_key on
    
    end_monitor
    
    monitor_event EscPressed TrueCondition
     and I_CompareCounter disable == 0
    
    historic_event instructions
    
    end_monitor
    
    wait_monitors
    end_script
    Last edited by Killerbee; August 03, 2009 at 04:14 PM.

  4. #4

    Default Re: Lesson 4

    Sorry for the triple post , but it seems like i have no attention when i edit (which is understandable ofcourse ) , but the show_recruitment_advise_button doesn't seem to work . Here's a part of my script :

    Spoiler Alert, click show to read: 
    Code:
    monitor_event ButtonPressed ButtonPressed show_construction_advice_button
    
    add_events
    event counter test_accepted
    event counter test_declined
    date 0
    end_add_events
    historic_event test true
    
    end_monitor
    
    monitor_conditions I_EventCounter test_accepted = 1
    
    console_command add_money england, 30000
    
    end_monitor
    
    monitor_event ButtonPressed ButtonPressed show_recruitment_advice_button
    
     historic_event age
    
    end_monitor


    When i press the advisor button in the building panel , i get a yes/no option which is what i want . But when i press the advisor buton in the recruitment panel , i also get the yes/no option , even though i have made a normal historic event . Anyone knows what could be wrong ?

  5. #5

    Default Re: Lesson 4

    Hmm, the script works fine as written by GED, but the minute I start fiddling with it, every monitor fails. Nothing works. And all I'm adding is one line!
    Son of PW

  6. #6

    Default Re: Lesson 4

    Okay, here’s my work. Instructions image:
    Spoiler Alert, click show to read: 


    And other image.
    Spoiler Alert, click show to read: 


    And script:

    Spoiler Alert, click show to read: 
    Code:
    [
    Code:
    Spoiler Alert, click show to read: 
    monitor_event ButtonPressed ButtonPressed advanced_stats_set_as_capital_button console_command add_money -4000 historic_event set_capital end_monitor monitor_event ScrollClosed ScrollClosed faction_ranking_scroll console_command add_money -1000 historic_event show_ranking end_monitor
    Son of PW

  7. #7
    ♔Jean-Luc Picard♔'s Avatar Domesticus
    Join Date
    Feb 2007
    Location
    North Carolina, USA
    Posts
    2,181

    Default Re: Lesson 4

    sorry about the delay, I should have mine up tomorrow night at the latest.

    It is my great honour to have my poem Farmer in the Scriptorium here.

  8. #8

    Default Re: Lesson 4

    Alright , here's mine :

    Spoiler Alert, click show to read: 
    Code:
    script
    
    declare_counter disable
    declare_counter ins
    declare_counter age
    declare_counter wait
    declare_counter notmore
    
    monitor_event FactionTurnStart FactionIsLocal
    
    historic_event welcome
    
    terminate_monitor
    end_monitor
    
    monitor_event ScrollAdviceRequested help_scroll
       and I_CompareCounter disable = 0
       and I_CompareCounter ins = 0
    
    historic_event instructionsdis
    set_counter disable 1
    set_counter ins 1
    
    end_monitor
    
    monitor_event FactionTurnEnd FactionIsLocal
       and I_CompareCounter ins = 1
    
    set_counter ins 0
    
    end_monitor
    
    monitor_event ScrollAdviceRequested help_scroll
       and I_CompareCounter disable = 1
       and I_CompareCounter ins = 0
    
    historic_event instructionsen
    set_counter disable 0
    set_counter ins 1
    
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
       and I_CompareCounter disable = 0
    
    steal_esc_key on
    
    end_monitor
    
    monitor_event EscPressed TrueCondition
     and I_CompareCounter disable == 0
    
    historic_event instructions
    
    end_monitor
    
    ;;; +++ AGE SYSTEM +++ ;;;
    
    monitor_event ButtonPressed ButtonPressed show_construction_advice_button
       and I_CompareCounter age = 0
    
    add_events
    event counter test_accepted
    event counter test_declined
    date 0
    end_add_events
    historic_event test true
    
    end_monitor
    
    monitor_conditions I_EventCounter test_accepted = 1
     and I_CompareCounter notmore = 0
    
    set_counter age 1
    console_command add_money -5200
    set_counter wait 1
    set_counter notmore 1
    
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
       and I_LocalFaction england
       and I_CompareCounter wait = 1
    
    inc_counter wait 1
    
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
       and I_LocalFaction england
       and I_CompareCounter wait = 2
    
    inc_counter wait 1
    
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
       and I_LocalFaction england
       and I_CompareCounter wait = 3
    
    inc_counter age 1
    
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
       and I_LocalFaction england
       and I_CompareCounter age = 2
    
     historic_event age1
    
    terminate_monitor    
    end_monitor
    
    monitor_event ButtonPressed ButtonPressed show_construction_advice_button
       and I_CompareCounter age = 2
    
    add_events
    event counter cas_accepted
    event counter cas_declined
    date 0
    end_add_events
    historic_event cas true
    
    end_monitor
    
    monitor_conditions I_EventCounter test_accepted = 1
     and I_CompareCounter notmore = 1
    
    console_command add_money -7500
    set_counter wait 1
    inc_counter notmore 1
    
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
       and I_LocalFaction england
     and I_CompareCounter wait = 1
    
    inc_counter wait 1
    
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
       and I_LocalFaction england
     and I_CompareCounter wait = 2
    
    inc_counter wait 1
    
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
       and I_LocalFaction england
     and I_CompareCounter wait = 3
    
    inc_counter wait 1
    
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
       and I_LocalFaction england
     and I_CompareCounter wait = 4
    
    inc_counter wait 1
    
    end_monitor
    
    
    ;; END ;;
    
    monitor_event ButtonPressed ButtonPressed show_recruitment_advice_button
    
     historic_event age
    
    end_monitor
    
    monitor_event ButtonPressed ButtonPressed garrison_info_zoom_to_button
    
     historic_event zoom
    
    end_monitor
    
    
    wait_monitors
    end_script


    All works well , except the recruitment advice button ...

    First of all , i added a way to disable the 'Esc' stuff .. (by pressing the help button in the 'F2 Scroll') Then , i also added an age system like in AoE2 '(by pressing construction help) , and some info bout the age system when pressing the 'Zoom to location' button .
    Last edited by Killerbee; August 15, 2009 at 04:58 PM.

  9. #9
    ♔Jean-Luc Picard♔'s Avatar Domesticus
    Join Date
    Feb 2007
    Location
    North Carolina, USA
    Posts
    2,181

    Default Re: Lesson 4

    For some reason I can't get my steal_esc_key on to fire. I'm not sure of its compatibility with the counter which is the only change I made since it last worked.

    Spoiler Alert, click show to read: 
    Code:
    ;;; Lesson 4
    
    declare_counter loan
    set_counter loan 0
    declare_counter esc_key
    set_counter esc_key 0
    
    monitor_event FactionTurnStart FactionIsLocal
     and I_CompareCounter esc_key = 0
     steal_esc_key on
    end_monitor
    
    monitor_event EscPressed
     historic_event escape
    end_monitor
    
    monitor_event ButtonPressed ButtonPressed settlement_stats_button
     and I_CompareCounter loan = 0
     historic_event debt
     add_money 40000
     add_money 10000
     set_counter loan 1
    end_monitor
    
    monitor_event ButtonPressed ButtonPressed settlement_stats_button
     and I_CompareCounter loan = 1
     historic_event debt_free
     add_money -40000
     add_money -10000
     set_counter loan 0
    end_monitor
    
    monitor_event ButtonPressed ButtonPressed garrison_info_zoom_to_button
     if I_CompareCounter esc_key = 0
      set_counter esc_key 1
     end_if
     
     if I_CompareCounter esc_key = 1
      set_counter esc_key 0
     end_if  
    end_monitor

    It is my great honour to have my poem Farmer in the Scriptorium here.

  10. #10

    Default Re: Lesson 4

    Well , i'm not sure , but i think the thing is that i think you have a loop going on , not sure though :

    Code:
    monitor_event ButtonPressed ButtonPressed garrison_info_zoom_to_button
     if I_CompareCounter esc_key = 0
      set_counter esc_key 1
     end_if
     
     if I_CompareCounter esc_key = 1
      set_counter esc_key 0
     end_if  
    end_monitor
    The thing is , the first 'if"' bit is checked , as the counter is 0 . However , when the counter is 1 , the second 'if' bit will react , by setting the counter to 0 again . So it's just a loop afaik ..
    Last edited by Killerbee; August 20, 2009 at 02:17 PM.

  11. #11
    ♔Jean-Luc Picard♔'s Avatar Domesticus
    Join Date
    Feb 2007
    Location
    North Carolina, USA
    Posts
    2,181

    Default Re: Lesson 4

    ahh. i see now. I need to make 2 separate parts for that.

    It is my great honour to have my poem Farmer in the Scriptorium here.

  12. #12

    Default Re: Lesson 4

    I think so , but really , i'm not sure .. i'm sure AL or GED knows a solution

  13. #13

    Default Re: Lesson 4

    Sorry for not posting lesson 4 yet I have been sorting out my computer. I will try to post lesson 4 this week.

  14. #14

    Default Re: Lesson 4

    Finally my first part of the lesson:
    Spoiler Alert, click show to read: 
    Code:
    monitor_event ButtonPressed ButtonPressed show_bodygaurd_unit_button
    if I_SettlementUnderSiege Caerllion
    historic_event emergency_troops
    create_unit Caerllion, Geffylwyr, num 4, exp 1, arm 0, wep 0
    create_unit Caerllion, Saethwyr, num 3, exp 2, arm 0, wep 0
    create_unit Caerllion, Gwffwyr, num 2, exp 2, arm 0, wep 0
    console_command add_population Caerllion -344
    console_command add_money gwent, -6000
    end_if
    terminate_monitor
    end_monitor


    Event pic:
    Spoiler Alert, click show to read: 







    I will post the other tomorrow or later on.
    EDITED:
    Another script:
    Spoiler Alert, click show to read: 
    Code:
    monitor_event ButtonPressed ButtonPressed building_browser_button
    if I_SettlementOwner Caerllion = gwent
    create_unit Caerllion, Geffylwyr, num 2, exp 1, arm 0, wep 0
    console_command add_money gwent, -1500
    console_command add_population Caerllion -120
    end_if
    historic_event build
    end_monitor
    Last edited by Icedie El Guaraní; September 03, 2009 at 06:07 PM. Reason: Finish lesson 4!!
    Contribuitor IBIICB-WOTN-Modeler-Scripter


  15. #15

    Default Re: Lesson 4

    Not so sure , but i don't think the 'if' is needed , couldn't you just do the following :

    Code:
    monitor_event ButtonPressed ButtonPressed show_bodygaurd_unit_button
     and I_SettlementUnderSiege Caerllion
    
    historic_event emergency_troops
    create_unit Caerllion, Geffylwyr, num 4, exp 1, arm 0, wep 0
    create_unit Caerllion, Saethwyr, num 3, exp 2, arm 0, wep 0
    create_unit Caerllion, Gwffwyr, num 2, exp 2, arm 0, wep 0
    console_command add_population Caerllion -344
    console_command add_money gwent, -6000
    
    terminate_monitor
    end_monitor

  16. #16

    Default Re: Lesson 4

    Thanks but this was my idea, so only 1 faction gets the bonus.
    Spoiler Alert, click show to read: 
    Code:
    monitor_event ButtonPressed ButtonPressed show_bodygaurd_unit_button
    and I_SettlementOwner Caerllion = gwent
    if I_SettlementUnderSiege Caerllion
    historic_event emergency_troops
    create_unit Caerllion, Geffylwyr, num 4, exp 1, arm 0, wep 0
    create_unit Caerllion, Saethwyr, num 3, exp 2, arm 0, wep 0
    create_unit Caerllion, Gwffwyr, num 2, exp 2, arm 0, wep 0
    console_command add_population Caerllion -344
    console_command add_money gwent, -6000
    end_if
    terminate_monitor
    end_monitor
    Contribuitor IBIICB-WOTN-Modeler-Scripter


  17. #17

    Default Re: Lesson 4

    Another script:
    Spoiler Alert, click show to read: 
    Code:
    monitor_event ButtonPressed ButtonPressed building_browser_button
    if I_SettlementOwner Caerllion = gwent
    create_unit Caerllion, Geffylwyr, num 2, exp 1, arm 0, wep 0
    console_command add_money gwent, -1500
    console_command add_population Caerllion -120
    end_if
    historic_event build
    end_monitor


    The event is meant to appear in all settlements to advice you that this can be applied only to your capital, in this case Caerllion.
    Last edited by Icedie El Guaraní; September 01, 2009 at 07:44 AM.

Posting Permissions

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