Skip to content

Commit

Permalink
add stats, ownage, bestround
Browse files Browse the repository at this point in the history
  • Loading branch information
WessTorn committed Oct 24, 2023
1 parent b758996 commit cdb1d02
Show file tree
Hide file tree
Showing 7 changed files with 482 additions and 4 deletions.
10 changes: 10 additions & 0 deletions data/lang/hidenseek.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ KNIFE_HIDE = Hide knife
KNIFE_CT = Hide for \yCT \r%s
KNIFE_TT = Hide for \yTT \r%s

ROUNDINFO_ON = [^3%s^1] Round info is now ^3enabled.
ROUNDINFO_OFF = [^3%s^1] Round info is now ^3disabled.

HNS_OWNAGE = %n owned %n's head!

HNS_YES = Yes
HNS_NO = No

Expand All @@ -43,5 +48,10 @@ KNIFE_HIDE = Спрятать нож
KNIFE_CT = Спрятать у \yКТ \r%s
KNIFE_TT = Спрятать у \yТТ \r%s

ROUNDINFO_ON = [^3%s^1] Информация о раунде ^3включена.
ROUNDINFO_OFF = [^3%s^1] Информация о раунде ^3выключена.

HNS_OWNAGE = %n запрыгнул на голову %n!

HNS_YES = Да
HNS_NO = Нет
13 changes: 10 additions & 3 deletions hns_main.sma
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ new const g_szDefaultEntities[][] = {
}

enum _: Forwards_s {
hns_team_swap
hns_round_start,
hns_team_swap,
hns_round_end
};

