SetPlayerHealth problem
#1

I have this script which doesn't work and I don't know why it makes the health goes 100 everytime it is set

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    if(weaponid == 39 || weaponid == 27 || weaponid == 28 || weaponid == 33 || weaponid == 36 || weaponid == 37 || weaponid == 38 || weaponid == 41)
    {
        new Float:CashDamage = 10/100*amount;
        new Float:PHealth;
        GetPlayerHealth(playerid, PHealth);
        PHealth = PHealth-CashDamage;
        SetPlayerHealth(playerid, PHealth);
    }
}
Is it the calculation problem? Can we set a decimal-ed number as a player's health?
Reply
#2

the health is float? Try rounding the number
Reply
#3

Damn thing won't let me just say 'Ok', message too short

Edit
Can I write like this

PHealth = floatround(PHealth);

Or must I create a new variable

EDIT 2
Doesn't work, it makes the health goes to 100 everytime I set health
Reply
#4

This is a calculation error.
pawn Код:
new Float:CashDamage = 10/100*amount;
Lets say for example, that you take an amount of damage '8'. (Thus, amount = 8 )

CashDamage = 10 / 100 * amount
CashDamage = 10 / 100 * 8
CashDamage = 0.1 * 8
CashDamage = 0.8

Therefore, you're pretty much only taking away less than 1 health at a time if a player is taking 8 damage. Reducing the damage dramatically.

I have a feeling this is not the outcome you were looking for, so I think this might be a more appropriate code:
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    switch(weaponid)
    {
        case 27, 28, 33, 37 .. 39, 41:
        {
            new Float:CashDamage = 10 * amount; //Because 100 * amount / 10 = 100 / 10 * amount = 10 * amount'
            //Now 10x the damage is a very drastic increase in damage, I would suggest 4x or 5x, making it CashDamage = 4 * amount || CashDamage = 5 * amount
            new Float:PHealth;
            GetPlayerHealth(playerid, PHealth);
            SetPlayerHealth(playerid, (PHealth - CashDamage));
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)