#pragma newdecls required #include #include #define MaxTokens 9 /* BOOLEANS */ bool g_bHasToken[MAXPLAYERS+1][MaxTokens]; bool g_bPostFilter[MAXPLAYERS+1]; //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public Plugin myinfo = { name = "TokenGroups", author = "zaCade", description = "Grant sourcemod groups", version = "1.0" }; //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int errorSize) { CreateNative("CheckTokens", Native_CheckTokens); CreateNative("GrantTokens", Native_GrantTokens); RegPluginLibrary("TokenGroups"); return APLRes_Success; } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public void OnRebuildAdminCache(AdminCachePart part) { if (part == AdminCache_Overrides) return; if (part == AdminCache_Groups) { CreateAdminGroup("Token-1"); CreateAdminGroup("Token-1-VIP"); CreateAdminGroup("Token-2"); CreateAdminGroup("Token-2-VIP"); CreateAdminGroup("Token-3"); CreateAdminGroup("Token-3-VIP"); CreateAdminGroup("Token-4"); CreateAdminGroup("Token-4-VIP"); CreateAdminGroup("Token-5"); CreateAdminGroup("Token-5-VIP"); CreateAdminGroup("Token-6"); CreateAdminGroup("Token-6-VIP"); CreateAdminGroup("Token-7"); CreateAdminGroup("Token-7-VIP"); CreateAdminGroup("Token-8"); CreateAdminGroup("Token-8-VIP"); CreateAdminGroup("Token-9"); CreateAdminGroup("Token-9-VIP"); } CreateTimer(1.0, OnRebuildAdminCachePost, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE); } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public Action OnRebuildAdminCachePost(Handle hTimer) { for (int client = 1; client <= MaxClients; client++) CheckClientTokens(client); } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public void OnClientConnected(int client) { ResetClient(client); } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public void OnClientDisconnect(int client) { ResetClient(client); } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public void OnClientPostAdminFilter(int client) { g_bPostFilter[client] = true; CheckClientTokens(client); } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- stock void ResetClient(int client) { for (int token = 0; token < MaxTokens; token++) g_bHasToken[client][token] = false; g_bPostFilter[client] = false; } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- stock void CheckClientTokens(int client) { if (!g_bPostFilter[client]) return; if (CheckCommandAccess(client, "sm_tokens_vip", ADMFLAG_CUSTOM1)) { if (g_bHasToken[client][0]) ApplyAdminGroup(client, "Token-1-VIP"); if (g_bHasToken[client][1]) ApplyAdminGroup(client, "Token-2-VIP"); if (g_bHasToken[client][2]) ApplyAdminGroup(client, "Token-3-VIP"); if (g_bHasToken[client][3]) ApplyAdminGroup(client, "Token-4-VIP"); if (g_bHasToken[client][4]) ApplyAdminGroup(client, "Token-5-VIP"); if (g_bHasToken[client][5]) ApplyAdminGroup(client, "Token-6-VIP"); if (g_bHasToken[client][6]) ApplyAdminGroup(client, "Token-7-VIP"); if (g_bHasToken[client][7]) ApplyAdminGroup(client, "Token-8-VIP"); if (g_bHasToken[client][8]) ApplyAdminGroup(client, "Token-9-VIP"); } else { if (g_bHasToken[client][0]) ApplyAdminGroup(client, "Token-1"); if (g_bHasToken[client][1]) ApplyAdminGroup(client, "Token-2"); if (g_bHasToken[client][2]) ApplyAdminGroup(client, "Token-3"); if (g_bHasToken[client][3]) ApplyAdminGroup(client, "Token-4"); if (g_bHasToken[client][4]) ApplyAdminGroup(client, "Token-5"); if (g_bHasToken[client][5]) ApplyAdminGroup(client, "Token-6"); if (g_bHasToken[client][6]) ApplyAdminGroup(client, "Token-7"); if (g_bHasToken[client][7]) ApplyAdminGroup(client, "Token-8"); if (g_bHasToken[client][8]) ApplyAdminGroup(client, "Token-9"); } } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- stock void CreateAdminGroup(const char[] group) { GroupId GrpID; if ((GrpID = FindAdmGroup(group)) == INVALID_GROUP_ID) { LogMessage("Creating new admin group %s", group); GrpID = CreateAdmGroup(group); GrpID.ImmunityLevel = 0; } } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- stock void ApplyAdminGroup(int client, const char[] group) { AdminId AdmID; GroupId GrpID; if ((AdmID = GetUserAdmin(client)) == INVALID_ADMIN_ID) { LogMessage("Creating new admin for %L", client); AdmID = CreateAdmin(); SetUserAdmin(client, AdmID, true); } if ((GrpID = FindAdmGroup(group)) != INVALID_GROUP_ID) { if (AdminInheritGroup(AdmID, GrpID)) { LogMessage("%L added to group %s", client, group); } } else { LogMessage("%L group not found %s", client, group); } } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public int Native_CheckTokens(Handle hPlugin, int numParams) { int client = GetNativeCell(1); if (client < 1 || client > MaxClients) { ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index. (%d)", client); return; } if (!IsClientConnected(client)) { ThrowNativeError(SP_ERROR_NATIVE, "Client (%d) is not connected.", client); return; } CheckClientTokens(client); } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public int Native_GrantTokens(Handle hPlugin, int numParams) { int client = GetNativeCell(1); int token = GetNativeCell(2); if (client < 1 || client > MaxClients) { ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index. (%d)", client); return; } if (token < 1 || token > MaxTokens) { ThrowNativeError(SP_ERROR_NATIVE, "Invalid token index. (%d)", token); return; } if (!IsClientConnected(client)) { ThrowNativeError(SP_ERROR_NATIVE, "Client (%d) is not connected.", client); return; } g_bHasToken[client][token -= 1] = true; CheckClientTokens(client); }