Code:
public Action:UpdateTimes(Handle:timer){
tracking = 0
new enabled = GetConVarInt(sm_ptt_enabled)
if (enabled == 1){
if (!rowExists){
return Plugin_Stop
}else{
new String:steamid[32], String:clientName[64]
for (new i = 1; i < MaxClients; i++){
if (IsClientInGame(i)){
new client = i
if (IsFakeClient(client)){
return Plugin_Continue
}
GetClientName(client, clientName, sizeof(clientName))
GetClientAuthString(client, steamid, sizeof(steamid))
Format(getTimeT, sizeof(getTimeT), "SELECT TimePlayed FROM TimeTracker WHERE steamid = '%s'", steamid)
SQL_TQuery(hDatabase, GetTheTime, getTimeT, client)
}
}
}
}
return Plugin_Continue;
}
public GetTheTime(Handle:owner, Handle:hQuery, const String:error[], any:client){
if (hQuery != INVALID_HANDLE){
if(SQL_GetRowCount(hQuery) > 0){
SQL_FetchRow(hQuery)
TotalTime = SQL_FetchInt(hQuery, 0)
new String:steamid[32]
GetClientAuthString(client, steamid, sizeof(steamid))
Format(getStoredT, sizeof(getStoredT), "SELECT StoredTime FROM TimeTracker WHERE steamid = '%s'", steamid)
SQL_TQuery(hDatabase, GetStored, getStoredT, client)
LogError("client is %L, TotalTime is %i", client, TotalTime)
LogError("Next query is %s", getStoredT)
}
}
CloseHandle(hQuery)
}
public GetStored(Handle:owner, Handle:hQuery, const String:error[], any:client){
if (hQuery != INVALID_HANDLE){
if(SQL_GetRowCount(hQuery) > 0){
SQL_FetchRow(hQuery)
TimeStored = SQL_FetchInt(hQuery, 0)
new String:steamid[32]
GetClientAuthString(client, steamid, sizeof(steamid))
Format(findActiveT, sizeof(findActiveT), "SELECT tracking FROM TimeTracker WHERE steamid = '%s'", steamid)
SQL_TQuery(hDatabase, FindActive, findActiveT, client)
LogError("client is %L, TimeStored is %i", client, TimeStored)
LogError("Next query is %s", findActiveT)
}
}
CloseHandle(hQuery)
}
public FindActive(Handle:owner, Handle:hQuery, const String:error[], any:client){
if (hQuery != INVALID_HANDLE){
if(SQL_GetRowCount(hQuery) > 0){
SQL_FetchRow(hQuery)
tracking = SQL_FetchInt(hQuery, 0)
}
if (tracking == 1){
new String:query[128], String:steamid[32]
GetClientAuthString(client, steamid, sizeof(steamid))
TimePlayed = GetClientTime(client)
new iTimePlayed = RoundToFloor(TimePlayed)
TotalTime = TotalTime+iTimePlayed-TimeStored
Format(query, sizeof(query), "UPDATE TimeTracker SET TimePlayed='%i', StoredTime='%i' WHERE steamid ='%s'", TotalTime, iTimePlayed, steamid);
SQL_TQuery(hDatabase, updateTime, query)
LogError("client is %L, tracking is %i", client, tracking)
}
}
CloseHandle(hQuery)
}
public updateTime(Handle:owner, Handle:hQuery, const String:error[], any:client){
if (hQuery != INVALID_HANDLE){
}
CloseHandle(hQuery)
}
public DBConnect(Handle:owner, Handle:hndl, const String:error[], any:data){
if (hndl == INVALID_HANDLE){
LogError("Error! %s", error)
return
}
hDatabase = hndl
}
It works fine when there's only one client, but as soon as there's multiple, the variables start intermixing. What should I do?