pawn Код:
#define MAX_FILTERSCRIPTS 16
#define MAX_FILTERSCRIPT_NAME 30
new gFilterscripts[MAX_FILTERSCRIPTS][MAX_FILTERSCRIPT_NAME];
public OnGameModeInit()
{
dcmd_loadfs(INVALID_PLAYER_ID, "derby");
dcmd_loadfs(INVALID_PLAYER_ID, "racing");
}
public OnGameModeExit()
{
new rcon[50];
for(new x=0; x < MAX_FILTERSCRIPTS; x++)
{
if(!strlen(gFilterscripts[x])) continue;
format(rcon, sizeof(rcon), "unloadfs %s", gFilterscripts[x]);
SendRconCommand(rcon);
}
}
public OnRconCommand(cmd[])
{
new playerid = INVALID_PLAYER_ID;
dcmd(reloadfs, 8, cmd);
dcmd(loadfs, 6, cmd);
dcmd(unloadfs, 8, cmd);
return 0;
}
dcmd_loadfs(playerid, params[])
{
if(playerid != INVALID_PLAYER_ID) return 0;
new x = ExistingFS(params);
if(x != -1)
{
dcmd_reloadfs(playerid, params);
return 1;
}
// Check if we haven't loaded the maximum already
for(x=0; x <= MAX_FILTERSCRIPTS; x++)
{
if(x == MAX_FILTERSCRIPTS) break;
if(!strlen(gFilterscripts[x])) break;
}
// Too many loaded!!
if(x == MAX_FILTERSCRIPTS)
{
print("Loaded too many filterscripts!!");
return 1;
}
// Load the script and put it into the array
new rcon[50];
format(rcon, sizeof(rcon), "loadfs %s", params);
format(gFilterscripts[x], MAX_FILTERSCRIPT_NAME, "%s", params);
SendRconCommand(rcon);
printf("/loadfs %s", params);
return 1;
}
dcmd_unloadfs(playerid, params[])
{
if(playerid != INVALID_PLAYER_ID) return 0;
new x = ExistingFS(params);
if(x == -1)
{
printf("Cannot unloadfs %s, it doesn't exist!", params);
return 1;
}
// Unload the script and empty the array
new rcon[50];
format(rcon, sizeof(rcon), "unloadfs %s", params);
gFilterscripts[x] = "";
SendRconCommand(rcon);
printf("/unloadfs %s", params);
return 1;
}
dcmd_reloadfs(playerid, params[])
{
if(playerid != INVALID_PLAYER_ID) return 0;
if(ExistingFS(params) == -1)
{
dcmd_loadfs(playerid, params);
return 1;
}
// Reload the script
new rcon[50];
format(rcon, sizeof(rcon), "reloadfs %s", params);
SendRconCommand(rcon);
printf("/reloadfs %s", params);
return 1;
}
stock ExistingFS(params[])
{
new x=0;
// Check if it already exists and reload it if so
for(x=0; x <= MAX_FILTERSCRIPTS; x++)
{
if(x == MAX_FILTERSCRIPTS) break;
if(!strlen(gFilterscripts[x])) continue;
if(!strcmp(params, gFilterscripts[x])) break;
}
// return x if it exists, return 0 if it does not
if(x == MAX_FILTERSCRIPTS) return -1;
else return x;
}
Seems to work just fine. Thanks for the idea Y_Less.
/rcon /loadfs derby
/rcon /reloadfs derby
/rcon /unloadfs derby
The loadfs command will kick you to reloadfs if the same name exists in the array, and the reloadfs command will kick you to loadfs if it doesn't exist already.
Can't load your filterscripts in the server.cfg file though if you do it this way.