Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Action:SM_Playtime(client, args)
- {
- if(!IsSpamming(client))
- {
- SetIsSpamming(client, 1.0);
- if(args == 0)
- {
- if(g_PlayerID[client] != 0)
- {
- DB_ShowPlaytime(client, g_PlayerID[client]);
- }
- }
- else
- {
- decl String:sArg[MAX_NAME_LENGTH];
- GetCmdArgString(sArg, sizeof(sArg));
- new target = FindTarget(client, sArg, true, false);
- if(target != -1)
- {
- if(g_PlayerID[target] != 0)
- {
- DB_ShowPlaytime(client, g_PlayerID[target]);
- }
- }
- }
- }
- return Plugin_Handled;
- }
- DB_ShowPlaytime(client, PlayerID)
- {
- new Handle:pack = CreateDataPack();
- WritePackCell(pack, GetClientUserId(client));
- WritePackCell(pack, PlayerID);
- decl String:query[512];
- Format(query, sizeof(query), "SELECT (SELECT Playtime FROM players WHERE PlayerID=%d) AS TargetPlaytime, User, Playtime, PlayerID FROM players ORDER BY Playtime DESC LIMIT 0, 100",
- PlayerID);
- SQL_TQuery(g_DB, DB_ShowPlaytime_Callback, query, pack);
- }
- public DB_ShowPlaytime_Callback(Handle:owner, Handle:hndl, String:error[], any:data)
- {
- if(hndl != INVALID_HANDLE)
- {
- ResetPack(data);
- new client = GetClientOfUserId(ReadPackCell(data));
- if(client != 0)
- {
- new rows = SQL_GetRowCount(hndl);
- if(rows != 0)
- {
- new TargetPlayerID = ReadPackCell(data);
- new Handle:menu = CreateMenu(Menu_ShowPlaytime);
- decl String:sName[MAX_NAME_LENGTH], String:sTime[32], String:sDisplay[64], String:sInfo[16], PlayTime, PlayerID, TargetPlaytime;
- for(new i = 1; i <= rows; i++)
- {
- SQL_FetchRow(hndl);
- TargetPlaytime = SQL_FetchInt(hndl, 0);
- SQL_FetchString(hndl, 1, sName, sizeof(sName));
- PlayTime = SQL_FetchInt(hndl, 2);
- PlayerID = SQL_FetchInt(hndl, 3);
- // Set info
- IntToString(PlayerID, sInfo, sizeof(sInfo));
- // Set display
- FormatPlayerTime(float(PlayTime), sTime, sizeof(sTime), false, 1);
- SplitString(sTime, ".", sTime, sizeof(sTime));
- FormatEx(sDisplay, sizeof(sDisplay), "#%d: %s: %s", i, sName, sTime);
- if((i % 7) == 0 || i == rows)
- {
- Format(sDisplay, sizeof(sDisplay), "%s\n--------------------------------------", sDisplay);
- }
- // Add item
- AddMenuItem(menu, sInfo, sDisplay);
- }
- GetNameFromPlayerID(TargetPlayerID, sName, sizeof(sName));
- new Float:ConnectionTime, target;
- if((target = GetClientFromPlayerID(TargetPlayerID)) != 0)
- {
- ConnectionTime = GetEngineTime() - g_fJoinTime[target];
- }
- FormatPlayerTime(ConnectionTime + float(TargetPlaytime), sTime, sizeof(sTime), false, 1);
- SplitString(sTime, ".", sTime, sizeof(sTime));
- SetMenuTitle(menu, "Playtimes\n \n%s: %s\n--------------------------------------",
- sName,
- sTime);
- SetMenuExitButton(menu, true);
- DisplayMenu(menu, client, MENU_TIME_FOREVER);
- }
- }
- }
- else
- {
- LogError(error);
- }
- CloseHandle(data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement