Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- - Latest stable version.
- - Fixed bugs.
- - Added whitelist cfg for boss entity's, so now plugin will track dmg if boss name have in whitelist cfg.
- - math_counter working now, but hpbar still need fix.
- */
- #define PLUGIN_NAME "[ZR] BossHUD"
- #define PLUGIN_AUTHOR "Null138, edits by sTc"
- #define PLUGIN_DESCRIPTION "Keeps track of boss entities (func_breakable etc.) and displays their current HP on damaging"
- #include <sourcemod>
- #include <sdktools>
- #include <sdkhooks>
- #include <multicolors>
- #pragma semicolon 1
- #pragma newdecls required
- enum bosses
- {
- String:targetname[64],
- String:customname[64]
- };
- int bossEnt[512][bosses];
- int bossEntArraySize = 512;
- //int Dmg[MAXPLAYERS+1]; //Global Damage variable
- //int Hits2[MAXPLAYERS+1]; //Global Hits variable(for math_counter bosses)
- bool g_bConfigLoaded = false;
- Handle g_bHudSync = INVALID_HANDLE;
- public Plugin myinfo = {
- name = PLUGIN_NAME,
- author = PLUGIN_AUTHOR,
- description = PLUGIN_DESCRIPTION
- };
- public void OnPluginStart()
- {
- g_bHudSync = CreateHudSynchronizer();
- HookEntityOutput("math_counter", "OutValue", DamageCounter);
- HookEntityOutput("func_physbox", "OnHealthChanged", OnHealthChanged);
- HookEntityOutput("func_physbox_multiplayer", "OnHealthChanged", OnHealthChanged);
- HookEntityOutput("func_breakable", "OnHealthChanged", OnHealthChanged);
- HookEvent("round_start", RoundStart, EventHookMode_PostNoCopy);
- }
- public void OnMapStart() {
- /*for (int i = 0; i <= (LINES - 1); i++)
- Buffer[i] = "";
- char cfgpath[PLATFORM_MAX_PATH];
- char Line[192];
- BuildPath(Path_SM, cfgpath, sizeof(cfgpath), "configs/topbossdmg/topbossdmg.cfg"); //path of cfg
- Handle hFile = OpenFile(cfgpath, "r");
- if(hFile != INVALID_HANDLE) {
- int iLine = 0;
- while (!IsEndOfFile(hFile)) {
- if (!ReadFileLine(hFile, Line, sizeof(Line)))
- break;
- int comment;
- comment = StrContains(Line, "//");
- if (comment != -1) {
- Line[comment] = 0;
- }
- TrimString(Line);
- Buffer[iLine] = Line;
- iLine++;
- }
- CloseHandle(hFile);
- }
- else {
- LogError("[SM] File not found! (configs/topbossdmg/topbossdmg.cfg)");
- }*/
- ClearConfig();
- LoadBossConfig();
- }
- public void RoundStart(Event event, char[] name, bool dontBroadcast)
- {
- /*for (int i = 1; i <= MaxClients; i++) {
- Dmg[i] = 0; //reset all players damages to boss
- Hits2[i] = 0; //reset all players hits to boss
- }*/
- if(g_bConfigLoaded)
- {
- CreateTimer(2.5, Start_MSG);
- }
- }
- public Action Start_MSG(Handle timer)
- {
- if(g_bConfigLoaded)
- {
- CPrintToChatAll("\x04[BossHUD] \x05The current map is supported by this plugin.");
- }
- }
- //HOOKS
- /*public void OnEntityCreated(int entity, const char[] classname)
- {
- if(StrEqual(classname, "func_physbox", false) || StrEqual(classname, "func_physbox_multiplayer", false) || StrEqual(classname, "func_breakable", false))
- {
- if (IsValidEntity(entity))
- {
- if(!IsBossBreakable(entity))
- return;
- SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage);
- }
- }
- }*/
- public Action OnHealthChanged(const char[] output, int entity, int activator, float delay)
- {
- if (IsValidEntity(entity) && IsValidClient(activator))
- {
- int health;
- char buffer[64];
- GetEntPropString(entity, Prop_Data, "m_iName", buffer, sizeof(buffer));
- health = GetEntProp(entity, Prop_Data, "m_iHealth");
- for(int index = 0; index < bossEntArraySize; index++)
- {
- if(StrEqual(buffer, bossEnt[index][targetname]))
- {
- SetHudTextParams(-1.0, -1.0, 0.2, 255, 0, 0, 255, 0, 6.0, 0.0, 0.0);
- //SetHudTextParams(-0.483, 0.471, 0.5, 179, 0, 0, 100, 0, 0.1, 0.1, 0.1);
- ClearSyncHud(activator, g_bHudSync);
- for(int client = 1; client < MaxClients; client++){
- if(!IsValidClient(client))
- continue;
- PrintHintText(client, "%s<br><font color='#00ff00'><span class='fontSize-xl'>HP: %d</span></font>", bossEnt[index][customname], health);
- }
- ShowSyncHudText(activator, g_bHudSync, "◞ ◟\n◝ ◜");
- }
- }
- //int idmg = RoundToFloor(damage);
- //Dmg[attacker] += idmg;
- }
- }
- public void DamageCounter(const char[] output, int caller, int activator, float delay)
- {
- if(IsValidEntity(caller) && IsValidClient(activator))
- {
- int health;
- char buffer[64];
- GetEntPropString(caller, Prop_Data, "m_iName", buffer, sizeof(buffer));
- health = RoundToNearest(GetEntDataFloat(caller, FindDataMapInfo(caller, "m_OutValue")));
- for(int index = 0; index < bossEntArraySize; index++)
- {
- if(StrEqual(buffer, bossEnt[index][targetname]))
- {
- SetHudTextParams(-1.0, -1.0, 0.2, 255, 0, 0, 255, 0, 6.0, 0.0, 0.0);
- //SetHudTextParams(-0.483, 0.471, 0.5, 179, 0, 0, 100, 0, 0.1, 0.1, 0.1);
- ClearSyncHud(activator, g_bHudSync);
- for(int client = 1; client < MaxClients; client++){
- if(!IsValidClient(client))
- continue;
- PrintHintText(client, "%s<br><font color='#00ff00'><span class='fontSize-xl'>HP: %d</span></font>", bossEnt[index][customname], health);
- }
- ShowSyncHudText(activator, g_bHudSync, "◞ ◟\n◝ ◜");
- }
- }
- }
- /*if((activator > 0 && activator <= MaxClients && IsClientInGame(activator)))
- {
- Hits2[activator] += 1;
- }
- static int offset = -1;
- if (offset == -1)
- offset = FindDataMapInfo(caller, "m_OutValue");
- float value = GetEntDataFloat(caller, offset);
- int hpcount = RoundToFloor(value);
- if(hpcount <= 1)
- {
- CounterBossDestroyed();
- }*/
- }
- /*public void OnEntityDestroyed(int entity) {
- char classname2[32];
- char cname3[32];
- if (IsValidEntity(entity))
- {
- GetEntityClassname(entity, classname2, sizeof(classname2));
- GetEntPropString(entity, Prop_Data, "m_iName", cname3, sizeof(cname3));
- if(strlen(cname3) == 0)
- return;
- if(StrEqual(classname2, "func_physbox", false) || StrEqual(classname2, "func_physbox_multiplayer", false) || StrEqual(classname2, "func_breakable", false))
- {
- if (!EntityIsBossD(entity))
- return;
- DmgBossDestroyed();
- }
- }
- }*/
- //FUNCTIONS
- /*public Action DmgBossDestroyed()
- {
- int df, ds, dt;
- //SORTING
- for (int i = 1; i <= MaxClients; i++) {
- if (IsClientInGame(i) && Dmg[i] >= Dmg[df]) {
- df = i;
- }
- }
- for (int i = 1; i <= MaxClients; i++) {
- if (i != df && IsClientInGame(i) && Dmg[i] >= Dmg[ds]) {
- ds = i;
- }
- }
- for (int i = 1; i <= MaxClients; i++) {
- if (i != df && i != ds && IsClientInGame(i) && Dmg[i] >= Dmg[dt]) {
- dt = i;
- }
- }
- char top1[170];
- Format(top1,sizeof(top1), "TOP BOSS DAMAGER\n*****************************\n1. %N - DAMAGE %i\n*****************************", df, Dmg[df]);
- char top2[170];
- Format(top2,sizeof(top2), "TOP BOSS DAMAGERS\n*****************************\n1. %N - DAMAGE %i\n2. %N - DAMAGE %i\n*****************************", df, Dmg[df], ds, Dmg[ds]);
- char top3[170];
- 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]);
- if(Dmg[dt]>=30) {
- for (int client = 1; client <= MaxClients; client++) {
- if (client == 0)
- return;
- if(IsClientInGame(client) && !IsFakeClient(client)) {
- SetHudTextParams(-0.83, -0.5, 5.0, 255,0,0,255, 0, 5.0, 0.1, 0.2);
- ShowHudText(client, 5, top3);
- ShowHudText(client, 5, top3);
- ShowHudText(client, 5, top3);
- }
- }
- }
- else if(Dmg[ds]>=30) {
- for (int client = 1; client <= MaxClients; client++) {
- if (client == 0)
- return;
- if(IsClientInGame(client) && !IsFakeClient(client)) {
- SetHudTextParams(-0.83, -0.5, 5.0, 255,0,0,255, 0, 5.0, 0.1, 0.2);
- ShowHudText(client, 5, top2);
- ShowHudText(client, 5, top2);
- ShowHudText(client, 5, top2);
- }
- }
- }
- else if(Dmg[df]>=30) {
- for (int client = 1; client <= MaxClients; client++) {
- if (client == 0)
- return;
- if(IsClientInGame(client) && !IsFakeClient(client)) {
- SetHudTextParams(-0.83, -0.5, 5.0, 255,0,0,255, 0, 5.0, 0.1, 0.2);
- ShowHudText(client, 5, top1);
- ShowHudText(client, 5, top1);
- ShowHudText(client, 5, top1);
- }
- }
- }
- for (int i = 1; i <= MaxClients; i++) {
- Dmg[i] = 0;
- }
- }
- public Action CounterBossDestroyed() {
- int cf, cs, ct;
- //SORTING
- for (int i = 1; i <= MaxClients; i++) {
- if (IsClientInGame(i) && Hits2[i] >= Hits2[cf]) {
- cf = i;
- }
- }
- for (int i = 1; i <= MaxClients; i++) {
- if (i != cf && IsClientInGame(i) && Hits2[i] >= Hits2[cs]) {
- cs = i;
- }
- }
- for (int i = 1; i <= MaxClients; i++) {
- if (i != cf && i != cs && IsClientInGame(i) && Hits2[i] >= Hits2[ct]) {
- ct = i;
- }
- }
- char top1[170];
- Format(top1,sizeof(top1), "TOP BOSS DAMAGER\n*****************************\n1. %N - HITS %i\n*****************************", cf, Hits2[cf]);
- char top2[170];
- Format(top2,sizeof(top2), "TOP BOSS DAMAGERS\n*****************************\n1. %N - HITS %i\n2. %N - HITS %i\n*****************************", cf, Hits2[cf], cs, Hits2[cs]);
- char top3[170];
- 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]);
- if(Hits2[ct]>=3) {
- for (int client = 1; client <= MaxClients; client++) {
- if (client == 0)
- return;
- if(IsClientInGame(client) && !IsFakeClient(client)) {
- SetHudTextParams(-0.83, -0.5, 5.0, 255,0,0,255, 0, 5.0, 0.1, 0.2);
- ShowHudText(client, 5, top3);
- ShowHudText(client, 5, top3);
- ShowHudText(client, 5, top3);
- }
- }
- }
- else if(Hits2[cs]>=3) {
- for (int client = 1; client <= MaxClients; client++) {
- if (client == 0)
- return;
- if(IsClientInGame(client) && !IsFakeClient(client)) {
- SetHudTextParams(-0.83, -0.5, 5.0, 255,0,0,255, 0, 5.0, 0.1, 0.2);
- ShowHudText(client, 5, top2);
- ShowHudText(client, 5, top2);
- ShowHudText(client, 5, top2);
- }
- }
- }
- else if(Hits2[cf]>=3) {
- for (int client = 1; client <= MaxClients; client++) {
- if (client == 0)
- return;
- if(IsClientInGame(client) && !IsFakeClient(client)) {
- SetHudTextParams(-0.83, -0.5, 5.0, 255,0,0,255, 0, 5.0, 0.1, 0.2);
- ShowHudText(client, 5, top1);
- ShowHudText(client, 5, top1);
- ShowHudText(client, 5, top1);
- }
- }
- }
- for (int i = 1; i <= MaxClients; i++) {
- Hits2[i] = 0;
- }
- }*/
- //STOCKS
- stock bool IsValidClient(int client)
- {
- return (0 < client <= MaxClients && IsClientInGame(client));
- }
- stock bool IsBossBreakable(int entity) { //If boss damageable
- char buffer[64];
- GetEntPropString(entity, Prop_Data, "m_iName", buffer, sizeof(buffer));
- for (int index = 0; index < bossEntArraySize; index++)
- {
- if (StrEqual(buffer, bossEnt[bossEntArraySize][targetname]))
- {
- return true;
- }
- }
- return false;
- }
- /*
- stock bool IsBossCounter(int caller) { //If boss has math_counter
- char buffer[64];
- GetEntPropString(caller, Prop_Data, "m_iName", buffer, sizeof(buffer));
- for (int index = 0; index < bossEntArraySize; index++)
- {
- if (StrEqual(buffer, bossEnt[bossEntArraySize][targetname]))
- {
- return true;
- }
- }
- return false;
- }*/
- stock void LoadBossConfig()
- {
- char buffer_map[128];
- char buffer_path[PLATFORM_MAX_PATH];
- char buffer_temp[64];
- GetCurrentMap(buffer_map, sizeof(buffer_map));
- Format(buffer_path, sizeof(buffer_path), "cfg/sourcemod/bosshud/maps/%s.cfg", buffer_map);
- if(!FileExists(buffer_path))
- {
- LogMessage("Could not find mapconfig: \"%s\"", buffer_path);
- return;
- }
- LogMessage("Found mapconfig: \"%s\"", buffer_path);
- KeyValues hKeyValues = new KeyValues("bosses");
- if(!hKeyValues.ImportFromFile(buffer_path))
- {
- delete hKeyValues;
- LogError("Error: ImportFromFile() failed!");
- return;
- }
- hKeyValues.Rewind();
- if(!hKeyValues.GotoFirstSubKey())
- {
- delete hKeyValues;
- LogError("Error: GotoFirstSubKey() failed!");
- return;
- }
- g_bConfigLoaded = true;
- bossEntArraySize = 0;
- do
- {
- hKeyValues.GetString("targetname", buffer_temp, sizeof(buffer_temp));
- Format(bossEnt[bossEntArraySize][targetname], 64, "%s", buffer_temp);
- if(!hKeyValues.GetString("customname", buffer_temp, sizeof(buffer_temp)))
- {
- Format(bossEnt[bossEntArraySize][customname], 64, "Boss");
- }
- else
- {
- if(buffer_temp[0])
- {
- Format(bossEnt[bossEntArraySize][customname], 64, "%s", buffer_temp);
- }
- else
- {
- Format(bossEnt[bossEntArraySize][customname], 64, "Boss");
- }
- }
- bossEntArraySize++;
- }
- while(hKeyValues.GotoNextKey(false));
- delete hKeyValues;
- }
- stock void ClearConfig()
- {
- for(int index = 0; index < bossEntArraySize; index++)
- {
- Format(bossEnt[index][targetname], 64, "");
- Format(bossEnt[index][customname], 64, "");
- }
- bossEntArraySize = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement