Random switch from one to all enemies

● ARCHIVED · READ-ONLY
Started by Kes 8 posts View original ↗
  1. I have a skill which is set up to attack one enemy.  I would like it also to be able to attack all, or 2, enemies.  I know that I could make a duplicate skill with just the scope changed.  However, I want to be able to determine more accurately how often it is used than is possible just using the rating number.

    Ideally, I would like it to be a one in three chance that it will attack all enemies, or 2 - I can't make up my mind which it will be until I test it and see what it does to the balancing.

    Does anyone have any suggestions?

    Thanks.
  2. It can be done using battle events:

    1. Set the action condition of all these skills as switches each associated to one of these skills to be ON(let them be switch a1, switch a2, switch a3, ..., switch an)

    2. Use a variable(let it be variable x) specifically for controlling which of the above switches is ON

    3. Add a new battle event page with condition turn 0 + 1 * x in all battles(assuming you're using the default RMVXA battle system)

    4. Add the below event commands to all those battle event pages:

    Spoiler
    Control Switches: [a1..an] = OFF

    Control Variables: variable x = random 0 ~ n

    Conditional Branch: variable x > k1

      Control Switches: switch a1 = ON

    Else

      Conditional Branch: variable x > k2

        Control Switches: switch a2 = ON

      Else

        Conditional Branch: variable x > k3

          Control Switches: switch a3 = ON

        Else

        ...

          Else

            Conditional Branch: variable x > kn

              Control Switches: switch an = ON

          Branch End

        ...

        Branch End

      Branch End

    Branch End
    Now switch a1 and an should have a probability of (n - k1) / n and kn / n to be ON respectively, and that of all the other ais should be (a(i-1) - ai) / n.

    If it's too complicated, you can use the below script code version instead:

    Spoiler
    switch_id_list = [a1, a2, a3, ..., an]probability_id_list = [k1, k2, k3, ..., kn]switch_id_list.each { |id| $game_switches[id] = false }x = rand(n)i = 0n.times do return $game_switches[switch_id_list] = true if x > probability_id_list i += 1endYou don't have to use $game_variables[x] now. You can just use x instead.

    I haven't tested either of them but I hope at least 1 of them works :)
  3. @DoubleX

    If you're still around, could you clarify a couple of things for me.

    When you say "all these skills" I assume you mean just the skill in question and the duplicate, not all the skills this enemy has.  Is that correct?  If that is correct, won't this prevent any other skill from being chosen?  If it is every skill the enemy has, that's not a problem, I just need to be clear.

    I don't know what you mean by >k1, >k2 etc.  What is the k?  Does it simply mean that the variable is returning 1, 2 etc?  In which case, presumably I start it at k0.  Or is k something else entirely?

    Thanks, and sorry for being a bit obtuse about this.
  4. ksjp17 said:
    @DoubleX

    If you're still around, could you clarify a couple of things for me.

    When you say "all these skills" I assume you mean just the skill in question and the duplicate, not all the skills this enemy has.  Is that correct?  If that is correct, won't this prevent any other skill from being chosen?  If it is every skill the enemy has, that's not a problem, I just need to be clear.

    I don't know what you mean by >k1, >k2 etc.  What is the k?  Does it simply mean that the variable is returning 1, 2 etc?  In which case, presumably I start it at k0.  Or is k something else entirely?

    Thanks, and sorry for being a bit obtuse about this.
    1. Yes, all these skills refer to those skills in question and the duplicate.

    2. No,  my setup won't prevent other skill from being chosen. It just controls the probability of each of those duplicate skills to be chosen given that exactly least 1 of them will be chosen. For example:

    skill duplicate 1, skill duplicate 2, skill duplicate 3, ..., skill duplicate n all have the same rating of 5 and all the other m skills also have the same rating of 5. Now all the other skills aren't excluded by rating or conditions of those duplicate skills although they can still be excluded by their own conditions. Without considering any of those conditions, the probability of picking any duplicate skill would be n / (m + n).

    However, if it's given that exactly 1 duplicate skill will be chosen, then my setup will step up to control the probability of each of those duplicate skills to be chosen among all those duplicate skills.

    Those kis are used to control the probability of skill duplicate i to be chosen given that exactly 1 of them will be chosen. Mathematically speaking(assuming you know what probability is):

    Spoiler
    (rand(n) is changed to rand(p) to try to make things less confusing)

    Ignoring other skill conditions, under my setup:

    The probability of choosing at least 1 duplicate skills, P(n), is n / (m + n)

    The probability of choosing skill duplicate i given that at least 1 duplicate skill will be chosen, P(i|n), is:

    (p - k1) / p for skill duplicate 1

    kn / p for skill duplicate n

    (k(i-1) - ki) / p for duplicate skill i

    Combining the above, the probability of choosing skill duplicate i, P(i), is:

    (p - k1) * n / p * (m + n) for skill duplicate 1

    kn * n / p * (m + n) for skill duplicate n

    (k(i-1) - ki) * n / p * (m + n) for duplicate skill i
    3. The > sign means "greater than", so

    Conditional Branch: variable x > ki

    Means "If variables x is greater than ki"

    I hope you can get the ideas and mathematics behinds my setup. My presentation surely sucks really hard :)

    Edit: Maybe I should have said earlier that your request and be done via rating alone. For example:

    Skill                    Condition            R

    Skill Duplicate 1                             5

    Skill Duplicate 1                             5

    Skill Duplicate 1                             5

    Skill Duplicate 2                             5

    Skill Duplicate 2                             5

    Skill Duplicate 3                             5

    Now if given exactly 1 skill duplicate will be chosen, then the probability of skill duplicate 1, 2 and 3 to be chosen is 1 / 2, 1 / 3 and 1 / 6 respectively.

    I provided an alternative setup just in case you don't want to do this via rating alone :D
  5. Thanks, I think I am a little clearer now, but unfortunately you picked the wrong bit of my final question.  I know what > means, it was the k that I was querying.
  6. ksjp17 said:
    Thanks, I think I am a little clearer now, but unfortunately you picked the wrong bit of my final question.  I know what > means, it was the k that I was querying.
    k is a number set by you to control the probability of each duplicate skill to be chosen. Let's consider the below specific example:

    You've 3 skill duplicates, skill duplicate 1, skill duplicate 2 and skill duplicate 3. You want the probability of the 1st, 2nd and 3rd one to be chosen given exctly one of them will be chosen to be 1 / 2, 1 / 3 and 1 / 6 respectively.

    Now set the action condition of the 1st, 2nd and 3rd one as switch a1, switch a2 and switch a3 as ON respectively and all of their rating as the same. Then use either one of the setup in 1 battle event page per battle:

    Non-script code version:

    Spoiler
    Control Switches: [a1, a2, a3] = OFF

    Control Variables: variable x = random 0 ~ 5

    Conditional Branch: variable x > 2

      Control Switches: switch a1 = ON

    Else

      Conditional Branch: variable x > 0

        Control Switches: switch a2 = ON

      Else

        Control Switches: switch a3 = ON

      Branch EndBranch End
    Script code version:

    Spoiler
    switch_id_list = [a1, a2, a3]probability_id_list = [2, 0, -1]switch_id_list.each { |id| $game_switches[id] = false }x = rand(6)i = 03.times do return $game_switches[switch_id_list] = true if x > probability_id_list i += 1end
    Now k1, k2 and k3 are 2, 0 and -1 respectively, causing the probability of each of them to be chosen given exactly 1 of them will be chosen to be:

    The 1st one - (5 - 2) / (5 + 1) = 1 / 2

    The 2nd one - (2 - 0) / (5 + 1) = 1 / 3

    The 3rd one - (0 - (-1)) / (5 + 1) = 1 / 6

    I hope you can get it this time, with the above specific example. If you still can't get it, then that's 100% my fault XD
  7. I think I've got it now.

    Thanks very much for all your help.
  8. This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.