samedi 29 juin 2019

Create chance function in rpg game

I am creating a server-side RPG game that has a chance system. for example, the player has a 30% chance when hit target stuns the enemy and 70% percent to 35% more damage.

so I come with this solution.

//'s' as stuns and 'd' as more damage;
array a = ['s', 's', 's', 'd', 'd', 'd', 'd', 'd', 'd', 'd'];
int chance = random(0, 9);
print a[chance];

but the above solution has a problem first it only works with an Integer number and another is that only work with a number that can be divided by 10.

for example, the above function that's not going to work with 25% or 0.1% chance as input.




Aucun commentaire:

Enregistrer un commentaire