Script command for not doing anything

Have questions about CoD2 mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Script command for not doing anything

Post by Rezil » January 16th, 2009, 4:39 pm

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?

}

}


Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
waywaaaard
Core Staff
Core Staff
Posts: 2214
Joined: February 6th, 2006, 3:18 pm
Location: Germany/Bayern

Re: Script command for not doing anything

Post by waywaaaard » January 16th, 2009, 5:45 pm

if you don't have anything in else you just dont need it
so only

Code: Select all

if (statement){
// your
// code
}
THAT HANDS WERE NOT TRACED!
visit my blog: Link
Soviet wrote:Yeah, watch out, Peds will hit you with his +5 D-Battleaxe of homosexuality :roll:

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Script command for not doing anything

Post by Rezil » January 16th, 2009, 6:05 pm

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.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
waywaaaard
Core Staff
Core Staff
Posts: 2214
Joined: February 6th, 2006, 3:18 pm
Location: Germany/Bayern

Re: Script command for not doing anything

Post by waywaaaard » January 16th, 2009, 6:14 pm

you don't need anything else you have your condition with the if and if the condition is not true nothing will happen
THAT HANDS WERE NOT TRACED!
visit my blog: Link
Soviet wrote:Yeah, watch out, Peds will hit you with his +5 D-Battleaxe of homosexuality :roll:

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Script command for not doing anything

Post by Rezil » January 16th, 2009, 6:31 pm

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?
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
waywaaaard
Core Staff
Core Staff
Posts: 2214
Joined: February 6th, 2006, 3:18 pm
Location: Germany/Bayern

Re: Script command for not doing anything

Post by waywaaaard » January 16th, 2009, 6:41 pm

omg you want to jump out of a function - why dont you say that -.-
THAT HANDS WERE NOT TRACED!
visit my blog: Link
Soviet wrote:Yeah, watch out, Peds will hit you with his +5 D-Battleaxe of homosexuality :roll:

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13315
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Script command for not doing anything

Post by Drofder2004 » January 16th, 2009, 11:37 pm

Yeh, if you want NOTHING to happen, then dont add anything. If you want the function to end, use return;
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

User avatar
Nightmare
Core Staff
Core Staff
Posts: 2688
Joined: January 12th, 2006, 10:09 pm
Contact:

Re: Script command for not doing anything

Post by Nightmare » January 17th, 2009, 1:14 am

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();
}
Coding is Poetry. Mapping is Art.
"Cause im the sexiest mapper ever...except for nm, that sexy man" - Soviet

-=[CoDJumper.com Movies]=-
[Ambush] || [Backlot] || [Bloc] || [Bog] || [Broadcast] || [Chinatown] || [Countdown]
[Crash] || [Creek] || [Crossfire] || [District] || [Downpour] || [Killhouse] || [Overgrown]
[Pipeline] || [Shipment & Wetwork] || [Showdown] || [Strike] || [Vacant]

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Script command for not doing anything

Post by Rezil » January 17th, 2009, 1:59 am

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. :)
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
Nightmare
Core Staff
Core Staff
Posts: 2688
Joined: January 12th, 2006, 10:09 pm
Contact:

Re: Script command for not doing anything

Post by Nightmare » January 17th, 2009, 2:49 am

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. :)
Coding is Poetry. Mapping is Art.
"Cause im the sexiest mapper ever...except for nm, that sexy man" - Soviet

-=[CoDJumper.com Movies]=-
[Ambush] || [Backlot] || [Bloc] || [Bog] || [Broadcast] || [Chinatown] || [Countdown]
[Crash] || [Creek] || [Crossfire] || [District] || [Downpour] || [Killhouse] || [Overgrown]
[Pipeline] || [Shipment & Wetwork] || [Showdown] || [Strike] || [Vacant]

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Script command for not doing anything

Post by Rezil » January 17th, 2009, 4:00 pm

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. :)
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13315
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Script command for not doing anything

Post by Drofder2004 » January 17th, 2009, 4:49 pm

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.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

User avatar
Coontang
CJ G0D!
CJ G0D!
Posts: 1797
Joined: March 4th, 2007, 3:48 pm
Location: Painting by numbers

Re: Script command for not doing anything

Post by Coontang » January 18th, 2009, 4:52 pm

384000 !?!?!?!?!?!?
Image
JDogg: 'I have a video of me pissing, wanna see?'

User avatar
Nightmare
Core Staff
Core Staff
Posts: 2688
Joined: January 12th, 2006, 10:09 pm
Contact:

Re: Script command for not doing anything

Post by Nightmare » January 18th, 2009, 6:32 pm

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.
Coding is Poetry. Mapping is Art.
"Cause im the sexiest mapper ever...except for nm, that sexy man" - Soviet

-=[CoDJumper.com Movies]=-
[Ambush] || [Backlot] || [Bloc] || [Bog] || [Broadcast] || [Chinatown] || [Countdown]
[Crash] || [Creek] || [Crossfire] || [District] || [Downpour] || [Killhouse] || [Overgrown]
[Pipeline] || [Shipment & Wetwork] || [Showdown] || [Strike] || [Vacant]

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13315
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Script command for not doing anything

Post by Drofder2004 » January 18th, 2009, 6:47 pm

Efficient but demanding. ;)
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests