load random fs - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: load random fs (
/showthread.php?tid=519979)
load random fs -
Onfroi - 16.06.2014
Just a simple question, how would I load a random FS from the folder filterscripts?
Thanks in advance.
Re: load random fs -
VladimirMark - 16.06.2014
Add the filterscript's name that you want to use from the "filterscripts" folder to the filterscripts line in the server.cfg file

Or use the RCON Admin command /rcon loadfs - to load filterscript manually
Re: load random fs -
Onfroi - 16.06.2014
Quote:
Originally Posted by VladimirMark
Add the filterscript's name that you want to use from the "filterscripts" folder to the filterscripts line in the server.cfg file  Or use the RCON Admin command /rcon loadfs - to load filterscript manually
|
No man, I mean like a function in the script, LoadNewFS(); and it loads a new FS everytime its used.
Re: load random fs -
Jefff - 16.06.2014
pawn Код:
static const ScriptNames[][] =
{
"script_name_1",
"script_name_2",
"script_name_3",
"script_name_4"
// more ...
};
static bool:Loaded[(sizeof(ScriptNames)) char];
LoadNewFS()
{
static ScriptsLoaded;
if(ScriptsLoaded >= sizeof(ScriptNames))
{
print("Warning: All scripts loaded!");
return -1;
}
new p, rand;
while(!p)
{
rand = random(sizeof(ScriptNames));
if(!Loaded{rand})
{
Loaded{rand} = true;
ScriptsLoaded++;
p = 1;
}
}
new cmd[45];
format(cmd,sizeof(cmd),"loadfs %s",ScriptNames[rand]);
SendRconCommand(cmd);
return rand;
}
Re: load random fs -
Onfroi - 16.06.2014
Quote:
Originally Posted by Jefff
pawn Код:
static const ScriptNames[][] = { "script_name_1", "script_name_2", "script_name_3", "script_name_4" // more ... }; static bool:Loaded[(sizeof(ScriptNames)) char];
LoadNewFS() { static ScriptsLoaded; if(ScriptsLoaded >= sizeof(ScriptNames)) { print("Warning: All scripts loaded!"); return -1; }
new p, rand; while(!p) { rand = random(sizeof(ScriptNames)); if(!Loaded{rand}) { Loaded{rand} = true; ScriptsLoaded++; p = 1; } }
new cmd[45]; format(cmd,sizeof(cmd),"loadfs %s",ScriptNames[rand]); SendRconCommand(cmd); return rand; }
|
Thanks man

, but lets say I want to unload the current fs loaded before loading a new one, will this work?
pawn Код:
stock LoadNewFS()
{
new p, rand;
while(!p)
{
rand = random(sizeof(ScriptNames));
if(!Loaded{rand})
{
Loaded{rand} = true;
p = 1;
}
else if(Loaded{rand})
{
new cmd[45];
format(cmd,sizeof(cmd),"unloadfs %s",ScriptNames[rand]);
SendRconCommand(cmd);
}
}
new cmd[45];
format(cmd,sizeof(cmd),"loadfs %s",ScriptNames[rand]);
SendRconCommand(cmd);
return rand;
}
Re: load random fs -
Jefff - 16.06.2014
No

this should work
pawn Код:
LoadNewFS()
{
static ScriptsLoaded;
if(ScriptsLoaded >= sizeof(ScriptNames))
{
print("Warning: All scripts loaded!");
return -1;
}
new cmd[45], script = -1;
if(ScriptsLoaded)
{
for(new i=0; i != sizeof(ScriptNames); i++)
if(Loaded{i})
{
script = i;
ScriptsLoaded--;
Loaded{i} = false;
format(cmd,sizeof(cmd),"unloadfs %s",ScriptNames[i]);
SendRconCommand(cmd);
break;
}
}
new p, rand;
while(!p)
{
rand = random(sizeof(ScriptNames));
if(!Loaded{rand} && script != rand)
{
Loaded{rand} = true;
ScriptsLoaded++;
p = 1;
}
}
format(cmd,sizeof(cmd),"loadfs %s",ScriptNames[rand]);
SendRconCommand(cmd);
return rand;
}