Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <commandfilters>
- #include <adt_trie>
- #include <files>
- #include <clientprefs>
- #pragma semicolon 1
- #define NEWBIE_FILE "newbiesfile.txt"
- float TimeOfConnect[32];
- float TimeOfDisconnect[32];
- float Playtime[32];
- bool noNewbiesTag = false;
- Handle g_hCookieNewbieTags = INVALID_HANDLE;
- Handle g_hCookieNewbieTime = INVALID_HANDLE;
- Handle g_hNewbieTags = INVALID_HANDLE;
- Handle g_hNewbieTime = INVALID_HANDLE;
- Handle g_hNewbies = INVALID_HANDLE;
- public OnPluginStart()
- {
- g_hNewbies = CreateTrie();
- g_hNewbieTags = CreateTrie();
- g_hNewbieTime = CreateTrie();
- g_hCookieNewbieTags = RegClientCookie("nametagnew", "Newbie name tag.", CookieAccess_Protected);
- g_hCookieNewbieTime = RegClientCookie("newbietime", "Newbie play time.", CookieAccess_Protected);
- CreateConVar("timeplayedint", "3600", "Playtime before newbie is disabled.");
- AddCommandListener(OnChat, "say");
- RegAdminCmd("sm_reloadnew", cmd_ReloadNewbies, ADMFLAG_SLAY);
- }
- public OnClientDisconnect(int client)
- {
- char PreviousPlaytimeBuffer[32];
- TimeOfDisconnect[client] = GetEngineTime();
- Playtime[client] = (TimeOfDisconnect[client] - TimeOfConnect[client]);
- GetClientCookie(client, g_hCookieNewbieTime, PreviousPlaytimeBuffer, sizeof(PreviousPlaytimeBuffer));
- float floatpp = StringToFloat(PreviousPlaytimeBuffer);
- SetClientCookie(client, g_hCookieNewbieTime, IntToString(RoundToFloor(Playtime[client] + floatpp)));
- }
- public OnClientConnected(int client)
- {
- TimeOfConnect[client] = GetEngineTime();
- }
- public OnClientPostAdminCheck(int client)
- {
- if (AreClientCookiesCached(client))
- {
- Handle g_hCvarNewbieTime = FindConVar("timeplayedint");
- char TagBuffer[32];
- char useSteamId[64];
- char PreviousPlaytimeBuffer[32];
- float previousplayertime[32];
- GetClientAuthId(client, useSteamId, sizeof(useSteamId));
- GetClientCookie(client, g_hCookieNewbieTags, TagBuffer, sizeof(TagBuffer));
- GetClientCookie(client, g_hCookieNewbieTime, PreviousPlaytimeBuffer, sizeof(PreviousPlaytimeBuffer));
- int intpp = StringToInt(PreviousPlaytimeBuffer);
- if (intpp < GetConVarInt(g_hCvarNewbieTime))
- {
- SetTrieString(g_hNewbieTags, useSteamId, TagBuffer, true);
- return Plugin_Continue;
- }
- if (intpp >= GetConVarInt(g_hCvarNewbieTime))
- {
- SetTrieString(g_hNewbieTags, useSteamId, "", true);
- noNewbiesTag = true;
- return Plugin_Continue;
- }
- }
- }
- public Action OnChat(client, const char command[], args)
- {
- if (noNewbiesTag = true)
- {
- return Plugin_Handled;
- }
- char useNameBuffer[MAXLENGTH_NAME]
- char useTagBuffer[32];
- char useSteamIdChat[64];
- GetClientAuthId(client, useSteamIdChat, sizeof(useSteamIdChat));
- GetTrieString(g_hNewbieTags, "tag", useTagBuffer, sizeof(useTagBuffer));
- GetClientName(client, useNameBuffer, sizeof(useNameBuffer));
- if (GetTrieString(client, "tag", useTagBuffer, sizeof(useTagBuffer)))
- {
- Format(useNameBuffer, sizeof(useNameBuffer), "%s%s", useTagBuffer, useNameBuffer);
- return Plugin_Continue;
- }
- }
- public Action NewbiesLoad()
- {
- char newFile[PLATFORM_MAX_PATH];
- BuildPath(Path_SM, newFile, sizeof(newFile), "config/newbies.cfg");
- Handle filehandle= OpenFile(newFile, "r");
- if (filehandle != INVALID_HANDLE)
- {
- newFile = "";
- ClearTrie(g_hNewbieTags);
- ClearTrie(g_hNewbies);
- while (!IsEndOfFile(filehandle) && ReadFileLine(file, newFile, sizeof(newFile)))
- {
- if (newFile[0] != ';' && strlen(newFile) > 1)
- {
- char bTemporary[2][64];
- TrimString(newFile);
- ExplodeString(newFile, ";", bTemporary, 2, sizeof(bTemporary[]));
- SetTrieValue(g_hNewbies, bTemporary[0], StringToInt(bTemporary[1]));
- SetTrieString(g_hNewbieTags, newFile, "");
- }
- }
- CloseHandle(filehandle);
- }
- else
- {
- SetFailState("Unable to load newbie file (%s)", NEWBIE_FILE);
- }
- }
- public Action cmd_ReloadNewbies(int client, int args)
- {
- NewbiesLoad();
- for (int i = 1; i <= MaxClients; i++)
- {
- if (IsClientInGame(i) && !IsFakeClient(i))
- {
- char useSteamIdReload[64];
- GetTrieString(g_hNewbies, "steamid", useSteamIdReload, sizeof(useSteamIdReload));
- if (GetTrieString(g_hNewbies, "steamid", useSteamIdReload, sizeof(useSteamIdReload))
- {
- ReplyToCommand(client, "You have reloaded newbies.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement