That script is going to provide an unnecessary amount of stress on a server.. Read your script in pseudo...
First function, no_weapons.
Start an infinite loop (while(1)), obtain all the players on the server and put them in an array.
Start a new loop, looping 'x' number of times (where x is player amount). Run a new thread on every player.
After 0.01 (actually 0.05) repeat this entire thread again...
---
Ok, now some quick maths.
0.05, 20th of a second. So, this thread will run 20 times a second.
If a server has 16 players on it, you will now have to run the "remove weapons" function 320 time a second.
A server goes on for 20 minutes (1200 seconds), is equal to 384000 times this function will run. And yet all it does is remove a players weapon...
You can save yourself a lot of hassle with some simple scripting.
First off, you want to get everyone currently on the server in an array. The simple method is using what Nightmare suggested, a trigger on the spawn area. The second way you can use avoided the unreal amounts of threads running is using a "onspawn" script.
Code: Select all
onPlayerSpawned()
{
for(;;)
{
self waittill("spawned_player");
//self newThread();
}
}
newThread()
{
self endon("disconnect");
self endon("killed_player");
self endon("joined_spectators");
while(self isAlive() && self.pers["team"] != "spectator")
{
while(!isDefined(self getCurrentWeapon()) || self getCurrentWeapon() != "none")
{
wait 3;
}
self takeallweapons();
}
}
This is the a CoD WaW script, it may be slightly different per game, consult the gametype files for the correct functions.
On a 16 person server, there are now a maximum of 33 loops.
The first loops runs ONCE per person joining the server. So although this is a loop, it is a paused loop.
The second loop is run on every person and is also a paused loops, and will loop ONCE every time a player is detected of having a weapon.
The third loop is run inside the 2nd loop and runs once every 3 seconds, checking if the player has a weapon in his hands, once a player is detected of having a gun, the loop ends, the player loses all weapons, and the loop restarts.
If a player goes into spectator, disconnects or dies, the 2nd and 3rd loops end.
If all 16 players are playing, then there are now a maximum 416 loops a match.