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

Thread: How does RandomPercent function?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default How does RandomPercent function?

    Can anyone clarify how RandomPercent functions, please! I know that it takes a number between 0 and 100, but when does the engine (BI) "roll the dice"? If I have RandomPercent inside a monitor, does it pick a separate number for each RandomPercent line, or is there one random number per monitor, or one random number per turn, or something else?

    This is important e.g. for defining some options within monitors.

    If I want for example two optional messages to be displayed after an event (defined in a monitor), can I do the following?

    Code:
    monitor_event [event]
              [conditions]
                          if RandomPercent > 50
                          advance_advice_thread [message1]
                          if RandomPercent <= 50
                          advance_advice_thread [message2]
                          end_if
                    end_if
    end_monitor
    If the number is picked every time, then both messages 1 and 2 may be displayed. But if it is picked only once during a monitor, or once during a turn, messages 1 and 2 are mutually exclusive - just as I would want them to be. Help, anyone?

    And please, confirm that the syntax above is correct! Or should the first end_if be in front of the second if like this?

    Code:
    monitor_event [event]
              [conditions]
                          if RandomPercent > 50
                          advance_advice_thread [message1]
                          end_if
                          if RandomPercent <= 50
                          advance_advice_thread [message2]
                          end_if
    end_monitor

  2. #2
    Squid's Avatar Opifex
    Patrician Artifex Technical Staff

    Join Date
    Feb 2007
    Location
    Frozen waste lands of the north
    Posts
    17,751
    Blog Entries
    3

    Default Re: How does RandomPercent function?

    Depends on what you're trying to achieve. For the first one, the first message will show 50% of the time and the second message will show 50% of the time the first message shows. The second one each message will appear 50% of time, the difference is that the second message can appear without the first one (and will do so 25% of the time).

    First: 50% no message, 25% first message, 25% first & second message
    Second: 25% no message, 25% first message, 25% first & second message, 25% second message
    Under the patronage of Roman_Man#3, Patron of Ishan
    Click for my tools and tutorials
    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." -----Albert Einstein

  3. #3

    Default Re: How does RandomPercent function?

    Quote Originally Posted by Squid View Post
    Depends on what you're trying to achieve. For the first one, the first message will show 50% of the time and the second message will show 50% of the time the first message shows. The second one each message will appear 50% of time, the difference is that the second message can appear without the first one (and will do so 25% of the time).

    First: 50% no message, 25% first message, 25% first & second message
    Second: 25% no message, 25% first message, 25% first & second message, 25% second message
    Oh, now I got it, thanks Squid! But is there any way of making the following:

    X% first message, (100-X)% second message, i.e. to make them dependent on each other?

  4. #4
    Squid's Avatar Opifex
    Patrician Artifex Technical Staff

    Join Date
    Feb 2007
    Location
    Frozen waste lands of the north
    Posts
    17,751
    Blog Entries
    3

    Default Re: How does RandomPercent function?

    Yes, its a bit convoluted though.

    Code:
    declare_counter event1_fired
    
    monitor event [event] [first condition]
        [conditions]
            set_couner event1_fired 0
            if RandomPercent <= X
                stuff for event 1
                set_counter event1_fired 1
            end
            if I_CompareCounter event1_fired 0
                stuff for event 2
            end
    end_monitor
    A very complicated way to do an if . . . else . . . end block.

    end_monitor
    Under the patronage of Roman_Man#3, Patron of Ishan
    Click for my tools and tutorials
    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." -----Albert Einstein

  5. #5

    Default Re: How does RandomPercent function?

    Quote Originally Posted by Squid View Post
    A very complicated way to do an if . . . else . . . end block.
    Clever, thanks! +rep

  6. #6

    Default Re: How does RandomPercent function?

    OK, many things resolved, but now have yet another question about this same topic. Some help would again much appreciated!

    I would like to add a random number to a counter during each turn when certain conditions are met. The numbers would be mostly small, but occasionally larger. I haven't been able to come up with any other option than using multiple ifs where large numbers are added with smaller likelyhood and smaller numbers more often. So something like this:

    Code:
    declare_counter cumulative_counter
    monitor_event [some event here]
    [conditions] if RandomPercent > 90
    inc_counter cumulative_counter 100
    end_if if RandomPercent > 50
    inc_counter cumulative_counter 10
    end_if if RandomPercent > 20
    inc_counter cumulative_counter 2
    end_if if RandomPercent > 10
    inc_counter cumulative_counter 1
    end_if
    end_monitor
    Now it would be important for me to understand how many times "the dice is thrown" during this monitor. Is it thrown only once or once for each RandomPercent? Because if it is thrown only once, then the only "large" number that can be added to the counter is 113 (if the first randompercent is more than 90, then the other conditions are met as well). If the random number is selected every time separately, then adding e.g. 100, 101, 102, 103, 110, 111, 112, 113 are all possible large numbers.

    Any idea how it works?

    And please, if you can think of a better way to achieve what I'm trying to do, please let me know!

  7. #7

    Default Re: How does RandomPercent function?

    Quote Originally Posted by Squid View Post
    Yes, its a bit convoluted though.

    Code:
    declare_counter event1_fired
    
    monitor event [event] [first condition]
        [conditions]
            set_couner event1_fired 0
            if RandomPercent <= X
                stuff for event 1
                set_counter event1_fired 1
            end
            if I_CompareCounter event1_fired 0
                stuff for event 2
            end
    end_monitor
    A very complicated way to do an if . . . else . . . end block.

    end_monitor
    Hi guys,

    could you Squid or someone else confirm that this indeed works? I've tried the following, but always get the second message, although have 99 % probability for first one.

    Code:
    declare_counter traitbased_options
    
    monitor_event FactionTurnStart FactionType romans_scipii
            and I_CompareCounter counter1 = 4
            and I_CompareCounter counter2 = 1
            and I_CompareCounter counter3 = 1
            and I_CompareCounter counter4 = 2
                set_counter traitbased_options 0
                if RandomPercent < 99
                    advance_advice_thread PromptThreadWinningMessage 1
                    set_counter traitbased_options 1
                end_if
                if I_CompareCounter traitbased_options = 0
                    advance_advice_thread PromptThreadWinningMessage 2
                end_if
    end_monitor
    When conditions are met, the monitor fires, since WinningMessage 2 appears. But where is 1? I'm not sure if there's something else wrong, since I cannot get message 1 appear with this either, always just second message:

    Code:
    monitor_event FactionTurnStart FactionType romans_scipii
            and I_CompareCounter counter1 = 4
            and I_CompareCounter counter2 = 1
            and I_CompareCounter counter3 = 1
                if I_CompareCounter counter4 = 2
                    advance_advice_thread PromptThreadWinningMessage 1
                end_if
            [....other similar if blocks with different counter4 values removed]
            set_counter counter2 0
            set_counter counter3 0
    end_monitor
    eda.txt

    Code:
    AdviceThread PromptThreadWinningMessage
        GameArea Campaign
    
        Item PromptItem1
            Uninhibitable
            Verbosity  0
            Threshold  1
            MaxRepeats  0
            RepeatInterval  1
            Attitude Normal
            Presentation Default
            Title WinningMessageTitle1
            Text WinningMessageText1
            Text WinningMessageText2
    ea.txt

    Code:
    {WinningMessageTitle1}Winning message!
    {WinningMessageText1}First message. 
    {WinningMessageText2}Second message.
    Last edited by chrisb; January 29, 2012 at 03:21 PM.

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

    Default Re: How does RandomPercent function?

    Every check is a separate roll.

    If you want your counter to only be incremented once per event, you'll need to add one more counter to act as a flag, i.e.:

    Code:
    declare_counter cumulative_counter
    declare_counter cumulative_flag ; 0 or 1
    
    monitor_event <event> <condition>
         [and <more conditions>]
    
        set_counter cumulative_flag 0
        if RandomPercent > 90
            inc_counter cumulative_counter 100
            set_counter cumulative_flag 1
        end_if
    
        if I_CompareCounter cumulative_flag = 0
        and RandomPercent > 50
            inc_counter cumulative_counter 100
            set_counter cumulative_flag 1
        end_if
    
        if I_CompareCounter cumulative_flag = 0
        and RandomPercent > 20
            inc_counter cumulative_counter 2 
            set_counter cumulative_flag 1
        end_if
        
        if I_CompareCounter cumulative_flag = 0
        and RandomPercent > 10
            inc_counter cumulative_counter 1
            set_counter cumulative_flag 1
        end_if 
    
    end_monitor
    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

  9. #9

    Default Re: How does RandomPercent function?

    Quote Originally Posted by HouseOfHam View Post
    Every check is a separate roll.

    If you want your counter to only be incremented once per event, you'll need to add one more counter to act as a flag, i.e.:
    Good advice again, thanks a lot!!!

  10. #10
    Quinn Inuit's Avatar Artifex
    Join Date
    Sep 2006
    Location
    Virginia, USA
    Posts
    4,968

    Default Re: How does RandomPercent function?

    For the record, I have gotten a script to work where it spawned two different armies based on the same R#. If the R# was < 5, it was the small army. If the R# was > 98, it was the large army. Let me know if you're interested in the script. I'm away from home ATM, and so don't have it with me.
    RTR Platinum Team Apprentice, RTR VII Team Member, and Extended Realism Mod Team Coordinator. Proud member of House Wilpuri under the patronage of Pannonian

    The ExRM forum: come for the mod, stay for the Classical History discussions. Or vice versa.

    My writing-related Twitter feed.

  11. #11

    Default Re: How does RandomPercent function?

    Quote Originally Posted by Quinn Inuit View Post
    For the record, I have gotten a script to work where it spawned two different armies based on the same R#. If the R# was < 5, it was the small army. If the R# was > 98, it was the large army. Let me know if you're interested in the script. I'm away from home ATM, and so don't have it with me.
    Hi there, and sorry for the delay, I've been away from home travelling. I would be very interested! Can you post it here, or PM? Here might be more useful for others too ;-)

  12. #12
    Quinn Inuit's Avatar Artifex
    Join Date
    Sep 2006
    Location
    Virginia, USA
    Posts
    4,968

    Default Re: How does RandomPercent function?

    Always happy to help an Edgar Rice Burroughs fan.

    Spoiler Alert, click show to read: 

    Code:
    monitor_event FactionTurnStart FactionType scythia
        and not FactionIsLocal
        if RandomPercent < 3
            spawn_army
                faction scythia
                character Kudurmabug, general, age 30, , x 314, y 122
                unit        sarmatian noble cavalry                exp 0 armour 1 weapon_lvl 1
                unit        sarmatian horse archer                exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer                exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer            exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer                exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer            exp 0 armour 0 weapon_lvl 0
            end
        end_if
            if RandomPercent > 98  
            spawn_army
                faction scythia
                character Kudurmabug, general, age 30, , x 316, y 122
                unit        sarmatian noble cavalry                exp 0 armour 1 weapon_lvl 1
                unit        sarmatian noble cavalry                exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer                exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer                exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer                exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer                exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer                exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer                exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer                exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer                exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer                exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer                exp 0 armour 0 weapon_lvl 0
                unit        sarmatian horse archer                exp 0 armour 0 weapon_lvl 0
            end
        end_if
        if I_SettlementOwner Merv = thrace
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia thrace war
        end_if
        if I_SettlementOwner Merv = seleucid
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia seleucid war
        end_if
        if I_SettlementOwner Merv = parthia
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia parthia war
        end_if
        if I_SettlementOwner Merv = armenia
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia armenia war
        end_if
        if I_SettlementOwner Merv = romans_julii
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia romans_julii war
        end_if
        if I_SettlementOwner Merv = egypt
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia egypt war
        end_if
        if I_SettlementOwner Merv = dacia
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia dacia war
        end_if
        if I_SettlementOwner Merv = pontus
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia pontus war
        end_if
        if I_SettlementOwner Merv = macedon
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia macedon war
        end_if
        if I_SettlementOwner Merv = carthage
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia carthage war
        end_if
        if I_SettlementOwner Merv = romans_scipii
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia romans_scipii war
        end_if
        if I_SettlementOwner Merv = romans_brutii
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia romans_brutii war
        end_if
        if I_SettlementOwner Merv = greek_cities
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia greek_cities war
        end_if
        if I_SettlementOwner Merv = spain
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia spain war
        end_if
        if I_SettlementOwner Merv = gauls
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia gauls war
        end_if
        if I_SettlementOwner Merv = germans
            and I_CharacterTypeNearTile scythia general, 10 316,117
            console_command diplomatic_stance scythia germans war
        end_if
    end_monitor
    RTR Platinum Team Apprentice, RTR VII Team Member, and Extended Realism Mod Team Coordinator. Proud member of House Wilpuri under the patronage of Pannonian

    The ExRM forum: come for the mod, stay for the Classical History discussions. Or vice versa.

    My writing-related Twitter feed.

  13. #13
    Squid's Avatar Opifex
    Patrician Artifex Technical Staff

    Join Date
    Feb 2007
    Location
    Frozen waste lands of the north
    Posts
    17,751
    Blog Entries
    3

    Default Re: How does RandomPercent function?

    That's still two different calls to RandomPercent, your probability of overlap is just very small (3% * 1% = 0.03% or three turns in every 10000 both will fire).
    Last edited by Squid; August 04, 2011 at 09:36 PM.
    Under the patronage of Roman_Man#3, Patron of Ishan
    Click for my tools and tutorials
    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." -----Albert Einstein

  14. #14
    Quinn Inuit's Avatar Artifex
    Join Date
    Sep 2006
    Location
    Virginia, USA
    Posts
    4,968

    Default Re: How does RandomPercent function?

    Oh, O.K. Can't say I've ever seen or heard of them firing together, but it's far enough out in the boonies that most users would probably miss it.
    RTR Platinum Team Apprentice, RTR VII Team Member, and Extended Realism Mod Team Coordinator. Proud member of House Wilpuri under the patronage of Pannonian

    The ExRM forum: come for the mod, stay for the Classical History discussions. Or vice versa.

    My writing-related Twitter feed.

  15. #15
    Squid's Avatar Opifex
    Patrician Artifex Technical Staff

    Join Date
    Feb 2007
    Location
    Frozen waste lands of the north
    Posts
    17,751
    Blog Entries
    3

    Default Re: How does RandomPercent function?

    My bad, the number of turns between fires was off by a factor of 100, so its 3 turns in every 10,000 that both will fire.
    Under the patronage of Roman_Man#3, Patron of Ishan
    Click for my tools and tutorials
    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." -----Albert Einstein

  16. #16
    Quinn Inuit's Avatar Artifex
    Join Date
    Sep 2006
    Location
    Virginia, USA
    Posts
    4,968

    Default Re: How does RandomPercent function?

    That would definitely explain why nobody's reported it yet.
    RTR Platinum Team Apprentice, RTR VII Team Member, and Extended Realism Mod Team Coordinator. Proud member of House Wilpuri under the patronage of Pannonian

    The ExRM forum: come for the mod, stay for the Classical History discussions. Or vice versa.

    My writing-related Twitter feed.

  17. #17

    Default Re: How does RandomPercent function?

    OK, thanks again! I'll definitely try this. And indeed, E.R.B. rocks!

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

    Default Re: How does RandomPercent function?

    Not sure how familiar you are with advice threads, so here is a really quick intro:

    Whenever an advice trigger fires or the advance_advice_thread command is used, it adds 1 or more points to an internal thread counter. The game then checks if its value is high enough to meet a threshold. If it is, it will display advice. In case of multiple item blocks, it will look for the highest met threshold. Each item block can have more than one text line. You have no control over which line within the item block will be displayed.

    Anyhow, what you really need is 2 separate threads.
    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

  19. #19

    Default Re: How does RandomPercent function?

    Oh, thanks a lot, I had really misunderstood the whole. I just read also this and got a bit more idea. So you cannot control which of the >1 text lines is displayed? But how do they appear then, in random order or what? That would actually be exactly what I'm looking for as I would like to have several different advice messages for the same event, creating a bit variability to the game. I tried to do it with the script if-else, but that may be too complicated approach for that purpose.

    Could you still explain what you mean with "In case of multiple item blocks". Thanks!

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

    Default Re: How does RandomPercent function?

    An advice thread can have multiple Item blocks, each with its own threshold value.

    For example:

    Spoiler Alert, click show to read: 

    Code:
    AdviceThread Characters_Agent_Army_Early_Advice_Thread
        GameArea Campaign
    
        Item Characters_Agent_Army_Early_Advice_Text_01
            Suppressible y 
            Uninhibitable
            Verbosity  3 
            Threshold  1 
            Attitude Normal
            Presentation Default
            Title Characters_Agent_Army_Early_Advice_Text_01_Title
            Text Characters_Agent_Army_Early_Advice_Text_01_Text1
    
        Item Characters_Agent_Army_Early_Advice_Text_02
            Suppressible y 
            Uninhibitable
            Verbosity  3 
            Threshold  8 
            Attitude Normal
            Presentation Default
            Title Characters_Agent_Army_Early_Advice_Text_02_Title
            Text Characters_Agent_Army_Early_Advice_Text_02_Text1
    
        Item Enemy_Zone_Of_Movement_Text_01
            Suppressible y 
            Uninhibitable
            Verbosity  3 
            Threshold  16 
            Attitude Normal
            Presentation Default
            Title Enemy_Zone_Of_Movement_Text_01_Title
            Text Enemy_Zone_Of_Movement_Text_01_Text1
    
        Item Characters_Agent_Army_Early_Advice_Text_03
            Suppressible y 
            Uninhibitable
            Verbosity  3 
            Threshold  24 
            Attitude Normal
            Presentation Default
            Title Characters_Agent_Army_Early_Advice_Text_03_Title
            Text Characters_Agent_Army_Early_Advice_Text_03_Text1
    
        Item Characters_Agent_Army_Early_Advice_Text_04
            Suppressible y 
            Uninhibitable
            Verbosity  3 
            Threshold  32 
            Attitude Normal
            Presentation Default
            Title Characters_Agent_Army_Early_Advice_Text_04_Title
            Text Characters_Agent_Army_Early_Advice_Text_04_Text1
    
        Item Characters_Agent_Army_Early_Advice_Text_05
            Uninhibitable
            Verbosity  3 
            Threshold  48 
            Attitude Normal
            Presentation Default
            Title Characters_Agent_Army_Early_Advice_Text_05_Title
            Text Characters_Agent_Army_Early_Advice_Text_05_Text1
    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

Page 1 of 2 12 LastLast

Posting Permissions

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