Page 1 of 2

Script command for not doing anything

Posted: January 16th, 2009, 4:39 pm
by Rezil
Um just a quick question:

What's the script command for the script not to do anything. For example, i have the following script(example code, not actually implemeted):

Code: Select all


main()

{

level.int = 0;

thread move();

}

move()

{

t = getent("trigger","targetname");

while(1)

{

t waittill("trigger");

if(level.int < 10)

{
level.int ++;
}

else //What do I put here?

}

}



Re: Script command for not doing anything

Posted: January 16th, 2009, 5:45 pm
by waywaaaard
if you don't have anything in else you just dont need it
so only

Code: Select all

if (statement){
// your
// code
}

Re: Script command for not doing anything

Posted: January 16th, 2009, 6:05 pm
by Rezil
Read what I wrote above. I know you don't need else but I need to specify the script to not do anything when for example int = 10.

Re: Script command for not doing anything

Posted: January 16th, 2009, 6:14 pm
by waywaaaard
you don't need anything else you have your condition with the if and if the condition is not true nothing will happen

Re: Script command for not doing anything

Posted: January 16th, 2009, 6:31 pm
by Rezil
I guess I made a bad example but nevermind, I got the command. It was return; . :)

One more thing: How can you script so that when players are spawned, they're spawned without weapons?

Re: Script command for not doing anything

Posted: January 16th, 2009, 6:41 pm
by waywaaaard
omg you want to jump out of a function - why dont you say that -.-

Re: Script command for not doing anything

Posted: January 16th, 2009, 11:37 pm
by Drofder2004
Yeh, if you want NOTHING to happen, then dont add anything. If you want the function to end, use return;

Re: Script command for not doing anything

Posted: January 17th, 2009, 1:14 am
by Nightmare
Rez|l wrote:I guess I made a bad example but nevermind, I got the command. It was return; . :)

One more thing: How can you script so that when players are spawned, they're spawned without weapons?
Put a nice big trigger around the spawn, give it a nice targetname, one with your map name in front to avoid conflicts.
Then use this code.

Code: Select all

RemoveWeaponCheck()
{
	trig = getent("remove_weapon","targetname");
	while(1)
	{
		trig waittill("trigger",user);
		user thread RemoveWeapon();
		wait 0.05;
	}
}

RemoveWeapon()
{
	self takeAllWeapons();
}

Re: Script command for not doing anything

Posted: January 17th, 2009, 1:59 am
by Rezil
That's a simple script, anyone can write that. :D

I was looking something more along the lines of this(every time you are spawned your weapon is taken away):

Code: Select all


no_weapons()
{
	while(1)
	{
		players = getentarray("player", "classname");

		for(i=0;i<players.size;i++)
		{
			players[i] thread take_all_weapons();
		}
	wait 0.01;
	}
}
take_all_weapons()
{
	wait 0.01;
	self takeallweapons();
	self waittill ("spawned");
	
	}

My own script, adapted from Leveller's code for disabling saving. Works like a charm. :)

Re: Script command for not doing anything

Posted: January 17th, 2009, 2:49 am
by Nightmare
Why make things overly inefficient?
While it's not a big difference, you are still running more instances, which uses more RAM.

But, sure, go with your way...

P.S.
There is no such time as 0.01, CoD servers refresh every 0.05 of a second. Therefore it will take a tenth of a second to do one player. Take a server with ten players, and you will have players who still have weapons for a whole second.
I know I sound picky, but I'm just saying. :)

Re: Script command for not doing anything

Posted: January 17th, 2009, 4:00 pm
by Rezil
Your script is only if the player is touching the trigger. I'm going to spawn players at other places aswell(checkpoint system, I disabled saving) and making a trigger at every checkpoint wouldn't work in my case.

As for 0.05, didn't know that. I'll fix it. :)

Re: Script command for not doing anything

Posted: January 17th, 2009, 4:49 pm
by Drofder2004
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.

Re: Script command for not doing anything

Posted: January 18th, 2009, 4:52 pm
by Coontang
384000 !?!?!?!?!?!?

Re: Script command for not doing anything

Posted: January 18th, 2009, 6:32 pm
by Nightmare
Mine is still the most efficient, it will only re-loop when someone went through the trigger. :P
Also, you can surround the whole map with a trigger if you wish.

Re: Script command for not doing anything

Posted: January 18th, 2009, 6:47 pm
by Drofder2004
Efficient but demanding. ;)