Hello, so I’m building a portfolio which means I’m undertaking a few small commissions.

I’ve had a client asking for a script which I’ve fully scripted but there’s one issue I don’t fully know how to solve. He wants this script that includes damage to another player but the damage increases proportionally to the player stats. I’ve asked him multiple times if he can explain it to me but neither times has it made sense. Here’s what they have said:

If anyone can help me understand what he’s said or put it in a logical way that would be great. Thanks.

1 Like

The way he has phrased it is slightly confusing, but I think I understand. There are multiple ways of doing this, but I would say the best is to compare the ‘Psychic’ stats of the two combatants. This could be done by dividing P1 (Player 1’s stat) by P2 (Player 2’s stat) which would result in a multiplier. You could use the multiplier to buff/decrease the base damage that the player holds. In terms of damage being deflected to the user you could check if the multiplier is below a certain level i.e below 1, and then use the multiplier again to determine how much damage is deflected (the lower the multiplier the greater the damage deflected).

```
-- calculate the multiplier
local dmgmultiplier = (P1/P2)
-- calculate the real damage taking into account the base damage
local realdmg = dmgmultiplier*dmg
-- if you wanted the deflected damage to be directly influenced by the dmgmultiplier
if dmgmultiplier < 1 then
PlayerHealth = dmgmultiplier*PlayerHealth
end
```

edit:

I was just thinking about the wording of what was being asked and I realised I’d used wrong (although maybe better) logic. In order to achieve what he’s asking, you actually have to do this:

```
-- calculate the multiplier
-- you also have to divide by 100 because you're using a factor of 100 to determine how much health is lost
local dmgmultiplier = (P1/P2)/100
Player2Health -= dmgmultiplier*Player2Health
```

The reason why I thought it was slightly odd is because as combatants converge towards equality (i.e two players with 1 psychic each) marginal amounts of damage are done. For example if you carried out the example with two players with 1 psychic each it would result in only 1/100 of the player’s damage being hit. Doesn’t sound like a very fun game unless there are other factors at play.

This does also have the possibility of producing negative health, but I suppose that doesn’t matter so much if the player is dead. You should also start with 1 Psychic since it’s not possible to divide by zero, and it’s more trouble than it’s worth to make a work around to that problem.

His math isn’t consistent. 1 x 10 ≠ 11. Though this does follow another: `((Attacker Psychic - Target Psychic)/(Target Psychic ≠ 0))`

% hp. If the denominator is 0, it must be set to 1 instead or else you get undefined.

For example, `(11 - 1)/1`

= 10% hp. This works for the others too:

`(100 - 0)/1`

= 100% hp

however it only works until you get to the bottom, because

`(10 - 100)/100`

= -0.9% hp. Which obviously doesn’t work, and even if you flip it to `(100 - 10)/10`

you still get 9% hp. Same with the last example

`(10 - 1000)/1000`

= -0.99. And flipping it would give you 99% hp.

However, like I said 10 x 1 ≠ 11 and 0 x 100 ≠ 100. I don’t think he’s wording it correctly.