ForumsProgramming ForumRandom events in AS3

4 5163
Katumi
offline
Katumi
9 posts
Nomad

Hi Everyone =)

I'm working on an RPG game at the moment, and i would like to know how i can add randomness to the game. For exmaple having a x% chanse to load one movieclip into the game when another movieclip is unloaded (Enemy dying and dropping an item) Anyone know how i can do this?

Thanks in advance =))

  • 4 Replies
Secretmapper
offline
Secretmapper
1,747 posts
Nomad

by using *

driejen
offline
driejen
486 posts
Nomad

function RNG(chance:Number):Number{
if(Math.random()*100>=chance){
return true
}else{
return false
}
}

//when an enemy dies
if(RNG(80)){
dropitem1() //create this function or replace this code, 80% chance of being called
}else{
dropitem2 //create this function or replace this code, called if item1 does not drop
}

I think thats the basic idea...

driejen
offline
driejen
486 posts
Nomad

Sorry the return is a Boolean type, not Number

Katumi
offline
Katumi
9 posts
Nomad

Just what i was looking for, Thanks a lot!

Showing 1-4 of 4