To add random states to random enemies you have to generate two different numbers. One if used for the state id, the other for the chance of applying it. In the example listed below I am assuming you want to pick your state from the whole list of states.
Code:
$game_troop.members.each do |member|
state_id = 1 + rand(number_of_states_goes_here)
chance = 1 + rand(100)
member.add_state(state_id) if (chance > 95)
end
If you want to pick the state from a smaller list then you have to create your list like this
Code:
my_states_list = [
state_id,
another_state_id,
a_different_state_id,
and_so_on,
] # do not remove this
All those lines "state_id" ,"another_state_id", etc. are supposed to be integers. You can add as many state IDs as you want as long as you add a comma at the end of each state. Then you use a slightly different variant of the previous code to pick the state from that list. In the end the code should look like this (I am using random numbers for state IDs).
Code:
my_states_list = [
3,
5,
6,
9,
11,
31,
]
$game_troop.members.each do |member|
state = rand(my_states_list.length)
chance = 1 + rand(100)
member.add_state(my_states_list[state]) if (chance > 95)
end
If you want you can put all your states on the same line like this:
Code:
my_states_list = [3, 5, 6, 9, 11, 31]
I honestly prefer this one but in the previous code I used long names for placeholders so having them on different lines was easier to the eye.