Weapon X2 damage
#1

I made a code, to make damages more realistic:
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    if(issuerid != INVALID_PLAYER_ID)
    {
        new Float:HP, Float: damage;
        GetPlayerHealth(playerid, HP);
       
        damage = floatdiv(HP, amount);
       
        SetPlayerHealth(playerid, damage);
    }
    return 1;
}
Is the command bugged or I just have to make the damage made lower? Currently if I shoot with a M4, I almost shoot the guy dead. The code is supposed to remove the amount of damage done from the player, and it returns 1 so it removes the amount of damage again. Is it X2 or bugged?
Reply
#2

Err, I think you just need to subtract amount once more from the current health, seeing as the old health is the current health plus the amount.
Reply
#3

I will explain the problem via an example.

What you actually do?

Let's say player at start has HP=100. amount(damage) is 2
1st time:
his health will be 100/2=50
2nd time:
his health will be 50/2=25
3rd time:
his health will be 25/2=12.5
etc.
It will allways take less damage. Cuz of that it will take time untill the player is dead.
Reply
#4

I want the damage to be X2 not more. Currently it seems to me that it's taking away more health than X2. The code takes away "amount" damage. Then I get the players health and subtract "amount" once again from the health. That should make the damage X2 as I want it to be. But it seems to be higher, 1 bullet with M4 almost kills the guy.

E:// How dumb.. I thought was using floatsub not floatdiv. Little typo there, thanks for helping.
Reply
#5

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    if(issuerid != INVALID_PLAYER_ID)
    {
        new Float:HP, Float: damage;
        GetPlayerHealth(playerid, HP);//lets say it is 100.
       
        damage = floatdiv(HP, amount);
        // lets say the damage was 50.
        //100/50 = 2 of hp.
       
        SetPlayerHealth(playerid, damage); // so the player gonna have 2 of hp.
    }
    return 1;
}

an simple example of what you're doing.
pawn Код:
public OnFilterScriptInit()
{
    new Float:Number1 = 100.0, Float:Number2 = 50.0;
    new Float:Result;
    new l[5];
    Result = floatdiv(Number1, Number2);
    format(l,5,"%0.2f",Result);
    printf(l);
}
//it gonna print 2.00 which is 2.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)