Results 1 to 7 of 7

Thread: How to create a Yes/No event

  1. #1

    Default How to create a Yes/No event

    Hello.

    I'm having trouble to find a tutorial about creating those scripted events that give you the options "Accept" and "Decline". I wanted to create one such event that causes effects both in case of acceptance and in case of refusal (different effects depending on the choice, of course).

    Could any kind soul please show me a sample model of how the full script is supposed to look like? I have managed to create the Yes/No event, but I haven't been able to attach each choice to an effect. As it stands to me, choosing either way has no effects because I can't find a way to associate the Accept and Decline buttons with the effects they are supposed to cause.

    Thanks in advance for any reply.

  2. #2
    Jurand of Cracow's Avatar History and gameplay!
    Join Date
    Oct 2012
    Location
    Cracovia
    Posts
    8,488

    Default Re: How to create a Yes/No event


  3. #3

    Default Re: How to create a Yes/No event

    That tutorial is a bit dated. A modern setup for a basic yes/no script looks more like this:

    Code:
    monitor_event PreFactionTurnStart FactionType england   ;this is a generic turn tracking monitor for england, it is convenient for many scripts to have these monitors for every faction
       set_event_counter faction_turn_england 1
    end_monitor
    ;... monitors for all other faction turns
    
    monitor_event FactionTurnEnd
       set_event_counter faction_turn_england 0
       ;... all other factions turn counters set to 0
    end_monitor
    
    monitor_event ;... event conditions for this random monitor
       ;... conditions and other effects in this random monitor
       set_event_counter yes_no_question_accepted 0   ;game reloaded safety, in case this script previously fired
       set_event_counter yes_no_question_declined 0
       historic_event yes_no_question true factions { england, }   ;send yes/no question only to england, can send to multiple factions or all factions as well
       while I_EventCounter yes_no_question_accepted == 0   ;this is optional, it pauses execution of this monitor until the user answers the yes/no question, can be useful for offering multiple yes/no questions sequentially
       and I_EventCounter yes_no_question_declined == 0
       end_while
       ;... other stuff in this random monitor
    end_monitor
    
    monitor_event EventCounter EventCounterType yes_no_question_accepted  ;yes/no question accepted
    and EventCounter > 0   ;in case the counter ever goes below 0 elsewhere in script
       log always ++++ yes_no_question_accepted ++++   ;this is optional, it puts a note in your script trace log file that the user accepted the event, you can change the text
       :... do stuff for accepted
    end_monitor
    
    monitor_event EventCounter EventCounterType yes_no_question_declined   ;yes/no question declined
    and EventCounter > 0
       log always ++++ yes_no_question_declined ++++
       ;do stuff for declined
    end_monitor
    
    monitor_event GameReloaded   ;game reloaded safety monitor, this is useful for yes/no events in single player (when the user saves and reloads before making a decision) and for all events in multiplayer hotseat (reloading kills all historic_events)
       campaign_wait 0.1   ;without this, the messages won't be sent after the GameReloaded event fires
    
       if I_EventCounter faction_turn_england == 1   ;campaign reloaded on england's turn
       and not I_IsFactionAIControlled england
          if I_EventCounter yes_no_question > 0   ;if the historic event has been given...
          and I_EventCounter yes_no_question_accepted == 0   ;... but the yes/no question has been neither accepted nor declined...
          and I_EventCounter yes_no_question_declined == 0
             historic_event yes_no_question true factions { england, }   ;... then send the option again
          end_if
       end_if
    end_monitor
    These EventCounterType monitors are obviously not the only way to interact with the yes/no event. Since it always generates these _accepted and _declined counters, we can query those wherever we like:

    Code:
    if I_EventCounter yes_no_question_accepted == 1
       ;do stuff
    end_if
    Last edited by Callistonian; May 11, 2021 at 07:25 PM.

  4. #4
    Jadli's Avatar The Fallen God
    Gaming Emeritus

    Join Date
    Dec 2013
    Location
    Czech Republic
    Posts
    8,528

    Default Re: How to create a Yes/No event

    Yea, definitely outdated. Using monitor_conditions is very bad for performance. Later in that thread they propose the modern methods, but most ppl are obviuosly not gonnna browse the thread. Shame the first posts never get updated...

    @Callistonian

    If you use many yes/no events (like over a hundred in my mod lol), not sure if its worth dividing this into numerous monitors just so that a player can save the game before hitting yes/no compared to the turn times due to so many monitors (but obviously would be very good for a HS)

    The usual most optimized way is to probably use a single monitor for this whole thing, i.e., putting the accepted and declined under if chains that are in the same monitor as the historic event, just below the if chains... unless you need to set some pre prequisite events ofc. We usually have some building/settlement ownership requirements, that can be put into the single monitor event as well. But in one I needed to checked a faction leader's trait, so had to divide that into two...
    Last edited by Jadli; May 11, 2021 at 02:28 AM.

  5. #5

    Default Re: How to create a Yes/No event

    That's perfect!

    Thanks all for the responses.

  6. #6
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,125
    Blog Entries
    35

    Default Re: How to create a Yes/No event

    Quote Originally Posted by Jadli View Post
    If you use many yes/no events (like over a hundred in my mod lol), not sure if its worth dividing this into numerous monitors just so that a player can save the game before hitting yes/no compared to the turn times due to so many monitors (but obviously would be very good for a HS)

    The usual most optimized way is to probably use a single monitor for this whole thing, i.e., putting the accepted and declined under if chains that are in the same monitor as the historic event, just below the if chains... unless you need to set some pre prequisite events ofc. We usually have some building/settlement ownership requirements, that can be put into the single monitor event as well. But in one I needed to checked a faction leader's trait, so had to divide that into two...
    The problem with stuffing all decline and accepted if loops into one monitor is the continued command execution unless you 'terminate' it with an event counter increase. Otherwise here is the simplified, single use monitor:
    Code:
        monitor_event whatever takes your fancy
            historic_event samplestuff true
    
            while I_EventCounter samplestuff_accepted = 0
                and I_EventCounter samplestuff_declined = 0
            end_while
    
            if I_EventCounter samplestuff_accepted = 1
                do stuff
                terminate_monitor            ; for good housekeeping
            end_if
            if I_EventCounter samplestuff_declined = 1
                do other stuff
                terminate_monitor            ; for good housekeeping
            end_if
        end_monitor
    The GameReloaded stuff can all go into one monitor without issues.
    Last edited by Gigantus; May 11, 2021 at 01:38 PM.










  7. #7

    Default Re: How to create a Yes/No event

    My GameReloaded monitor only contains the single historic_event as an example but obviously you could put as many in there as you need.

    As for stuffing accept/decline effects into the same monitor as the historic_event, this is another case of function calls vs. hard coding. It depends on what you're doing with your yes/no events - if they only show up once in script, then I can see including the effects immediately after the historic_event in the same monitor. But if the option is given in multiple places in script, you don't want to 'hard code' the accept/decline effects under every instance of the historic_event. In that case, the function call setup is much cleaner and doesn't necessarily need to come at the expense of 2 additional monitors for every yes/no option. You could do something like this instead:

    Code:
    monitor_event EventCounter TrueCondition   ;any event_counter has changed value
       if I_EventCounter yes_no_question_accepted > 0
          set_event_counter yes_no_question_accepted 0   ;prevent infinite looping, you may want to use a different counter for this purpose so the accept/decline counter can be used in script
          ;do stuff for accepted
       end_if
       ;... etc. for other accepted/declined counters
    end_monitor

Posting Permissions

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