Value for all players OR for 1 player

Have a question about modding, modelling or skinning? Have a tutorial to post? Post here!

Moderator: Core Staff

Post Reply
Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Value for all players OR for 1 player

Post by Moustache » May 12th, 2010, 2:44 pm

This should be for the one player that knives: When one player knifes he add 1 to the value boom. When boom = 2 he explode and die.
This should be for all players: When someone explodes he adds 1 to the value level.total. When level.total = 3 people do not explode but only here the explosion sound and die.

But I do not know if it is correct. Sometimes the script acts a bit strange. Then it looks like it doesn't count good. So then you see for example 5 explosions instead of the max of 3. But this is only when there are multiple people in the server.
When a player joins you can explode again, with effect and with sound. It shouldn't be like that.

Shortly said: level.total needs to count for all the players. And boom needs to count for only the player that knifed.

This is the full script:

Code: Select all

setnoob()
{
	boom = 0;
	level.total = 0;
	self endon( "disconnect" );
	for(;;)
	{
		wait 0.05;
		if ( self meleeButtonPressed () && isPlayer(self) && self.sessionstate == "playing")
		{
			boom++;

			if (boom==1)
			{
				self IPrintLnBold( "^1Warning" );
				wait 1.4;

				while(self meleeButtonPressed ())
				{
					wait 0.05;
				}
			}

			else if (boom>=2 && level.total<=3)
			{
				boom = 0;
				level.total++;

				self IPrintLnBold( "^1DIE^7!" );
				wait 3;

				playfx(level.fx_knife, self.origin);
				self playsound("artillery_explosion");
				wait 0.05;

				self.ex_cmdmondeath = true; 
				if(isPlayer(self)) self suicide(); 

				IPrintLn("^6" + self.name + " ^7was blown to bits because he can't ^1knife");
			}

			else if (boom>=2 && level.total>=4)
			{
				boom = 0;
				level.total++;

				self IPrintLnBold( "^1DIE^7!" );
				wait 3;

				self playlocalSound("artillery_explosion");
				wait 0.05;

				self.ex_cmdmondeath = true; 
				if(isPlayer(self)) self suicide(); 

				self IPrintLn( "Sorry, no ^1explosion^7. We already have seen enough of them this map");
				IPrintLn("^6" + self.name + " ^7died because he can't ^1knife");
			}

			else
			{
				boom = 0;
			}
		}
	}
}

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: Value for all players OR for 1 player

Post by Rezil » May 12th, 2010, 4:18 pm

I'm confused as to why you need level.total, wouldn't a simple check if boom is more than 3 and not play the explosion fx be sufficient?

EDIT: Disregard, read it a bit better, so you want a maximum of 3 explosions? Try this:

Code: Select all


GetPlayers()
{
	for(;;)
	{
		players = getentarray("player", "classname");
		for(i = 0; i < players.size; i++) 
		{
			if ((!isdefined(players[i].reset)) && (isalive(players[i])))
			{	
				players[i].reset = true;
				players[i] thread HasKnifed();
			}
		}
		wait 0.05;
	}
}

HasKnifed()
{
	knife_count = 0;
	if(!isdefined(level.global_knife_count))
	{
		level.global_knife_count = 0;
	}
	for(;;)
	{
		if (self meleeButtonPressed()&&isPlayer(self)&&self.sessionstate=="playing")
		{
			knife_count ++;
			if(knife_count==1)
			{
				self IPrintLnBold( "^1Warning" );
				wait 1.4;
			}
			else if(knife_count>=2)
			{
				knife_count = 0;
				level.global_knife_count ++;
				self IPrintLnBold( "^1DIE^7!" );
				wait 3;
				if(level.global_knife_count < 3)
				{
					//level.playfx(level.fx_knife, self.origin);
					//self playsound("artillery_explosion");
					wait 0.05;
					self.ex_cmdmondeath = true; //What's this for?
					self suicide();
					IPrintLn("^6" + self.name + " ^7was blown to bits because he can't ^1knife");
				}
				else if(level.global_knife_count >= 3)
				{
					//self playlocalSound("artillery_explosion");
					wait 0.05;
					self.ex_cmdmondeath = true;
					if(isPlayer(self)) self suicide();
					self IPrintLn( "Sorry, no ^1explosion^7. We already have seen enough of them this map");
					IPrintLn("^6" + self.name + " ^7died because he can't ^1knife");
				}
			}
			wait 0.05;
		}
		wait 0.05;
	}
}

Haven't tested it so it might be buggy.

EDIT2: Revised it like 10x :)
EDIT3: Tested it in cod2, works perfectly for one player, should work for multiple aswell. Remove // from playfx and playsound, omitted them because I wasn't sure if they're present in cod2, the line prints work though and you die.

Call maps\mp\_knifekill_revised::GetPlayers(); in your main map .gsc.
Last edited by Rezil on May 12th, 2010, 5:56 pm, edited 1 time in total.
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.

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: Value for all players OR for 1 player

Post by Moustache » May 12th, 2010, 5:56 pm

But that maximum is for only that player. Not for all the players right?

