diff --git a/discord_verificiation/scripting/unloze_player_time.sp b/discord_verificiation/scripting/unloze_player_time.sp index 30afdfd..3369edb 100644 --- a/discord_verificiation/scripting/unloze_player_time.sp +++ b/discord_verificiation/scripting/unloze_player_time.sp @@ -17,6 +17,7 @@ int g_iPlayerAFKTime; int g_iPlayerCount_excludeSpec; int g_iPlayerRTVCapacity; int g_iAvgHour_Contribution_per_player; +int g_iPlayerTier[MAXPLAYERS + 1]; static Handle g_hForwardPlayerHours; @@ -254,6 +255,7 @@ public void OnClientPostAdminCheck(int client) { GetClientAuthId(client, AuthId_Steam2, g_csSID[client], sizeof(g_csSID[])); is_bot_player[client] = false; + g_iPlayerTier[client] = 0; g_iPlayerTimeServer[client] = 0; if(!IsValidClient(client) || IsFakeClient(client)) return; @@ -338,10 +340,87 @@ public void SQL_OnQueryCompletedTimeServer(Database db, DBResultSet results, con Call_PushCell(g_iPlayerTimeServer[client]); Call_PushCell(iMinutes_Server); Call_Finish(); + + SetPlayerTier(client); + SetTierRewards(client); +} + +public void SetTierRewards(int client) +{ + if (g_iPlayerTier[client] < 1) + { + return; + } + for (int i = 1; i <= g_iPlayerTier[client]; i++) + { + char groupname[64]; + Format(groupname, sizeof(groupname), "tier%i", i); + AddClientToGroup(client, groupname); + } +} + +public void AddClientToGroup(int client, const char[] groupName) +{ + AdminId id = GetUserAdmin(client); + if (id == INVALID_ADMIN_ID) + { + id = CreateAdmin(); + SetUserAdmin(client, id, true); + } + + GroupId grp = FindAdmGroup(groupName); + if (grp == INVALID_GROUP_ID) + { + grp = CreateAdmGroup(groupName); + } + + AdminInheritGroup(id, grp); +} + +public void SetPlayerTier(int client) +{ + char sPath[PLATFORM_MAX_PATH]; + BuildPath(Path_SM, sPath, sizeof(sPath), "configs/unloze_playt_time_tiers.cfg"); + + KeyValues kv = new KeyValues("PlayTimeTiers"); + if (!kv.ImportFromFile(sPath)) + { + LogError("configs/unloze_playt_time_tiers not found"); + delete kv; + return; + } + + if (!kv.GotoFirstSubKey(false)) + { + LogError("configs/unloze_playt_time_tiers.cfg is empty or malformed"); + delete kv; + return; + } + + do + { + char sKey[16], sVal[16]; + kv.GetSectionName(sKey, sizeof(sKey)); + kv.GetString(NULL_STRING, sVal, sizeof(sVal), "-1"); + + int tier = StringToInt(sVal); + int hours = StringToInt(sKey); + if (hours > g_iPlayerTimeServer[client]) + { + break; + } + g_iPlayerTier[client] = tier; + + } while (kv.GotoNextKey(false)); + + PrintToChat(client, "Your Player Tier is %i", g_iPlayerTier[client]); + + delete kv; } public void OnClientDisconnect(int client) { + g_iPlayerTier[client] = 0; Format(g_csSID[client], sizeof(g_csSID[]), ""); is_bot_player[client] = false; g_iPlayerTimeServer[client] = 0;