OnPlayerTakeDamage Help - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerTakeDamage Help (
/showthread.php?tid=415623)
OnPlayerTakeDamage Help -
AphexCCFC - 13.02.2013
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.
Re: OnPlayerTakeDamage Help -
austin070 - 13.02.2013
EDIT: I'm stupid
EDIT 2: Is
pawn Код:
PlayerInfo[playerid][pHealth]
set to correlate with the player's actual health?
Re: OnPlayerTakeDamage Help -
AphexCCFC - 13.02.2013
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);
}
Re: OnPlayerTakeDamage Help -
MP2 - 13.02.2013
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.
Re: OnPlayerTakeDamage Help -
AphexCCFC - 13.02.2013
Cheers man, I'll see what I can do.