And I want that is is for all the players. So if player1 explodes and player2 and player3. That players cant explode anymore for that map. Only in the next map they can explode again.

Shouldn't I need something like this?

Code: Select all

setdvar("scr_total", "1");
And when they explode set that server dvar to +1 ?

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: Value for all players OR for 1 player

Post by Rezil » May 12th, 2010, 5:59 pm

The script checks for every player on the server if level.global_knife_count(a global variable) is less than 3. If it is, the player will explode; if not, he won't. I haven't tested it on a server, you try it out and tell me if it works.

The GetPlayers thread will loop all the time so the number of players on the server is updated every 0.05 seconds, it will then thread HasKnifed to every player on the server where it will check the number of global knifes and his own local knifecount. The explosions will only happen at the first three knifes, afterwards everyone will die without an explosion until a restart or a map change.
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.

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: Value for all players OR for 1 player

Post by Moustache » May 12th, 2010, 7:42 pm

Thanxs :D :mrgreen:
It works great now.

If you want to know, this is the full script now:

Code: Select all

setnoob()
{
	for(;;)
	{
		players = getentarray("player", "classname");
		for(i = 0; i < players.size; i++) 
		{
		if ((!isdefined(players[i].reset)) && (isalive(players[i])))
			{
				players[i].reset = true;
				players[i] thread HasKnifed();
			}
		}
	wait 0.05;
	}
}

HasKnifed()
{
	knife_count = 0;
	if(!isdefined(level.global_knife_count))
	{
		level.global_knife_count = 0;
	}

	for(;;)
	{
      		if (self meleeButtonPressed()&&isPlayer(self)&&self.sessionstate=="playing")
		{
			knife_count ++;

			if(knife_count==1)
			{
				self IPrintLnBold( " ");
				self IPrintLnBold( " ");
				self IPrintLnBold( " ");
				self IPrintLnBold( "^6Noob ^7!" );
				self IPrintLnBold( " ");
				self IPrintLnBold( "^1Warning 1^7: You missed with knife" );
				wait 1.5;

				while(self meleeButtonPressed ())
				{
					wait 0.05;
				}
			} 

			else if(knife_count==2)
			{
				self IPrintLnBold( " ");
				self IPrintLnBold( " ");
				self IPrintLnBold( " ");
				self IPrintLnBold( "^6Noob ^7!" );
				self IPrintLnBold( " ");
				self IPrintLnBold( "^1Warning 2^7: You missed ^1again ^7with knife" );
				wait 1.5;

				while(self meleeButtonPressed ())
				{
					wait 0.05;
				}
			}

			else if(knife_count==3)
			{
				self IPrintLnBold( " ");
				self IPrintLnBold( " ");
				self IPrintLnBold( " ");
				self IPrintLnBold( "^6Noob ^7!" );
				self IPrintLnBold( " ");
				self IPrintLnBold( "^1 FINAL Warning^7: If you miss one more time you ^1die^7!" );
				wait 1.5;

				while(self meleeButtonPressed ())
				{
					wait 0.05;
				}
			}

			else if(knife_count>=4)
			{
				knife_count = 0;
				level.global_knife_count ++;

				self IPrintLnBold( " ");
				self IPrintLnBold( " ");
				self IPrintLnBold( " ");
				self IPrintLnBold( " ");
				self IPrintLnBold( " ");
				self IPrintLnBold( "Time to ^1DIE^7!" );
				Earthquake( 0.5, 1, self.origin, 75 );
				wait 1;
				Earthquake( 0.8, 1, self.origin, 75 );
				wait 1;
				Earthquake( 1.1, 1, self.origin, 75 );
				wait 1;

				if(level.global_knife_count<=3)
				{
					playfx(level.fx_knife, self.origin);
					self playsound("artillery_explosion");
					wait 0.05;
					Earthquake( 2.5, 3, self.origin, 100 );
					wait 0.05;
					self.ex_cmdmondeath = true;
					self suicide();

					IPrintLn("^6" + self.name + " ^7was blown to bits because he can't ^1knife");
				}

				else if(level.global_knife_count>=4)
				{
					self playlocalSound("artillery_explosion");
					wait 0.05;
					self.ex_cmdmondeath = true;
					if(isPlayer(self)) self suicide();

					self IPrintLnBold( " ");
					self IPrintLnBold( " ");
					self IPrintLnBold( " ");
					self IPrintLnBold( " ");
					self IPrintLnBold( "Sorry, no ^1explosion");
				        self IPrintLnBold( "We already have seen enough of them this map");

					IPrintLn("^6" + self.name + " ^7died because he can't ^1knife");
				}
			}
			wait 0.05;
		}
		wait 0.05;
	}
}

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: Value for all players OR for 1 player

Post by Rezil » May 12th, 2010, 8:01 pm

No problem, glad I could help. :)
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.

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: Value for all players OR for 1 player

Post by Moustache » May 12th, 2010, 8:56 pm

Rez|l wrote:No problem, glad I could help. :)
I am also glad that you could help :mrgreen:

Post Reply

Who is online

Users browsing this forum: No registered users and 37 guests