Alright this took a while for me to get and it's my first try with Key Values, but here you go:
PHP Code:
int iPoints;
char g_sPortPath[PLATFORM_MAX_PATH];
public void OnPluginStart()
{
SQL_TConnect(SQLCallback_Connect, "ckSurf");
BuildPath(Path_SM, g_sPortPath, sizeof(g_sPortPath), "configs/ports.cfg");
FindPort();
}
public void FindPort()
{
int iPort = GetConVarInt(FindConVar("hostport"));
Handle hPorts = CreateKeyValues("Ports");
if(!FileExists(g_sPortPath))
{
SetFailState("Configuration file %s not found!", g_sPortPath);
return;
}
if(!FileToKeyValues(hSettings, g_sPortPath))
{
SetFailState("Improper structure for configuration file %s!", g_sPortPath);
return;
}
if(KvGotoFirstSubKey(hSettings))
{
do
{
char Port[7];
KvGetString(hPorts, "port", Port, 7);
kv_iPort = StringToInt(Port);
if (iPort == kv_iPort)
{
char Points[32];
KvGetString(hPorts, "points", Points, 32);
iPoints = StringToInt(Points);
break;
}
} while(KvGotoNextKey(hSettings, false));
}
else
{
SetFailState("Can't find first subkey in configuration file %s!", g_sPortPath);
return;
}
CloseHandle(hPorts);
}
public void SQLCallback_LoadPlayerPoints(Handle owner, Handle hndl, const char[] error, any data)
{
if (hndl == null)
{
SetFailState("Error grabbing player points. %s", error);
}
int client = GetClientOfUserId(data);
if (SQL_GetRowCount(hndl) == 1)
{
SQL_FetchRow(hndl);
int playerpoints = SQL_FetchInt(hndl, 0);
if (playerpoints >= iPoints)
{
KickClient(client, "This server is for beginners.");
}
}
}
Just add or change all of that in your plugin and make a "ports.cfg" in your addons/sourcemod/configs folder that looks like:
Code:
"Setups"
{
"Server1"
{
"port" "111"
"points" "1000"
}
"Server2"
{
"port" "222"
"points" "1500"
}
}
You can add more lines into that for as many servers as you have. Just follow the hierarchy and keep the "Server#" different each time.
__________________