Random/Inbetween

Started by ncw14, Tue 08/01/2008 01:25:15

Previous topic - Next topic

ncw14

Im making an Rpg

my problem -

getglobalint5 is enemy health

i can make my person do any amount of damage (but only if its defined)

so my problem is i want to make globalint5 to drop 5-10 i cant find a way to make things randomly happen like a random amount of damage anywhere between 2 numbers

so i could do possibly 5,6,7,8,9,10 damage instead of 1 of those but only over and over

Gilbert

Since Random(n) returns a random value from 0, 1, 2, ..., n, so if you want to have a certain range of values, it is just straight forward to do something like:

damage = 5 + Random(5);

which will easily give a random value from 5, 6, 7, 8, 9, 10.

ncw14

you solved that but anoth random question

Can i make it go from random items
Can i make it go from random rooms, for fights when i click battle or will i always have to have it same thing

and lastly is there a way to say it could be either 1,3,5 without randomly doing 2,4 either

Khris

I completely failed to understand the first part of the question, sorry.
If you're talking about going to random rooms, just do a "player.ChangeRoom(Random(2)+2);" to randomly go to room 2, 3 or 4.

Lastly: again basic math to the rescue. Random(2)*2+1 will yield 1, 3 or 5.

OneDollar

Quote from: ncw14 on Tue 08/01/2008 23:23:23
Can i make it go from random items

I'm guessing for an RPG you wouldn't want to just add any item in the game, so you'd want to set up a list of possible items and pick one depending on the random number. So something like:

Code: ags

int giveItem;

giveItem=Random(2);
if (giveItem==0){
  player.AddInventory(iApple);
}else if (giveItem==1){
  player.AddInventory(iElixir);
}else{
  player.AddInventory(iRustyBlade);
}


If that's what you meant by the question...

SMF spam blocked by CleanTalk