The Daily Click ::. Forums ::. Klik Coding Help ::. How to randomize damage?
 

Post Reply  Post Oekaki 
 

Posted By Message

J.C



Registered
  22/03/2013 05:18:14
Points
  118
12th January, 2014 at 12/01/2014 04:17:12 -

Hello, I have a new question for you guys.

First off, I know how to randomize damage to the player's health with the counter object, but what bothers me is that I don't know how to set a minimum/maximum amount of damage.

This is how I set up my code:

Enemy projectile hits player
Subtract random(120) from counter



 
n/a

nim



Registered
  17/05/2002
Points
  7233
12th January, 2014 at 12/01/2014 04:35:21 -

Enemy projectile hits player
Subtract 10 + random(120) from counter

range 10 to 129

 
//

nim



Registered
  17/05/2002
Points
  7233
12th January, 2014 at 12/01/2014 04:49:09 -

Another way to do it would be to use MMF's max() and min() functions.

min(x,y) will give you the lowest value of the two - x or y
and max(x,y) will give you the value that's the highest of the two.

so you can combine them:

Max(X, Min(value, Y))

this will keep "value" within the upper/lower limit of X and Y

 
//

nim



Registered
  17/05/2002
Points
  7233
12th January, 2014 at 12/01/2014 04:49:56 -

Or if you're using Fusion 2.5 you can use its RRandom(x,y) expression to specify a range.

 
//

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
12th January, 2014 at 12/01/2014 17:12:35 -

You just want to say:

Damage = MinDamage + Random( Maamage - MinDamage )

Using max() would be a very bad idea, as you'd end up with the lowest possible value being greatly over-represented (too many attacks would inflict the minimum possible amount of damage).

If you want to make things complicated, you could try to make damage random but "normally distributed" (so attacks usually do an average amount of damage, and extremely high or low amounts of damage are much rarer) or some approximation of that - but that's a fair amount of work (see "Probability Distribution" on wikipedia).

 
n/a

Pan-tosser



Registered
  24/10/2008
Points
  520

Has Donated, Thank You!
13th January, 2014 at 13/01/2014 03:45:25 -

off to wikipedia i go. Sounds like a good way to create an rpg styled strength stat. I've never really used random to accomplish resolving damage. I main just divide the defense number into it, and called it done.

 
https://www.facebook.com/nathon.brown.7

nim



Registered
  17/05/2002
Points
  7233
13th January, 2014 at 13/01/2014 08:03:48 -

max damage

maamage

oh, tdc.

 
//
   

Post Reply



 



Advertisement

Worth A Click