06.02.2018, 09:20
How do I make a 3d attachement above player's head whenever they get hit so it says like
" -60 hp"
" 40 hp left"
" -60 hp"
" 40 hp left"
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
if(issuerid != INVALID_PLAYER_ID) // If not self-inflicted
{
new
infoString[128],
victimName[MAX_PLAYER_NAME],
attackerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, victimName, sizeof (victimName));
GetPlayerName(issuerid, attackerName, sizeof (attackerName));
new str[30];
new Float:health;
format(str, sizeof(str), "-%.0f HP\n%d HP Left", amount, GetPlayerHealth(issuerid, health));
new Text3D:HealthLabel = Create3DTextLabel(infoString, 0x00AE00FF, 0,0, 0, 20.0, 0, 1);
Attach3DTextLabelToPlayer(HealthLabel, issuerid, 0.0, 0.0, 2.0);
}
return 1;
}
Untested, let me know if problem persists.
EDIT: I saw that this will not delete the 3Dlabel once created so what you can do is; add timer to delete it. |
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
new string[50], playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
if(playerid != INVALID_PLAYER_ID && issuerid != INVALID_PLAYER_ID)
{
SetTimerEx("DamageString", 10, false, "i", issuerid);
format(string, sizeof(string), "{800000}-%.0f damage by {800000}%s", amount, playername(issuerid));
SetPlayerChatBubble(playerid, string, COLOR_GREY, 60.0, 3000);
}
return 1;
}