# Got a math problem kinda thing!

Okay … I’m designing a combat system for this MUSH I’m working on, and I wanna put in a “Guts” stat which causes the amount of damage you take to decrease with your HP.

So if your Guts is 10 (the maximum for each stat), then at 50% HP you’d take 75% as much damage as you would at 100% HP, and, uh, at 0% HP you’d take 50% as much damage as at 100% HP. (Yes, I know, but if you could take damage after hitting 0 HP, you would.)

If your Guts is 5, you’d take 87.5% damage at 50% HP, and 75% damage at “0 HP”. It would decrease linearly like that, basically. I’m having trouble working out how, exactly, to work that out. Anyone got any idea how I might work this out? An equation maybe?

hp_percent = current_hp / total_hp
damage_percent = 1 - (guts / 10) * (1 - hp_percent) * 0.5
damage = damage * damage_percent

Or, simplified:

damage = damage * (1 - guts / 20 + (guts / 20) * (current hp / total hp))

Make sure the variables are declared as something with decimals to a few places.

You’re dividing by zero, that’s the problem. It always is on these topics.

In the future, if you’re not going to add anything useful Arac, I would highly consider not posting at all.

Okay, that algorithm works when I plugged the numbers in … now, to get all that into MUSHcode, heh …

… and figure out the order of operations better …