Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.87 KB | None | 0 0
  1. /*
  2.   - Latest stable version.
  3.   - Fixed bugs.
  4.   - Added whitelist cfg for boss entity's, so now plugin will track dmg if boss name have in whitelist cfg.
  5.   - math_counter working now, but hpbar still need fix.  
  6. */
  7.  
  8. #define PLUGIN_NAME         "[ZR] BossHUD"
  9. #define PLUGIN_AUTHOR       "Null138, edits by sTc"
  10. #define PLUGIN_DESCRIPTION  "Keeps track of boss entities (func_breakable etc.) and displays their current HP on damaging"
  11.  
  12. #include <sourcemod>
  13. #include <sdktools>
  14. #include <sdkhooks>
  15. #include <multicolors>
  16.  
  17. #pragma semicolon 1
  18. #pragma newdecls required
  19.  
  20. enum bosses
  21. {
  22.     String:targetname[64],
  23.     String:customname[64]
  24. };
  25.  
  26. int bossEnt[512][bosses];
  27. int bossEntArraySize = 512;
  28. //int Dmg[MAXPLAYERS+1]; //Global Damage variable
  29. //int Hits2[MAXPLAYERS+1]; //Global Hits variable(for math_counter bosses)
  30.  
  31. bool g_bConfigLoaded = false;
  32.  
  33. Handle g_bHudSync = INVALID_HANDLE;
  34.  
  35. public Plugin myinfo = {
  36.     name = PLUGIN_NAME,
  37.     author = PLUGIN_AUTHOR,
  38.     description = PLUGIN_DESCRIPTION
  39. };
  40.  
  41. public void OnPluginStart()
  42. {
  43.     g_bHudSync = CreateHudSynchronizer();
  44.  
  45.     HookEntityOutput("math_counter", "OutValue", DamageCounter);
  46.     HookEntityOutput("func_physbox", "OnHealthChanged", OnHealthChanged);
  47.     HookEntityOutput("func_physbox_multiplayer", "OnHealthChanged", OnHealthChanged);
  48.     HookEntityOutput("func_breakable", "OnHealthChanged", OnHealthChanged);
  49.     HookEvent("round_start", RoundStart, EventHookMode_PostNoCopy);
  50. }
  51.  
  52. public void OnMapStart() {
  53.     /*for (int i = 0; i <= (LINES - 1); i++)
  54.         Buffer[i] = "";
  55.  
  56.     char cfgpath[PLATFORM_MAX_PATH];
  57.     char Line[192];
  58.  
  59.     BuildPath(Path_SM, cfgpath, sizeof(cfgpath), "configs/topbossdmg/topbossdmg.cfg"); //path of cfg
  60.  
  61.     Handle hFile = OpenFile(cfgpath, "r");
  62.  
  63.     if(hFile != INVALID_HANDLE) {
  64.         int iLine = 0;
  65.         while (!IsEndOfFile(hFile)) {
  66.             if (!ReadFileLine(hFile, Line, sizeof(Line)))
  67.                 break;
  68.                
  69.             int comment;
  70.             comment = StrContains(Line, "//");
  71.             if (comment != -1) {
  72.                 Line[comment] = 0;
  73.             }
  74.            
  75.             TrimString(Line);
  76.             Buffer[iLine] = Line;
  77.             iLine++;
  78.         }
  79.         CloseHandle(hFile);
  80.     }
  81.     else {
  82.         LogError("[SM] File not found! (configs/topbossdmg/topbossdmg.cfg)");
  83.     }*/
  84.  
  85.     ClearConfig();
  86.     LoadBossConfig();
  87. }
  88.  
  89. public void RoundStart(Event event, char[] name, bool dontBroadcast)
  90. {
  91.     /*for (int i = 1; i <= MaxClients; i++) {  
  92.         Dmg[i] = 0; //reset all players damages to boss
  93.         Hits2[i] = 0; //reset all players hits to boss
  94.     }*/
  95.     if(g_bConfigLoaded)
  96.     {
  97.         CreateTimer(2.5, Start_MSG);
  98.     }
  99. }
  100.  
  101. public Action Start_MSG(Handle timer)
  102. {
  103.     if(g_bConfigLoaded)
  104.     {
  105.         CPrintToChatAll("\x04[BossHUD] \x05The current map is supported by this plugin.");
  106.     }
  107. }
  108.  
  109. //HOOKS
  110.  
  111. /*public void OnEntityCreated(int entity, const char[] classname)
  112. {
  113.     if(StrEqual(classname, "func_physbox", false) || StrEqual(classname, "func_physbox_multiplayer", false) || StrEqual(classname, "func_breakable", false))
  114.     {
  115.         if (IsValidEntity(entity))
  116.         {
  117.             if(!IsBossBreakable(entity))
  118.                 return;
  119.             SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
  120.         }
  121.     }
  122. }*/
  123.  
  124. public Action OnHealthChanged(const char[] output, int entity, int activator, float delay)
  125. {  
  126.     if (IsValidEntity(entity) && IsValidClient(activator))
  127.     {
  128.         int health;
  129.         char buffer[64];
  130.  
  131.         GetEntPropString(entity, Prop_Data, "m_iName", buffer, sizeof(buffer));
  132.         health = GetEntProp(entity, Prop_Data, "m_iHealth");
  133.  
  134.         for(int index = 0; index < bossEntArraySize; index++)
  135.         {
  136.             if(StrEqual(buffer, bossEnt[index][targetname]))
  137.             {
  138.                 SetHudTextParams(-1.0, -1.0, 0.2, 255, 0, 0, 255, 0, 6.0, 0.0, 0.0);
  139.                 //SetHudTextParams(-0.483, 0.471, 0.5, 179, 0, 0, 100, 0, 0.1, 0.1, 0.1);
  140.                 ClearSyncHud(activator, g_bHudSync);
  141.                
  142.                 for(int client = 1; client < MaxClients; client++){
  143.                     if(!IsValidClient(client))
  144.                         continue;
  145.  
  146.                     PrintHintText(client, "%s<br><font color='#00ff00'><span class='fontSize-xl'>HP: %d</span></font>", bossEnt[index][customname], health);
  147.                 }
  148.                 ShowSyncHudText(activator, g_bHudSync, "◞  ◟\n◝  ◜");
  149.             }    
  150.         }  
  151.         //int idmg = RoundToFloor(damage);
  152.         //Dmg[attacker] += idmg;
  153.     }      
  154. }
  155.  
  156.  
  157. public void DamageCounter(const char[] output, int caller, int activator, float delay)
  158. {  
  159.     if(IsValidEntity(caller) && IsValidClient(activator))
  160.     {  
  161.         int health;
  162.         char buffer[64];
  163.        
  164.         GetEntPropString(caller, Prop_Data, "m_iName", buffer, sizeof(buffer));
  165.         health = RoundToNearest(GetEntDataFloat(caller, FindDataMapInfo(caller, "m_OutValue")));
  166.  
  167.         for(int index = 0; index < bossEntArraySize; index++)
  168.         {
  169.             if(StrEqual(buffer, bossEnt[index][targetname]))
  170.             {
  171.                 SetHudTextParams(-1.0, -1.0, 0.2, 255, 0, 0, 255, 0, 6.0, 0.0, 0.0);
  172.                 //SetHudTextParams(-0.483, 0.471, 0.5, 179, 0, 0, 100, 0, 0.1, 0.1, 0.1);
  173.                 ClearSyncHud(activator, g_bHudSync);
  174.                
  175.                 for(int client = 1; client < MaxClients; client++){
  176.                     if(!IsValidClient(client))
  177.                         continue;
  178.  
  179.                     PrintHintText(client, "%s<br><font color='#00ff00'><span class='fontSize-xl'>HP: %d</span></font>", bossEnt[index][customname], health);
  180.                 }
  181.                 ShowSyncHudText(activator, g_bHudSync, "◞  ◟\n◝  ◜");
  182.             }    
  183.         }            
  184.     }
  185.     /*if((activator > 0 && activator <= MaxClients && IsClientInGame(activator)))
  186.     {
  187.         Hits2[activator] += 1;
  188.     }
  189.    
  190.     static int offset = -1;
  191.     if (offset == -1)
  192.         offset = FindDataMapInfo(caller, "m_OutValue");
  193.         float value = GetEntDataFloat(caller, offset);
  194.         int hpcount = RoundToFloor(value);
  195.    
  196.     if(hpcount <= 1)
  197.     {
  198.         CounterBossDestroyed();
  199.     }*/
  200. }
  201.  
  202. /*public void OnEntityDestroyed(int entity) {
  203.     char classname2[32];
  204.     char cname3[32];
  205.    
  206.     if (IsValidEntity(entity))
  207.     {
  208.         GetEntityClassname(entity, classname2, sizeof(classname2));
  209.         GetEntPropString(entity, Prop_Data, "m_iName", cname3, sizeof(cname3));
  210.    
  211.         if(strlen(cname3) == 0)
  212.             return;
  213.            
  214.         if(StrEqual(classname2, "func_physbox", false) || StrEqual(classname2, "func_physbox_multiplayer", false) || StrEqual(classname2, "func_breakable", false))
  215.         {
  216.             if (!EntityIsBossD(entity))
  217.                 return;
  218.            
  219.             DmgBossDestroyed();
  220.         }  
  221.     }  
  222. }*/
  223.  
  224. //FUNCTIONS
  225.  
  226. /*public Action DmgBossDestroyed()
  227. {
  228.  
  229.     int df, ds, dt;
  230.    
  231.     //SORTING
  232.    
  233.     for (int i = 1; i <= MaxClients; i++) {
  234.         if (IsClientInGame(i) && Dmg[i] >= Dmg[df]) {
  235.             df = i;
  236.         }
  237.     }
  238.     for (int i = 1; i <= MaxClients; i++) {
  239.         if (i != df && IsClientInGame(i) && Dmg[i] >= Dmg[ds]) {          
  240.             ds = i;
  241.         }
  242.     }      
  243.     for (int i = 1; i <= MaxClients; i++) {
  244.         if (i != df && i != ds && IsClientInGame(i)  && Dmg[i] >= Dmg[dt]) {
  245.             dt = i;
  246.         }
  247.     }
  248.    
  249.     char top1[170];
  250.     Format(top1,sizeof(top1), "TOP BOSS DAMAGER\n*****************************\n1. %N - DAMAGE %i\n*****************************", df, Dmg[df]);
  251.    
  252.     char top2[170];
  253.     Format(top2,sizeof(top2), "TOP BOSS DAMAGERS\n*****************************\n1. %N - DAMAGE %i\n2. %N - DAMAGE %i\n*****************************", df, Dmg[df], ds, Dmg[ds]);
  254.    
  255.     char top3[170];
  256.     Format(top3,sizeof(top3), "TOP BOSS DAMAGERS\n*****************************\n1. %N - DAMAGE %i\n2. %N - DAMAGE %i\n3. %N - DAMAGE %i\n*****************************", df, Dmg[df], ds, Dmg[ds], dt, Dmg[dt]);
  257.            
  258.     if(Dmg[dt]>=30) {
  259.         for (int client = 1; client <= MaxClients; client++) {
  260.             if (client == 0)
  261.                 return;
  262.  
  263.             if(IsClientInGame(client) && !IsFakeClient(client)) {
  264.                 SetHudTextParams(-0.83, -0.5, 5.0, 255,0,0,255, 0, 5.0, 0.1, 0.2);
  265.                 ShowHudText(client, 5, top3);
  266.                 ShowHudText(client, 5, top3);
  267.                 ShowHudText(client, 5, top3);
  268.             }
  269.         }
  270.     }
  271.     else if(Dmg[ds]>=30) {
  272.         for (int client = 1; client <= MaxClients; client++) {
  273.             if (client == 0)
  274.                 return;
  275.  
  276.             if(IsClientInGame(client) && !IsFakeClient(client)) {
  277.                 SetHudTextParams(-0.83, -0.5, 5.0, 255,0,0,255, 0, 5.0, 0.1, 0.2);
  278.                 ShowHudText(client, 5, top2);
  279.                 ShowHudText(client, 5, top2);
  280.                 ShowHudText(client, 5, top2);
  281.             }
  282.         }
  283.     }
  284.     else if(Dmg[df]>=30) {
  285.         for (int client = 1; client <= MaxClients; client++) {
  286.             if (client == 0)
  287.                 return;
  288.  
  289.             if(IsClientInGame(client) && !IsFakeClient(client)) {
  290.                 SetHudTextParams(-0.83, -0.5, 5.0, 255,0,0,255, 0, 5.0, 0.1, 0.2);
  291.                 ShowHudText(client, 5, top1);
  292.                 ShowHudText(client, 5, top1);
  293.                 ShowHudText(client, 5, top1);
  294.             }
  295.         }
  296.     }      
  297.     for (int i = 1; i <= MaxClients; i++) {
  298.         Dmg[i] = 0;
  299.     }  
  300. }
  301.  
  302. public Action CounterBossDestroyed() {
  303.  
  304.     int cf, cs, ct;
  305.    
  306.     //SORTING
  307.    
  308.     for (int i = 1; i <= MaxClients; i++) {
  309.         if (IsClientInGame(i) && Hits2[i] >= Hits2[cf]) {
  310.             cf = i;
  311.         }
  312.     }
  313.     for (int i = 1; i <= MaxClients; i++) {
  314.         if (i != cf && IsClientInGame(i) && Hits2[i] >= Hits2[cs]) {          
  315.             cs = i;
  316.         }
  317.     }      
  318.     for (int i = 1; i <= MaxClients; i++) {
  319.         if (i != cf && i != cs && IsClientInGame(i)  && Hits2[i] >= Hits2[ct]) {
  320.             ct = i;
  321.         }
  322.     }
  323.    
  324.     char top1[170];
  325.     Format(top1,sizeof(top1), "TOP BOSS DAMAGER\n*****************************\n1. %N - HITS %i\n*****************************", cf, Hits2[cf]);
  326.    
  327.     char top2[170];
  328.     Format(top2,sizeof(top2), "TOP BOSS DAMAGERS\n*****************************\n1. %N - HITS %i\n2. %N - HITS %i\n*****************************", cf, Hits2[cf], cs, Hits2[cs]);
  329.    
  330.     char top3[170];
  331.     Format(top3,sizeof(top3), "TOP BOSS DAMAGERS\n*****************************\n1. %N - HITS %i\n2. %N - HITS %i\n3. %N - HITS %i\n*****************************", cf, Hits2[cf], cs, Hits2[cs], ct, Hits2[ct]);
  332.            
  333.     if(Hits2[ct]>=3) {
  334.         for (int client = 1; client <= MaxClients; client++) {
  335.             if (client == 0)
  336.                 return;
  337.  
  338.             if(IsClientInGame(client) && !IsFakeClient(client)) {
  339.                 SetHudTextParams(-0.83, -0.5, 5.0, 255,0,0,255, 0, 5.0, 0.1, 0.2);
  340.                 ShowHudText(client, 5, top3);
  341.                 ShowHudText(client, 5, top3);
  342.                 ShowHudText(client, 5, top3);
  343.             }
  344.         }
  345.     }
  346.     else if(Hits2[cs]>=3) {
  347.         for (int client = 1; client <= MaxClients; client++) {
  348.             if (client == 0)
  349.                 return;
  350.  
  351.             if(IsClientInGame(client) && !IsFakeClient(client)) {
  352.                 SetHudTextParams(-0.83, -0.5, 5.0, 255,0,0,255, 0, 5.0, 0.1, 0.2);
  353.                 ShowHudText(client, 5, top2);
  354.                 ShowHudText(client, 5, top2);
  355.                 ShowHudText(client, 5, top2);
  356.             }
  357.         }
  358.     }
  359.     else if(Hits2[cf]>=3) {
  360.         for (int client = 1; client <= MaxClients; client++) {
  361.             if (client == 0)
  362.                 return;
  363.  
  364.             if(IsClientInGame(client) && !IsFakeClient(client)) {
  365.                 SetHudTextParams(-0.83, -0.5, 5.0, 255,0,0,255, 0, 5.0, 0.1, 0.2);
  366.                 ShowHudText(client, 5, top1);
  367.                 ShowHudText(client, 5, top1);
  368.                 ShowHudText(client, 5, top1);
  369.             }
  370.         }
  371.     }      
  372.     for (int i = 1; i <= MaxClients; i++) {
  373.         Hits2[i] = 0;
  374.     }  
  375. }*/
  376.  
  377. //STOCKS
  378.  
  379. stock bool IsValidClient(int client)
  380. {
  381.     return (0 < client <= MaxClients && IsClientInGame(client));
  382. }
  383.  
  384. stock bool IsBossBreakable(int entity) { //If boss damageable
  385.     char buffer[64];
  386.     GetEntPropString(entity, Prop_Data, "m_iName", buffer, sizeof(buffer));
  387.  
  388.     for (int index = 0; index < bossEntArraySize; index++)
  389.     {
  390.         if (StrEqual(buffer, bossEnt[bossEntArraySize][targetname]))
  391.         {
  392.             return true;  
  393.         }
  394.     }      
  395.     return false;
  396. }
  397.  
  398. /*
  399. stock bool IsBossCounter(int caller) { //If boss has math_counter
  400.     char buffer[64];
  401.     GetEntPropString(caller, Prop_Data, "m_iName", buffer, sizeof(buffer));
  402.  
  403.     for (int index = 0; index < bossEntArraySize; index++)
  404.     {
  405.         if (StrEqual(buffer, bossEnt[bossEntArraySize][targetname]))
  406.         {
  407.             return true;  
  408.         }
  409.     }    
  410.     return false;
  411. }*/
  412.  
  413. stock void LoadBossConfig()
  414. {
  415.    
  416.     char buffer_map[128];
  417.     char buffer_path[PLATFORM_MAX_PATH];
  418.     char buffer_temp[64];
  419.  
  420.     GetCurrentMap(buffer_map, sizeof(buffer_map));
  421.     Format(buffer_path, sizeof(buffer_path), "cfg/sourcemod/bosshud/maps/%s.cfg", buffer_map);
  422.     if(!FileExists(buffer_path))
  423.     {
  424.         LogMessage("Could not find mapconfig: \"%s\"", buffer_path);
  425.         return;
  426.     }
  427.     LogMessage("Found mapconfig: \"%s\"", buffer_path);
  428.  
  429.     KeyValues hKeyValues = new KeyValues("bosses");
  430.  
  431.     if(!hKeyValues.ImportFromFile(buffer_path))
  432.     {
  433.         delete hKeyValues;
  434.         LogError("Error: ImportFromFile() failed!");
  435.         return;
  436.     }
  437.     hKeyValues.Rewind();
  438.  
  439.     if(!hKeyValues.GotoFirstSubKey())
  440.     {
  441.         delete hKeyValues;
  442.         LogError("Error: GotoFirstSubKey() failed!");
  443.         return;
  444.     }
  445.  
  446.     g_bConfigLoaded = true;
  447.     bossEntArraySize = 0;
  448.  
  449.     do
  450.     {
  451.         hKeyValues.GetString("targetname", buffer_temp, sizeof(buffer_temp));
  452.         Format(bossEnt[bossEntArraySize][targetname], 64, "%s", buffer_temp);
  453.  
  454.         if(!hKeyValues.GetString("customname", buffer_temp, sizeof(buffer_temp)))
  455.         {
  456.             Format(bossEnt[bossEntArraySize][customname], 64, "Boss");
  457.         }
  458.         else
  459.         {
  460.             if(buffer_temp[0])
  461.             {
  462.                 Format(bossEnt[bossEntArraySize][customname], 64, "%s", buffer_temp);            
  463.             }
  464.             else
  465.             {
  466.                 Format(bossEnt[bossEntArraySize][customname], 64, "Boss");
  467.             }                      
  468.         }
  469.        
  470.         bossEntArraySize++;
  471.     }
  472.     while(hKeyValues.GotoNextKey(false));
  473.  
  474.     delete hKeyValues;
  475. }
  476.  
  477. stock void ClearConfig()
  478. {
  479.     for(int index = 0; index < bossEntArraySize; index++)
  480.     {
  481.         Format(bossEnt[index][targetname], 64, "");
  482.         Format(bossEnt[index][customname], 64, "");
  483.     }
  484.  
  485.     bossEntArraySize = 0;
  486. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement