2 random and different picks out of 1 source

  • Hearts of Iron IV Survey

    Help us make HoI IV better by sharing your experiences in this 5 minute survey


  • Crusader Kings III Available Now!

    The realm rejoices as Paradox Interactive announces the launch of Crusader Kings III, the latest entry in the publisher’s grand strategy role-playing game franchise. Advisors may now jockey for positions of influence and adversaries should save their schemes for another day, because on this day Crusader Kings III can be purchased on Steam, the Paradox Store, and other major online retailers.


    Real Strategy Requires Cunning
Mar 13, 2021
25
15
Hello guys,

could someone help me with the following issue, please? I need 2 randomly picked names out of a custom "list". 1 name for red_rooster_name and 1 name for blue_rooster_name and the names must not be the same. At the moment I only have 2 seperate random_list-commands, so there is a pretty high chance, that the names picked will be the same (although I want to add more names, if it's working). I could make 2 "lists" with totally different names each of course, but it would be much nicer if both names would be picked from the same source, so that there are more possibilities.

Here is the code:

event-file
Code:
    immediate = {

        random_list = {
            25 = {
                set_variable = {
                    name = red_rooster_name
                    value = flag:rooster_name_kingslayer
                }
            }
            25 = {
                set_variable = {
                    name = red_rooster_name
                    value = flag:rooster_name_thunderstorm
                }
            }
            25 = {
                set_variable = {
                    name = red_rooster_name
                    value = flag:rooster_name_peoples_champ
                }
            }
            25 = {
                set_variable = {
                    name = red_rooster_name
                    value = flag:rooster_name_phoenix
                }
            }
        }

        random_list = {
            25 = {
                set_variable = {
                    name = blue_rooster_name
                    value = flag:rooster_name_kingslayer
                }
            }
            25 = {
                set_variable = {
                    name = blue_rooster_name
                    value = flag:rooster_name_thunderstorm
                }
            }
            25 = {
                set_variable = {
                    name = blue_rooster_name
                    value = flag:rooster_name_peoples_champ
                }
            }
            25 = {
                set_variable = {
                    name = blue_rooster_name
                    value = flag:rooster_name_phoenix
                }
            }
        }
    }


A little more context:
I need the names to show up in the event-window and that part is fortunately already working with [ROOT.Char.Custom('RedRoosterName')] and [ROOT.Char.Custom('BlueRoosterName')] after setting the variables.

customizable_localization-file
Code:
RedRoosterName = {
    type = character

    text = {
        trigger = { var:red_rooster_name = flag:rooster_name_kingslayer }
        localization_key = rooster_name_kingslayer
    }
    text = {
        trigger = { var:red_rooster_name = flag:rooster_name_thunderstorm }
        localization_key = rooster_name_thunderstorm
    }
    text = {
        trigger = { var:red_rooster_name = flag:rooster_name_peoples_champ }
        localization_key = rooster_name_peoples_champ
    }
    text = {
        trigger = { var:red_rooster_name = flag:rooster_name_phoenix }
        localization_key = rooster_name_phoenix
    }
}

BlueRoosterName = {
    type = character

    text = {
        trigger = { var:blue_rooster_name = flag:rooster_name_kingslayer }
        localization_key = rooster_name_kingslayer
    }
    text = {
        trigger = { var:blue_rooster_name = flag:rooster_name_thunderstorm }
        localization_key = rooster_name_thunderstorm
    }
    text = {
        trigger = { var:blue_rooster_name = flag:rooster_name_peoples_champ }
        localization_key = rooster_name_peoples_champ
    }
    text = {
        trigger = { var:blue_rooster_name = flag:rooster_name_phoenix }
        localization_key = rooster_name_phoenix
    }
}

Thank you very much for reading :)
 
Mar 13, 2021
25
15
While there are probably way more elegant ways to have 2 random but different values picked off a list, I am happy that I managed to find a solution anyway :)
I just put it here in case anyone else in the world could need it sometime. So it's still not just 1 list, but still 2 identical ones, but at least result a will never equal result b again. (I wanted 2 different names for roosters from an identical pool of names )

Call the scripted_effects in the event.txt
Code:
        # Random number
        x_rooster_number_effect = yes

        # Apply the same number to red and blue...
        set_variable = {
            name = x_rooster_number_effect_result_red
            value = var:x_rooster_number
        }
        set_variable = {
            name = x_rooster_number_effect_result_blue
            value = var:x_rooster_number
        }
        # ...then roll again, until blue has a different number than red
        while = {
            limit = {
                check_variable = { which = x_rooster_number_effect_result_red which = x_rooster_number_effect_result_blue }
            }
            x_rooster_number_effect = yes
            set_variable = {
                name = x_rooster_number_effect_result_blue
                value = var:x_rooster_number
            }  
        }

        # Finally name them!
        red_rooster_naming = yes
        blue_rooster_naming = yes

common/scripted_effects/ *.txt
Code:
# Pick a random number
x_rooster_number_effect = {
        random_list = {
            15 = {
                set_variable = {
                    name = x_rooster_number
                    value = 1
                }
            }
            15 = {
                set_variable = {
                    name = x_rooster_number
                    value = 2
                }
            }
            15 = {
                set_variable = {
                    name = x_rooster_number
                    value = 3
                }
            }
            15 = {
                set_variable = {
                    name = x_rooster_number
                    value = 4
                }
            }
        }
}

red_rooster_naming = {
        if = {
            limit = {var:x_rooster_number_effect_result_red = 1}
                set_variable = {
                    name = red_rooster_name
                    value = flag:rooster_name_kingslayer
                }
        }
        else_if = {
            limit = {var:x_rooster_number_effect_result_red = 2}
                set_variable = {
                    name = red_rooster_name
                    value = flag:rooster_name_thunderstorm
                }
        }
        else_if = {
            limit = {var:x_rooster_number_effect_result_red = 3}
                set_variable = {
                    name = red_rooster_name
                    value = flag:rooster_name_peoples_champ
                }
        }
        else_if = {
            limit = {var:x_rooster_number_effect_result_red = 4}
                set_variable = {
                    name = red_rooster_name
                    value = flag:rooster_name_phoenix
                }
        }
}

blue_rooster_naming = {
        if = {
            limit = {var:x_rooster_number_effect_result_blue = 1}
                set_variable = {
                    name = blue_rooster_name
                    value = flag:rooster_name_kingslayer
                }
        }
        else_if = {
            limit = {var:x_rooster_number_effect_result_blue = 2}
                set_variable = {
                    name = blue_rooster_name
                    value = flag:rooster_name_thunderstorm
                }
        }
        else_if = {
            limit = {var:x_rooster_number_effect_result_blue = 3}
                set_variable = {
                    name = blue_rooster_name
                    value = flag:rooster_name_peoples_champ
                }
        }
        else_if = {
            limit = {var:x_rooster_number_effect_result_blue = 4}
                set_variable = {
                    name = blue_rooster_name
                    value = flag:rooster_name_phoenix
                }
        }
}

Here is the customisable_localization as well, because being able to display the names was what it was all about in the first place xD
Code:
RedRoosterName = {
    type = character

    text = {
        trigger = { var:red_rooster_name = flag:custom }
        localization_key = rooster_name
    }
    text = {
        trigger = { var:red_rooster_name = flag:rooster_name_kingslayer }
        localization_key = rooster_name_kingslayer
    }
    text = {
        trigger = { var:red_rooster_name = flag:rooster_name_thunderstorm }
        localization_key = rooster_name_thunderstorm
    }
    text = {
        trigger = { var:red_rooster_name = flag:rooster_name_peoples_champ }
        localization_key = rooster_name_peoples_champ
    }
    text = {
        trigger = { var:red_rooster_name = flag:rooster_name_phoenix }
        localization_key = rooster_name_phoenix
    }
}

BlueRoosterName = {
    type = character

    text = {
        trigger = { var:blue_rooster_name = flag:custom }
        localization_key = rooster_name
    }
    text = {
        trigger = { var:blue_rooster_name = flag:rooster_name_kingslayer }
        localization_key = rooster_name_kingslayer
    }
    text = {
        trigger = { var:blue_rooster_name = flag:rooster_name_thunderstorm }
        localization_key = rooster_name_thunderstorm
    }
    text = {
        trigger = { var:blue_rooster_name = flag:rooster_name_peoples_champ }
        localization_key = rooster_name_peoples_champ
    }
    text = {
        trigger = { var:blue_rooster_name = flag:rooster_name_phoenix }
        localization_key = rooster_name_phoenix
    }
}