This will be hard to explain what I want, so I'll try my best.
I have a game, and the players in the game have a health counter (hp), and bodyguards as well. Each bodyguard has 100 hp, and once all a players bodyguards are gone, the damage comes off their hp.
So, these are the values I have:
$dmg // the damage
$bgs // the amount of bodyguards the player has
$bg_hp // the bodyguards health. Starts at 100, drains with $dmg fired at
$hp // the players health
When they're shot, it needs to check if they have $bgs. This is a basic example.
if ($bgs > 0) {
$bgs_hp = $bgs_hp - $dmg;
if ($bg_hp <= 0) { $bg = $bg - 1; $bg_hp = 100; }
} else {
$hp = $hp - $dmg;
}
Anyway, the part I need help with is this. I want the damage to overlap. So say the $dmg is 200, that would kill 2 bodyguards (they have 100 hp each). Or someone could shoot all their bodyguards and a remainder of the $dmg comes off the $hp too.
The reason I need help is because im awful at maths, and theres problem some MOD function or something that I need to use.
Examples;
1) Player has 3 bodyguards. Someone shoots at him for 150 dmg. It would kill 1 bodyguard, and cause 50 damage to the next.
2) Player has 1 bodyguard that is half hp (50). Someone shoots him for 160, it'd kill the bodyguard (50hp), and the rest of that damage (110) would kill the player too.