Results 1 to 5 of 5

Thread: How-to: Let the player make a yes/no choice in a script

  1. #1
    HouseOfHam's Avatar Primicerius
    Join Date
    Apr 2007
    Location
    Minnesota, USA
    Posts
    3,030

    Default How-to: Let the player make a yes/no choice in a script

    There is more than one way to do this, but the easiest, in my option, is by using the advisor.

    Again, like in my other tutorials, I'm going to use an example to demonstrate how this is done. The example I'm going to use is offering the player a chance to buy a lottery ticket at the beginning of every turn.

    First, we'll need to set up an advice thread. This involves adding stuff to 2 files.

    1. export_descr_advice.txt

    Code:
    ;-----------------------------------------------
    AdviceThread PromptThread
        GameArea Campaign
    
        Item PromptItem1
            Uninhibitable
            Verbosity  0
            Threshold  1
            MaxRepeats  0
            RepeatInterval  1
            Attitude Normal
            Presentation Default
            Title PromptTitle1
            Text PromptText1
    and 2. text\export_advice.txt

    Code:
    {PromptTitle1}Test your luck
    {PromptText1}Would you like to buy a lottery ticket for a chance to win 10k? The cost of the ticket is 1 gold. Click on the advisor portrait to try your luck, or on the dismiss button to decline.
    Now, the code that you'll add to the script:
    Code:
    declare_counter isOfferActive
    
    monitor_event FactionTurnStart FactionIsLocal
    
        advance_advice_thread PromptThread 1
    
        ; This assumes that you have declare_show_me at the top of the script,
        ; which opens the advisor text box for you automatically.
        ; If you do not, uncomment the 2 lines below.
        ;select_ui_element advisor_portrait_button
        ;simulate_mouse_click lclick_up
    
        set_counter isOfferActive 1
    end_monitor
    
    ; Offer accepted
    monitor_event ButtonPressed ButtonPressed advisor_portrait_button
              and I_CompareCounter isOfferActive = 1
    
        console_command add_money -1            ; Cost of the lottery ticket
    
        if RandomPercent > 99
            console_command add_money 10000   ; You won!
        end_if
    
        set_counter isOfferActive 0
    end_monitor
    
    ; Offer rejected
    monitor_event ButtonPressed ButtonPressed advisor_dismiss_button
              and I_CompareCounter isOfferActive = 1
    
        ; greedy bastard! charge him 1 gold anyways!
        console_command add_money -1
    
        set_counter isOfferActive 0
    end_monitor
    And it's that simple!
    Last edited by HouseOfHam; September 02, 2008 at 03:56 PM.
    RTR website/SVN admin

    - Settlement coordinate locator -for RTW/M2TW
    - EDB Validator v1.2.8 (Oct 16, 2012) - for RTW/M2TW
    - RTW scripting tutorials
    - n-turns per year script generator

  2. #2

    Default Re: How-to: Let the player make a yes/no choice in a script

    What about a True or False quiz on ancient history? and if you get it right you get units or something.
    Last edited by Pompeii Soldier; June 15, 2008 at 08:56 AM.

  3. #3
    HouseOfHam's Avatar Primicerius
    Join Date
    Apr 2007
    Location
    Minnesota, USA
    Posts
    3,030

    Default Re: How-to: Let the player make a yes/no choice in a script

    My tutorial only demonstrates the concept. What/where/how you choose to use it is up to you.

    With a little work, implementing a quiz is certainly possible. You'd need to create a separate advice thread for each question and setup a counter so you have a way to tell which question the player was asked and react to their answer appropriately in the two monitors that process the answer.
    RTR website/SVN admin

    - Settlement coordinate locator -for RTW/M2TW
    - EDB Validator v1.2.8 (Oct 16, 2012) - for RTW/M2TW
    - RTW scripting tutorials
    - n-turns per year script generator

  4. #4

    Default Re: How-to: Let the player make a yes/no choice in a script

    Great tuto (yet again) HouseOfHam !

    I'm sorry if i sound like a total noob , but where do i have to put the actual script ?

    Also , is there a trigger needed ?
    Last edited by Killerbee; March 22, 2009 at 02:47 PM.

  5. #5
    HouseOfHam's Avatar Primicerius
    Join Date
    Apr 2007
    Location
    Minnesota, USA
    Posts
    3,030

    Default Re: How-to: Let the player make a yes/no choice in a script

    Looks like you've already found the answer to that.
    RTR website/SVN admin

    - Settlement coordinate locator -for RTW/M2TW
    - EDB Validator v1.2.8 (Oct 16, 2012) - for RTW/M2TW
    - RTW scripting tutorials
    - n-turns per year script generator

Posting Permissions

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