Nyzenic

Custom Player Nametags

Apr 13th, 2019
970
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Custom Player Nametags
  3.     ----- by Nyzenic -----
  4.     https://forum.sa-mp.com/showthread.php?p=4004123
  5.  
  6.     Make sure to put this under OnGameModeInit!
  7.         ShowNameTags(0);
  8. */
  9. #define FILTERSCRIPT
  10.  
  11. #include <a_samp>
  12. #include <streamer>
  13. #include <foreach>
  14.  
  15. #define NT_DISTANCE 25.0
  16.  
  17. new Text3D:cNametag[MAX_PLAYERS];
  18.  
  19. public OnFilterScriptInit()
  20. {
  21.     print("--- Custom nametags by Nyzenic loaded.");
  22.     // OnPlayerUpdate causes lag and OnPlayer(Take/Give)Damage doesn't work with it
  23.     SetTimer("UpdateNametag", 500, true); // So we're using a timer, change the interval to what you want
  24.     return 1;
  25. }
  26. GetHealthDots(playerid)
  27. {
  28.     new
  29.         dots[64], Float: HP;
  30.  
  31.     GetPlayerHealth(playerid, HP);
  32.  
  33.     if(HP >= 100)
  34.         dots = "••••••••••";
  35.     else if(HP >= 90)
  36.         dots = "•••••••••{660000}•";
  37.     else if(HP >= 80)
  38.         dots = "••••••••{660000}••";
  39.     else if(HP >= 70)
  40.         dots = "•••••••{660000}•••";
  41.     else if(HP >= 60)
  42.         dots = "••••••{660000}••••";
  43.     else if(HP >= 50)
  44.         dots = "•••••{660000}•••••";
  45.     else if(HP >= 40)
  46.         dots = "••••{660000}••••••";
  47.     else if(HP >= 30)
  48.         dots = "•••{660000}•••••••";
  49.     else if(HP >= 20)
  50.         dots = "••{660000}••••••••";
  51.     else if(HP >= 10)
  52.         dots = "•{660000}•••••••••";
  53.     else if(HP >= 0)
  54.         dots = "{660000}••••••••••";
  55.  
  56.     return dots;
  57. }
  58.  
  59. GetArmorDots(playerid)
  60. {
  61.     new
  62.         dots[64], Float: AR;
  63.  
  64.     GetPlayerArmour(playerid, AR);
  65.  
  66.     if(AR >= 100)
  67.         dots = "••••••••••";
  68.     else if(AR >= 90)
  69.         dots = "•••••••••{666666}•";
  70.     else if(AR >= 80)
  71.         dots = "••••••••{666666}••";
  72.     else if(AR >= 70)
  73.         dots = "•••••••{666666}•••";
  74.     else if(AR >= 60)
  75.         dots = "••••••{666666}••••";
  76.     else if(AR >= 50)
  77.         dots = "•••••{666666}•••••";
  78.     else if(AR >= 40)
  79.         dots = "••••{666666}••••••";
  80.     else if(AR >= 30)
  81.         dots = "•••{666666}•••••••";
  82.     else if(AR >= 20)
  83.         dots = "••{666666}••••••••";
  84.     else if(AR >= 10)
  85.         dots = "•{666666}•••••••••";
  86.     else if(AR >= 0)
  87.         dots = "{666666}••••••••••";
  88.  
  89.     return dots;
  90. }
  91.  
  92. public OnPlayerConnect(playerid)
  93. {
  94.     cNametag[playerid] = CreateDynamic3DTextLabel("Loading nametag...", 0xFFFFFFFF, 0.0, 0.0, 0.1, NT_DISTANCE, .attachedplayer = playerid, .testlos = 1);
  95.     return 1;
  96. }
  97. public OnPlayerDisconnect(playerid, reason)
  98. {
  99.     if(IsValidDynamic3DTextLabel(cNametag[playerid]))
  100.               DestroyDynamic3DTextLabel(cNametag[playerid]);
  101.     return 1;
  102. }
  103. forward UpdateNametag();
  104. public UpdateNametag()
  105. {
  106.     foreach(new i : Player)
  107.     {
  108.         if(IsPlayerConnected(i))
  109.         {
  110.             new nametag[128], playername[MAX_PLAYER_NAME], Float:armour;
  111.             GetPlayerArmour(i, armour);
  112.             GetPlayerName(i, playername, sizeof(playername));
  113.             if(armour > 1.0)
  114.             {
  115.                 format(nametag, sizeof(nametag), "{%06x}%s {FFFFFF}(%i)\n{FFFFFF}%s\n{FF0000}%s", GetPlayerColor(i) >>> 8, playername, i, GetArmorDots(i), GetHealthDots(i));
  116.             }
  117.             else
  118.             {
  119.                 format(nametag, sizeof(nametag), "{%06x}%s {FFFFFF}(%i)\n{FF0000}%s", GetPlayerColor(i) >>> 8, playername, i, GetHealthDots(i));
  120.             }
  121.             UpdateDynamic3DTextLabelText(cNametag[i], 0xFFFFFFFF, nametag);
  122.         }
  123.     }
  124. }
RAW Paste Data