OnPlayerTakeDamage Help
#1

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new query[500], pname[24];
    GetPlayerName(playerid, pname, 24);
    GetPlayerHealth(playerid, PlayerInfo[playerid][pHealth]);
    if(issuerid != INVALID_PLAYER_ID || issuerid == INVALID_PLAYER_ID)
    {
        if(PlayerInfo[playerid][pHealth] <= 20) // Why won't this work?
        {
            SetPlayerHealth(playerid, PlayerInfo[playerid][pHealth]);
            ApplyAnimation(playerid,"BEACH", "bather", 4.0, 0, 0, 0, 0, 0);
            TogglePlayerControllable(playerid, 0);
        }
        PlayerInfo[playerid][pHealth] -= amount+8; // Cause this works
        SetPlayerHealth(playerid, PlayerInfo[playerid][pHealth]);
        format(query, sizeof(query), "UPDATE playerdata SET Health=%.0f WHERE Username='%s'",
        PlayerInfo[playerid][pHealth],
        pname);
        mysql_query(query);
    }
    return 1;
}
Yeah, basically, I've shown in the code exactly what's wrong.
When I jump off a building and get my health to 20 or less, it's supposed to use the lay animation and not allow my player to be able to move but it's not working.
Reply
#2

EDIT: I'm stupid

EDIT 2: Is
pawn Код:
PlayerInfo[playerid][pHealth]
set to correlate with the player's actual health?
Reply
#3

Still doesn't work :/
The rest does, just not:

pawn Код:
if(PlayerInfo[playerid][pHealth] <= 20) // Why won't this work?
        {
            SetPlayerHealth(playerid, PlayerInfo[playerid][pHealth]);
            ApplyAnimation(playerid,"BEACH", "bather", 4.0, 0, 0, 0, 0, 0);
            TogglePlayerControllable(playerid, 0);
        }
Reply
#4

GetPlayerHealth doesn't work under OnPlayerGive/TakeDamage because of the way Get...() functions work. Most of them (if not all) get data stored on the SERVER when a client syncs (OnPlayerUpdate); they don't 'query' the client. The problem here is that the new health isn't synced before OnPlayerGive/TakeDamage is called, so GetPlayerHealth etc. won't work.

Perhaps my latest include may assist you: https://sampforum.blast.hk/showthread.php?tid=414939

I guess you just have to GetPlayerHealth and remove 'healthloss' and you'll get the new values. If health-healthloss <= 20 do something.
Reply
#5

Cheers man, I'll see what I can do.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)