It goes like that:
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#pragma newdecls required
KeyValues g_kvRequests;
public void OnPluginStart()
{
RegConsoleCmd("sm_request", Command_Request);
RegConsoleCmd("sm_showrequests", Command_ShowRequests);
}
public void OnMapStart()
{
g_kvRequests = new KeyValues("Requests");
}
public void OnMapEnd()
{
delete g_kvRequests;
}
public Action Command_Request( int client, int args )
{
char szName[32];
GetClientName(client, szName, sizeof(szName) - 1);
char szAuth[32];
GetClientAuthId(client, AuthId_Steam3, szAuth, sizeof(szAuth) - 1);
char szArg[15];
GetCmdArg(1, szArg, sizeof(szArg));
if( g_kvRequests.JumpToKey(szAuth) ) PrintToChat(client, "Your old request has been replaced!");
else
{
g_kvRequests.JumpToKey(szAuth, true);
//g_iTotalRequests++;
}
g_kvRequests.SetString("text", szArg);
g_kvRequests.SetString("name", szName );
g_kvRequests.SetString("auth", szAuth );
g_kvRequests.Rewind();
return Plugin_Handled;
}
public Action Command_ShowRequests( int client, int args )
{
if (!g_kvRequests.GotoFirstSubKey())
{
return Plugin_Handled;
}
char szAuth[32], szName[32], szArg[15];
do
{
g_kvRequests.GetSectionName(szAuth, sizeof(szAuth));
g_kvRequests.GetString("name", szName, sizeof(szName));
g_kvRequests.GetString("text", szArg, sizeof(szArg));
PrintToConsole(client, "%s - %s - %s", szAuth, szName, szArg);
} while (g_kvRequests.GotoNextKey());
g_kvRequests.Rewind();
return Plugin_Handled;
}
/request - adds a request
/showrequests - shows all requests
Lets assume 2 players are typing /showrequests at the exact same time, and there are 30 keys in the keyvalue.
The function "g_kvRequests.GotoNextKey()" will work good?
What if the first player's loop is at different key from the second player's loop? Won't it scramble together?
And if this is not an effective way to code what i want to do, there's something else i can use but not keyvalues? A way that i can store 3 vars for each player on the server?
Thanks!