#include <amxmodx>
#include <reapi>
enum _:DATA { Float:KILLS, DEATH };
new g_szTempData[MAX_CLIENTS + 1][DATA];
new g_szAuthID[MAX_CLIENTS + 1][32];
new Trie:g_tPlayerScore;
new HookChain:hRestartRoundPost;
public plugin_end() {
TrieDestroy(g_tPlayerScore);
}
public plugin_init() {
register_plugin("Save score", "1.1.0", "Minni Mouse");
RegisterHookChain(RG_RoundEnd, "refwd_RoundEnd_Post", .post = true);
DisableHookChain((hRestartRoundPost =
RegisterHookChain(RG_CSGameRules_RestartRound, "refwd_RestartRound_Post", .post = true))
);
g_tPlayerScore = TrieCreate();
}
public client_disconnected(pPlayer) {
if(is_user_hltv(pPlayer) || is_user_bot(pPlayer)) {
return;
}
func_GetData(pPlayer);
}
public client_putinserver(pPlayer) {
if(is_user_hltv(pPlayer) || is_user_bot(pPlayer)) {
return;
}
get_user_authid(pPlayer, g_szAuthID[pPlayer], charsmax(g_szAuthID[]));
func_SetData(pPlayer);
}
public refwd_RestartRound_Post() {
DisableHookChain(hRestartRoundPost);
new iPlayers[MAX_CLIENTS], iNum;
get_players(iPlayers, iNum, "ch");
for(new i = 0; i < iNum; i++) {
func_SetData(iPlayers[i]);
}
}
public refwd_RoundEnd_Post(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay) {
if(event == ROUND_GAME_COMMENCE || event == ROUND_GAME_RESTART) {
EnableHookChain(hRestartRoundPost);
}
}
func_GetData(pPlayer) {
if(g_szAuthID[pPlayer][0]) {
g_szTempData[pPlayer][KILLS] = Float:get_entvar(pPlayer, var_frags);
g_szTempData[pPlayer][DEATH] = get_member(pPlayer, m_iDeaths);
TrieSetArray(g_tPlayerScore, g_szAuthID[pPlayer], g_szTempData[pPlayer], DATA);
}
}
func_SetData(pPlayer) {
if(TrieGetArray(g_tPlayerScore, g_szAuthID[pPlayer], g_szTempData[pPlayer], DATA)) {
set_entvar(pPlayer, var_frags, g_szTempData[pPlayer][KILLS]);
set_member(pPlayer, m_iDeaths, g_szTempData[pPlayer][DEATH]);
}
else {
arrayset(_:g_szTempData[pPlayer], _:0.0, sizeof(g_szTempData[]));
}
}