|
| 1 | +#pragma semicolon 1 |
| 2 | +#include <clientprefs> |
| 3 | + |
| 4 | +public Plugin myinfo = |
| 5 | +{ |
| 6 | + name = "Shower of Health", |
| 7 | + version = "1.0", |
| 8 | + description = "Shower of your hp", |
| 9 | + author = "ღ λŌK0ЌЭŦ ღ ™", |
| 10 | + url = "https://github.com/IL0co" |
| 11 | +} |
| 12 | + |
| 13 | +static const char SPACE[][][] = {{"", "", "", "", "", "", ""}, |
| 14 | + {"", " ", " ", " ", " ", " ", " "}, |
| 15 | + {"", " ", " ", " ", " ", " ", " "}, |
| 16 | + {"", " ", " ", " ", " ", " ", " "}, |
| 17 | + {"", " ", " ", " ", " ", " ", " "}, |
| 18 | + {"", " ", " ", " ", " ", " ", " "}, |
| 19 | + {"", " ", " ", " ", " ", " ", " "}, |
| 20 | + {"", " ", " ", " ", " ", " ", " "}}; |
| 21 | + |
| 22 | +char oldValue[MAXPLAYERS+1][5][16]; |
| 23 | +int iHealthNow[MAXPLAYERS+1]; |
| 24 | +float iTime[MAXPLAYERS+1]; |
| 25 | + |
| 26 | +bool g_bHUD[MAXPLAYERS+1]; |
| 27 | + |
| 28 | +Handle g_hCookie, iHud, iTimer[MAXPLAYERS+1]; |
| 29 | + |
| 30 | +ConVar cvar_cCount, |
| 31 | + cvar_cType, |
| 32 | + cvar_cTimeClean, |
| 33 | + cvar_cTimeUpdate, |
| 34 | + cvar_cTypePoss, |
| 35 | + cvar_cHudColor, |
| 36 | + cvar_cHudPoss, |
| 37 | + cvar_cTimeHide, |
| 38 | + cvar_cEnable; |
| 39 | + |
| 40 | +int cCount, cType, cTypePoss, cHudColor[4]; |
| 41 | +float cTimeClean, cTimeUpdate, cHudPoss[2], cTimeHide; |
| 42 | +bool cEnable; |
| 43 | + |
| 44 | +public void OnPluginStart() |
| 45 | +{ |
| 46 | + iHud = CreateHudSynchronizer(); |
| 47 | + g_hCookie = RegClientCookie("shower_health", "shower_health", CookieAccess_Private); |
| 48 | + SetCookieMenuItem(CreditsCookieHandler, 0, "shower_health"); |
| 49 | + for(int i = 1; i <= MaxClients; i++) if(IsClientInGame(i) && IsClientAuthorized(i)) |
| 50 | + OnClientCookiesCached(i); |
| 51 | + |
| 52 | + (cvar_cEnable = CreateConVar("sm_shower_health_enable", "1", "RU: Включен ли плагин?\nEN: Enabled plugin?", _, true, 0.0, true, 1.0)).AddChangeHook(CVarChanged); |
| 53 | + cEnable = cvar_cEnable.BoolValue; |
| 54 | + |
| 55 | + (cvar_cCount = CreateConVar("sm_shower_health_count", "5", "RU: Количество столбиков\nEN: Number of posts", _, true, 1.0, true, 5.0)).AddChangeHook(CVarChanged); |
| 56 | + cCount = cvar_cCount.IntValue; |
| 57 | + |
| 58 | + (cvar_cType = CreateConVar("sm_shower_health_type", "2", "RU: На сколько смещать каждую новую строчку? (в пробелах)\nEN: How much to shift each new line? (in spaces)", _, true, 0.0, true, 7.0)).AddChangeHook(CVarChanged); |
| 59 | + cType = cvar_cType.IntValue; |
| 60 | + |
| 61 | + (cvar_cTypePoss = CreateConVar("sm_shower_health_type_poss", "0", "RU: Куда уходит лесенка начиная от прицела?, 0 - в левый низ, 1 - в правый вверх, 2 - в правый низ, 3 - в левый вверх\nEN: Where does the ladder go from the sight ?, 0 - to the left bottom, 1 - to the right up, 2 - to the right bottom, 3 - to the left up", _, true, 0.0, true, 3.0)).AddChangeHook(CVarChanged); |
| 62 | + cTypePoss = cvar_cTypePoss.IntValue; |
| 63 | + |
| 64 | + (cvar_cTimeClean = CreateConVar("sm_shower_health_clean_time", "2.0", "RU: Время очищения истории\nEN: History Cleansing Time", _, true, 0.1)).AddChangeHook(CVarChanged); |
| 65 | + cTimeClean = cvar_cTimeClean.FloatValue; |
| 66 | + |
| 67 | + (cvar_cTimeUpdate = CreateConVar("sm_shower_health_update_time", "0.5", "Время проверки изменения хп. Требуется рестарт плагина!\nEN: Check time changes hp. Restart plugin required!", _, true, 0.1)).AddChangeHook(CVarChanged); |
| 68 | + cTimeUpdate = cvar_cTimeUpdate.FloatValue; |
| 69 | + |
| 70 | + (cvar_cHudColor = CreateConVar("sm_shower_health_rgba", "255 0 255 255", "RU: RGBA цвет худа\nEN: RGBA color hud")).AddChangeHook(CVarChanged); |
| 71 | + SetHUDColor(cvar_cHudColor); |
| 72 | + |
| 73 | + (cvar_cHudPoss = CreateConVar("sm_shower_health_poss", "0.38 0.5", "RU: XY позиция худа\nEN: XY hud position")).AddChangeHook(CVarChanged); |
| 74 | + SetHUDPosition(cvar_cHudPoss); |
| 75 | + |
| 76 | + (cvar_cTimeHide = CreateConVar("sm_shower_health_hide_time", "2.0", "RU: Время скрытия худа\nEN: Hud hiding time", _, true, 0.1)).AddChangeHook(CVarChanged); |
| 77 | + cTimeHide = cvar_cTimeHide.FloatValue; |
| 78 | + |
| 79 | + AutoExecConfig(true, "shower_health"); |
| 80 | + |
| 81 | + CreateTimer(cTimeUpdate, timerhealthOut, _, TIMER_REPEAT); |
| 82 | + LoadTranslations("shower_base.phrases"); |
| 83 | +} |
| 84 | + |
| 85 | +public void CVarChanged(ConVar cvar, const char[] oldVal, const char[] newVal) |
| 86 | +{ |
| 87 | + if(cvar == cvar_cCount) cCount = cvar.IntValue; |
| 88 | + else if(cvar == cvar_cType) cType = cvar.IntValue; |
| 89 | + else if(cvar == cvar_cTypePoss) cTypePoss = cvar.IntValue; |
| 90 | + else if(cvar == cvar_cTimeClean) cTimeClean = cvar.FloatValue; |
| 91 | + else if(cvar == cvar_cTimeHide) cTimeHide = cvar.FloatValue; |
| 92 | + else if(cvar == cvar_cEnable) cEnable = cvar.BoolValue; |
| 93 | + else if(cvar == cvar_cHudColor) SetHUDColor(cvar); |
| 94 | + else if(cvar == cvar_cHudPoss) SetHUDPosition(cvar); |
| 95 | +} |
| 96 | + |
| 97 | +public Action timerhealthOut(Handle timer) |
| 98 | +{ |
| 99 | + if(!cEnable) return; |
| 100 | + for(int client = 1; client <= MaxClients; client++) if(IsClientInGame(client) && g_bHUD[client]) |
| 101 | + { |
| 102 | + char textBuff[256]; |
| 103 | + int currHealth, health; |
| 104 | + |
| 105 | + health = GetEntProp(client, Prop_Send, "m_iHealth"); |
| 106 | + currHealth = health-iHealthNow[client]; |
| 107 | + |
| 108 | + if(iHealthNow[client] != health || health != 100 && currHealth != 0) |
| 109 | + { |
| 110 | + iTime[client] = cTimeClean; |
| 111 | + iTimer[client] = CreateTimer(0.1, TimerDamege_Clean, GetClientUserId(client), TIMER_REPEAT); |
| 112 | + |
| 113 | + if(health > iHealthNow[client]) Format(oldValue[client][0], sizeof(oldValue[][]), "+%i", currHealth); |
| 114 | + else Format(oldValue[client][0], sizeof(oldValue[][]), "%i", currHealth); |
| 115 | + |
| 116 | + switch(cTypePoss) |
| 117 | + { |
| 118 | + case 0: Procc_Left_Down(client, textBuff, sizeof(textBuff)); |
| 119 | + case 1: Procc_Right_Up(client, textBuff, sizeof(textBuff)); |
| 120 | + case 2: Procc_Right_Down(client, textBuff, sizeof(textBuff)); |
| 121 | + case 3: Procc_Left_Up(client, textBuff, sizeof(textBuff)); |
| 122 | + } |
| 123 | + |
| 124 | + for(int poss = cCount-1; poss > 0; poss--) |
| 125 | + oldValue[client][poss] = oldValue[client][poss-1]; |
| 126 | + |
| 127 | + SetHudTextParams(cHudPoss[0], cHudPoss[1], cTimeHide, cHudColor[0], cHudColor[1], cHudColor[2], cHudColor[3], 0, 0.0, 0.1, 0.1); |
| 128 | + ShowSyncHudText(client, iHud, textBuff); |
| 129 | + |
| 130 | + iHealthNow[client] = health; |
| 131 | + } |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +public Action TimerDamege_Clean(Handle timer, any client) |
| 136 | +{ |
| 137 | + client = GetClientOfUserId(client); |
| 138 | + |
| 139 | + if(!client || !IsClientInGame(client) || iTimer[client] != timer) |
| 140 | + return Plugin_Stop; |
| 141 | + |
| 142 | + if((iTime[client] -= 0.1) <= 0.0) |
| 143 | + { |
| 144 | + for(int poss = 0; poss < cCount; poss++) |
| 145 | + oldValue[client][poss][0] = '\0'; |
| 146 | + |
| 147 | + return Plugin_Stop; |
| 148 | + } |
| 149 | + |
| 150 | + return Plugin_Continue; |
| 151 | +} |
| 152 | + |
| 153 | +public void OnClientCookiesCached(int client) |
| 154 | +{ |
| 155 | + char szValue[4]; |
| 156 | + GetClientCookie(client, g_hCookie, szValue, sizeof(szValue)); |
| 157 | + if(!szValue[0]) g_bHUD[client] = true; |
| 158 | + else g_bHUD[client] = view_as<bool>(StringToInt(szValue)); |
| 159 | +} |
| 160 | + |
| 161 | +public void CreditsCookieHandler(int client, CookieMenuAction action, any info, char[] buffer, int maxlen) |
| 162 | +{ |
| 163 | + if(!cEnable) return; |
| 164 | + switch (action) |
| 165 | + { |
| 166 | + case CookieMenuAction_DisplayOption: |
| 167 | + { |
| 168 | + SetGlobalTransTarget(client); |
| 169 | + FormatEx(buffer, maxlen, "%t%t", g_bHUD[client] ? "Plus" : "Minus", "Health"); |
| 170 | + } |
| 171 | + case CookieMenuAction_SelectOption: |
| 172 | + { |
| 173 | + if(g_bHUD[client]) SetClientCookie(client, g_hCookie, "0"); |
| 174 | + else SetClientCookie(client, g_hCookie, "1"); |
| 175 | + |
| 176 | + g_bHUD[client] = !g_bHUD[client]; |
| 177 | + |
| 178 | + ShowCookieMenu(client); |
| 179 | + } |
| 180 | + } |
| 181 | +} |
| 182 | + |
| 183 | +stock void Procc_Right_Up(int client, char[] textBuff, int size = 256) |
| 184 | +{ |
| 185 | + for(int poss = cCount; poss > 0; poss--) |
| 186 | + { |
| 187 | + if(oldValue[client][poss-1][0]) |
| 188 | + Format(textBuff, size, "%s\n%s%s", textBuff, SPACE[cType][poss], oldValue[client][poss-1]); |
| 189 | + else |
| 190 | + Format(textBuff, size, "%s\n%s", textBuff, SPACE[cType][poss]); |
| 191 | + } |
| 192 | +} |
| 193 | + |
| 194 | +stock void Procc_Left_Down(int client, char[] textBuff, int size = 256) |
| 195 | +{ |
| 196 | + for(int poss = 0, poss2 = cCount; poss < cCount; poss++, poss2--) if(oldValue[client][poss][0]) |
| 197 | + { |
| 198 | + Format(textBuff, size, "%s\n%s%s", textBuff, SPACE[cType][poss2], oldValue[client][poss]); |
| 199 | + } |
| 200 | +} |
| 201 | +stock void Procc_Right_Down(int client, char[] textBuff, int size = 256) |
| 202 | +{ |
| 203 | + for(int poss = 0, poss2 = cCount; poss < cCount; poss++, poss2--) if(oldValue[client][poss][0]) |
| 204 | + { |
| 205 | + Format(textBuff, size, "%s\n%s%s", textBuff, SPACE[cType][poss], oldValue[client][poss]); |
| 206 | + } |
| 207 | +} |
| 208 | + |
| 209 | +stock void Procc_Left_Up(int client, char[] textBuff, int size = 256) |
| 210 | +{ |
| 211 | + for(int poss = 0, poss2 = cCount; poss < cCount; poss++, poss2--) |
| 212 | + { |
| 213 | + if(oldValue[client][poss2-1][0]) |
| 214 | + Format(textBuff, size, "%s\n%s%s", textBuff, SPACE[cType][poss], oldValue[client][poss2-1]); |
| 215 | + else |
| 216 | + Format(textBuff, size, "%s\n%s", textBuff, SPACE[cType][poss]); |
| 217 | + } |
| 218 | +} |
| 219 | + |
| 220 | +stock void SetHUDColor(ConVar cvar) |
| 221 | +{ |
| 222 | + char buffer[16], clr[4][4]; |
| 223 | + cvar.GetString(buffer, sizeof(buffer)); |
| 224 | + ExplodeString(buffer, " ", clr, 4, 4); |
| 225 | + for(int i; i <= 3; i++) cHudColor[i] = StringToInt(clr[i]); |
| 226 | +} |
| 227 | + |
| 228 | +stock void SetHUDPosition(ConVar cvar) |
| 229 | +{ |
| 230 | + char buffer[16], pos[2][8]; |
| 231 | + cvar.GetString(buffer, sizeof(buffer)); |
| 232 | + ExplodeString(buffer, " ", pos, 2, 8); |
| 233 | + cHudPoss[0] = StringToFloat(pos[0]); |
| 234 | + cHudPoss[1] = StringToFloat(pos[1]); |
| 235 | +} |
0 commit comments