Hi, I am trying to make a script where it will give the player a random reward but I don't know what to use or how to make it random or a %chance of getting a certain reward.
Sorry if this seems like a dumb question but I am still trying to learn the whole coding language.
Reward script
Moderators: marionline, SDHawk
Reward script
Last edited by yoelleoy on Sun May 03, 2015 8:26 pm, edited 1 time in total.
Use the 'random' command. For example, for a 7% chance of something happening, write:
If you want to choose exactly one of a series of things each with a certain chance, use a chain of ifs:
If you just want to select between a set of things, each with equal chance, then clearly things can be a bit simpler.
You can also use 'switch':
Code: Select all
if (random(1,100) <= 7) then (...)
Code: Select all
variable (rand)
rand := random(1,100)
if (rand <= 5) then ( # 5% chance
...
) else if (rand > 5 && rand <= 15) then ( # 10% chacne
...
) else if (rand > 15 && rand <= 35) then ( # 20% chance
...
) else ( # 65%
...
)
You can also use 'switch':
Code: Select all
variable (rand)
rand := random(1,4)
switch (rand) do (
case(1)
...
case(2)
...
case(3)
...
case(4)
...
)
Last edited by TMC on Mon May 04, 2015 5:50 am, edited 1 time in total.
Thanks a lot for the helpTMC wrote:Use the 'random' command. For example, for a 7% chance of something happening, write:If you want to choose exactly one of a series of things each with a certain chance, use a chain of ifs:Code: Select all
if (random(1,100) <= 7) then (...)
If you just want to select between a set of things, each with equal chance, then clearly things can be a bit simpler.Code: Select all
variable (rand) rand := random(1,100) if (rand <5> 5 && rand <15> 15 && rand <= 35) then ( # 20% chance ... ) else ( # 65% ... )
You can also use 'switch':
Code: Select all
variable (rand) rand := random(1,4) switch (rand) do ( case(1) ... case(2) ... case(3) ... case(4) ... )