new g_hForwards[Forwards_s];
Expand Down Expand Up @@ -82,7 +84,9 @@ public plugin_init() {

set_task(0.5, "delayed_mode");

g_hForwards[hns_round_start] = CreateMultiForward("hns_round_start", ET_CONTINUE);
g_hForwards[hns_team_swap] = CreateMultiForward("hns_team_swap", ET_CONTINUE);
g_hForwards[hns_round_end] = CreateMultiForward("hns_round_end", ET_CONTINUE);

register_dictionary("hidenseek.txt");
}
Expand Down Expand Up @@ -150,6 +154,7 @@ public rgFreezeEnd() {

public rgRoundStart() {
set_task(1.0, "taskDestroyBreakables");
ExecuteForward(g_hForwards[hns_round_start]);
}

public rgPlayerResetMaxSpeed(id) {
Expand All @@ -171,8 +176,8 @@ public rgPlayerSpawn(id) {

public checkBalanceTeams() {
new iPlayers[MAX_PLAYERS], iCTNum, iTTNum
get_players(iPlayers, iCTNum, "he", "CT");
get_players(iPlayers, iTTNum, "he", "TERRORIST");
get_players(iPlayers, iCTNum, "che", "CT");
get_players(iPlayers, iTTNum, "che", "TERRORIST");

if (abs(iCTNum - iTTNum) < 2)
return PLUGIN_HANDLED;
Expand Down Expand Up @@ -294,6 +299,8 @@ public rgRoundEnd(WinStatus: status, ScenarioEventEndRound: event, Float:tmDelay
}
}

ExecuteForward(g_hForwards[hns_round_end]);

return HC_CONTINUE;
}

Expand Down
47 changes: 47 additions & 0 deletions hns_ownage.sma
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <amxmodx>
#include <engine>
#include <reapi>

#define rg_get_user_team(%0) get_member(%0, m_iTeam)

new Float:g_pCvarDelay;

new Float:g_flLastHeadTouch[MAX_PLAYERS + 1];

new g_hForwardOwnage;

new const g_szSound[][] = {
"openhns/mario.wav",
"openhns/ownage.wav"
};

public plugin_init() {
register_plugin("HNS Ownage", "1.0", "OpenHNS");

bind_pcvar_float(register_cvar("hns_ownage_delay", "5.0"), g_pCvarDelay);

register_touch("player", "player", "iTouchPlayer");

g_hForwardOwnage = CreateMultiForward("hns_ownage", ET_CONTINUE, FP_CELL, FP_CELL);
}

public plugin_precache() {
for(new i; i < sizeof(g_szSound); i++)
precache_sound(g_szSound[i]);
}

public iTouchPlayer(iToucher, iTouched) {
if(entity_get_int(iToucher, EV_INT_flags) & FL_ONGROUND && entity_get_edict(iToucher, EV_ENT_groundentity) == iTouched && rg_get_user_team(iToucher) == TEAM_TERRORIST && rg_get_user_team(iTouched) == TEAM_CT) {
new Float:flGametime = get_gametime();

if(flGametime > (g_flLastHeadTouch[iToucher] + g_pCvarDelay)) {
set_dhudmessage(250, 255, 0, -1.0, 0.2, .holdtime = 4.0);
show_dhudmessage(0, "%L", LANG_PLAYER, "HNS_OWNAGE", iToucher, iTouched);

g_flLastHeadTouch[iToucher] = flGametime;
rg_send_audio(0, g_szSound[random(sizeof(g_szSound))]);

ExecuteForward(g_hForwardOwnage, _, iToucher, iTouched);
}
}
}
183 changes: 183 additions & 0 deletions hns_showbest.sma
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
#include <amxmodx>

#include <hns_mode_main>
#include <hns_mode_stats>

#define rg_get_user_team(%0) get_member(%0, m_iTeam)

#define TASK_SHOWSTATS 1328

new g_szPrefix[24];

enum _: PLAYER_STATS {
PLR_STATS_KILLS,
PLR_STATS_DEATHS,
PLR_STATS_ASSISTS,
PLR_STATS_STABS,
PLR_STATS_DMG_CT,
PLR_STATS_DMG_TT,
Float:PLR_STATS_RUNNED,
Float:PLR_STATS_FLASHTIME,
Float:PLR_STATS_SURVTIME,
PLR_STATS_OWNAGES,
}

new g_StatsRound[MAX_PLAYERS + 1][PLAYER_STATS];

new bool:g_bRoundInfo[MAX_PLAYERS + 1];

new g_eBestIndex[PLAYER_STATS];
new g_eBestStats[PLAYER_STATS];

new g_szMess[2048];

new g_iSecShow;

new g_HudSync;

public plugin_init() {
register_plugin("HNS Show round best players", "1.0", "OpenHNS");

register_clcmd("say /roundinfo", "cmdRoundInfo");
register_clcmd("say_team /roundinfo", "cmdRoundInfo");

g_HudSync = CreateHudSyncObj();
}

public client_putinserver(id) {
g_bRoundInfo[id] = true;
}

public plugin_cfg() {
hns_get_prefix(g_szPrefix, charsmax(g_szPrefix));
}

public cmdRoundInfo(id) {
g_bRoundInfo[id] = !g_bRoundInfo[id];

if (g_bRoundInfo[id])
client_print_color(id, print_team_blue, "%L", id, "ROUNDINFO_ON", g_szPrefix);
else
client_print_color(id, print_team_blue, "%L", id, "ROUNDINFO_OFF", g_szPrefix);

return PLUGIN_HANDLED;
}

public hns_round_end() {
new iPlayers[MAX_PLAYERS], iCTNum, iTTNum
get_players(iPlayers, iCTNum, "che", "CT");
get_players(iPlayers, iTTNum, "che", "TERRORIST");

if (iCTNum + iTTNum > 1) {
set_best_stats();

set_best_mess();

g_iSecShow = 10;
set_task(1.0, "taskShowStats", TASK_SHOWSTATS, .flags = "b");
}
}

public set_best_stats() {
new iPlayers[MAX_PLAYERS], iNum;
get_players(iPlayers, iNum, "ch");

for (new i = 0; i < iNum; i++) {
new id = iPlayers[i];

get_player_stats(id);

for (new j = 0; j < PLAYER_STATS; j++) {
if (g_StatsRound[id][j] > g_eBestStats[j])
{
g_eBestStats[j] = g_StatsRound[id][j];
g_eBestIndex[j] = id;
}
}
}
}

public get_player_stats(id) {
g_StatsRound[id][PLR_STATS_KILLS] = hns_get_stats_kills(id);
g_StatsRound[id][PLR_STATS_DEATHS] = hns_get_stats_deaths(id);
g_StatsRound[id][PLR_STATS_ASSISTS] = hns_get_stats_assists(id);
g_StatsRound[id][PLR_STATS_STABS] = hns_get_stats_stabs(id);
g_StatsRound[id][PLR_STATS_DMG_CT] = hns_get_stats_dmgct(id);
g_StatsRound[id][PLR_STATS_DMG_TT] = hns_get_stats_dmgtt(id);
g_StatsRound[id][PLR_STATS_RUNNED] = hns_get_stats_run(id);
g_StatsRound[id][PLR_STATS_FLASHTIME] = hns_get_stats_flashtime(id);
g_StatsRound[id][PLR_STATS_SURVTIME] = hns_get_stats_surv(id);
g_StatsRound[id][PLR_STATS_OWNAGES] = hns_get_stats_ownages(id);
}

public set_best_mess() {
new iLen = format(g_szMess, sizeof g_szMess - 1, "Best players of the round:^n^n");

new sTime[24];
fnConvertTime(g_eBestStats[PLR_STATS_SURVTIME], sTime, charsmax(sTime));

if (g_eBestIndex[PLR_STATS_SURVTIME]) iLen += format(g_szMess[iLen], sizeof g_szMess - iLen, "Survived: %n - %s^n", g_eBestIndex[PLR_STATS_SURVTIME], sTime)
if (g_eBestIndex[PLR_STATS_OWNAGES]) iLen += format(g_szMess[iLen], sizeof g_szMess - iLen, "Ownages: %n - %d^n", g_eBestIndex[PLR_STATS_OWNAGES], g_eBestStats[PLR_STATS_OWNAGES])
if (g_eBestIndex[PLR_STATS_KILLS]) iLen += format(g_szMess[iLen], sizeof g_szMess - iLen, "Killed: %n - %d^n", g_eBestIndex[PLR_STATS_KILLS], g_eBestStats[PLR_STATS_KILLS])
if (g_eBestIndex[PLR_STATS_ASSISTS]) iLen += format(g_szMess[iLen], sizeof g_szMess - iLen, "Assists: %n - %d^n", g_eBestIndex[PLR_STATS_ASSISTS], g_eBestStats[PLR_STATS_ASSISTS])
if (g_eBestIndex[PLR_STATS_STABS]) iLen += format(g_szMess[iLen], sizeof g_szMess - iLen, "Stabs: %n - %d^n", g_eBestIndex[PLR_STATS_STABS], g_eBestStats[PLR_STATS_STABS])
if (g_eBestIndex[PLR_STATS_DMG_CT]) iLen += format(g_szMess[iLen], sizeof g_szMess - iLen, "CT Dmg: %n - %d^n", g_eBestIndex[PLR_STATS_DMG_CT], g_eBestStats[PLR_STATS_DMG_CT])
if (g_eBestIndex[PLR_STATS_DMG_TT]) iLen += format(g_szMess[iLen], sizeof g_szMess - iLen, "TT Dmg: %n - %d^n", g_eBestIndex[PLR_STATS_DMG_TT], g_eBestStats[PLR_STATS_DMG_TT])
if (g_eBestIndex[PLR_STATS_RUNNED]) iLen += format(g_szMess[iLen], sizeof g_szMess - iLen, "Runned: %n - %.2f^n", g_eBestIndex[PLR_STATS_RUNNED], g_eBestStats[PLR_STATS_RUNNED])
if (g_eBestIndex[PLR_STATS_FLASHTIME]) iLen += format(g_szMess[iLen], sizeof g_szMess - iLen, "Flashed: %n - %.2f^n", g_eBestIndex[PLR_STATS_FLASHTIME], g_eBestStats[PLR_STATS_FLASHTIME])
}

public fnConvertTime(Float:time, convert_time[], len) {
new sTemp[24];
new Float:fSeconds = time, iMinutes;

iMinutes = floatround(fSeconds / 60.0, floatround_floor);
fSeconds -= iMinutes * 60.0;
new intpart = floatround(fSeconds, floatround_floor);
new Float:decpart = (fSeconds - intpart) * 100.0;
intpart = floatround(decpart);

formatex(sTemp, charsmax(sTemp), "%02i:%02.0f.%d", iMinutes, fSeconds, intpart);

formatex(convert_time, len, sTemp);

return (PLUGIN_HANDLED);
}


public taskShowStats(id) {
if (g_iSecShow) {
g_iSecShow--;
} else {
remove_task(TASK_SHOWSTATS);
}

new iPlayers[MAX_PLAYERS], iNum;
get_players(iPlayers, iNum, "ch");

for (new i = 0; i < iNum; i++) {
new id = iPlayers[i];

if (!is_user_connected(id) || !g_bRoundInfo[id]) {
continue;
}

set_hudmessage(.red = 100, .green = 100, .blue = 100, .x = 0.1, .y = -1.0, .fxtime = 0.0, .holdtime = 1.0);
ShowSyncHudMsg(id, g_HudSync, g_szMess);
}
}

public hns_round_start() {
new iPlayers[MAX_PLAYERS], iNum;
get_players(iPlayers, iNum, "ch");

for (new i = 0; i < iNum; i++) {
new id = iPlayers[i];
arrayset(g_StatsRound[id], 0, PLAYER_STATS);

}

arrayset(g_eBestIndex, 0, PLAYER_STATS);
arrayset(g_eBestStats, 0, PLAYER_STATS);
g_szMess[0] = 0;
}
Loading

0 comments on commit cdb1d02

Please sign in to comment.