Script problems

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

Moderator: Core Staff

Post Reply
User avatar
iCYsoldier
CJ Worshipper
CJ Worshipper
Posts: 289
Joined: December 5th, 2009, 7:12 am
Location: Australia

Script problems

Post by iCYsoldier » August 21st, 2010, 10:26 am

Hello,

I have my .gsc, and while there are no errors, there are some problems. I tested my map on CJ #13 and for some of the scripts, they only work once, for one player. For example, a player walks into a trigger, it prints out "Hello", then the next play walk into the trigger, and nothing happens. This happens for a fair few of my scripts.. Here are a just a few of them.

Code: Select all

msg1()
{
	message1 = getEnt("msg1", "targetname");
	message1 waittill ("trigger", player);
	iprintlnbold ("^7www.^1CoD^8Jumper^7.com - For all your CoDJumping needs!");
}
and..

Code: Select all

nosprint()
{
	trig = getEnt("nosprint","targetname");
	trig waittill ("trigger", user);
	user iprintln ("You cannot sprint in this room^6!");
	for(;;)
	{
		if (user isTouching(trig))
		{
			user allowSprint(false);
			wait 0.1;
		}
		else
		{
			user allowSprint(true);
			wait 0.1;
		}
	}
}
That's just two of them.. they both work well, but only for one player..

Also, the Dvar's that I set in the main(), don't have any affect while playing on the server, but do when I play on my own.

Can anyone point out what I'm doing wrong?

Thanks alot :)

User avatar
Opel
CJ Fan
CJ Fan
Posts: 188
Joined: September 15th, 2008, 12:28 pm
Location: Scotland

Re: Script problems

Post by Opel » August 21st, 2010, 11:28 am

For the dvars i think you use setclientdvar.

User avatar
Buzzard
CJ Wannabe
CJ Wannabe
Posts: 23
Joined: November 5th, 2009, 7:13 pm

Re: Script problems

Post by Buzzard » August 21st, 2010, 11:44 am

It only works for one player because the script isn't used in a loop. Also you should use Arrays so you don't have to create a function for each (message) trigger.
Use this script:

Code: Select all

main()
{
        ...

	addFunc("message", ::message);
	addFunc("no_sprint", ::no_sprint);
}
"message" and "no_sprint" are the two targetnames. So create a trigger and give it the targetname "message" for a message trigger and "no_sprint" for a no_sprint area.

Code: Select all

addFunc(targetname, function)
{
	entArray = getEntArray(targetname, "targetname");

	for(idx = 0;idx < entArray.size;idx++)
	{
		if(isDefined(entArray[idx]))
			thread [[function]](entArray[idx]);
	}
}
This is the function for initializing the trigger arrays.

Code: Select all

message(trigger)
{
	for(;;)
	{
		trigger waittill("trigger");

		iPrintLnBold(trigger.script_noteworthy);
		wait 2;
	}
}
This is the message function. You can define trigger.script_noteworthy in the radiant. Just do: - Key: script_noteworthy - Value: <your message>

Code: Select all

no_sprint(trigger, user)
{
	if(!isDefined(user))
	{
		for(;;)
		{
			trigger waittill("trigger", user);

			if(isDefined(user.no_sprint))
				continue;

			thread no_sprint(trigger, user);
		}
	}

	user endon("disconnect");

	user.no_sprint = true;

	user iPrintLn("You cannot sprint in this room^6!");

	user allowSprint(false);

	for(;user isTouching(trigger);)
		wait 0.05;

	user allowSprint(true);

	user.no_sprint = undefined;
}
This is the no_sprint function.

User avatar
iCYsoldier
CJ Worshipper
CJ Worshipper
Posts: 289
Joined: December 5th, 2009, 7:12 am
Location: Australia

Re: Script problems

Post by iCYsoldier » August 21st, 2010, 12:49 pm

Well, I tried that code in there, but unfortunately it didn't work.. but I do appreciate the effort, thanks Buzzard.

Again, I got no errors, but they are both not working. What type of trigger, I'm using trigger_multiple, could that be the reason? Other than that, I'm pretty sure I've done everything else right..

About the arrays, is there any way to keep the code nice and simple? Because I'm just a little uneasy with having code that I can't fully understand, in case I need to make changes and things..

Thanks again all..

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: Script problems

Post by megazor » August 21st, 2010, 3:56 pm

Code: Select all

msg1()
{
	while(1)
	{
   		getEnt("msg1", "targetname") waittill ("trigger", player);
   		player iprintlnbold("^7www.^1CoD^8Jumper^7.com - For all your CoDJumping needs!");
	}
}

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: Script problems

Post by megazor » August 21st, 2010, 4:03 pm

Code: Select all

nosprint()
{
	trig = getEnt("nosprint","targetname");
	while(1)
	{
   		trig waittill ("trigger", user);
		if (!isDefined(user.nosprintLOL))
			user thread trigthink(trig);
	}
}

trigthink(ent)
{
	self.nosprintLOL = 1;
  	self iprintln ("You cannot sprint in this room^6!");
	self allowSprint(false);
   	while(isPlayer(self) && self isTouching(ent))
        		 wait 0.1;
   
	if (!isPlayer(self)) return;
         	self allowSprint(true);
	self.nosprintLOL = undefined;
}
perhaps isPlayer function is unnecessary, but should be working anyway.

User avatar
iCYsoldier
CJ Worshipper
CJ Worshipper
Posts: 289
Joined: December 5th, 2009, 7:12 am
Location: Australia

Re: Script problems

Post by iCYsoldier » August 22nd, 2010, 12:11 am

Well megazor, the nosprint script works very well, thanks for that..

But regarding the message, I was looking for it to not go off every x amount of seconds for the same player. So, I don't want a player to stay in the trigger, and if i added a 'wait 2;' line, and for it to go off every 2 seconds. But still, it's not a very big deal..

Thanks alot man.. and I'm still welcome for help if anyone has any ideas..

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: Script problems

Post by megazor » August 22nd, 2010, 1:41 am

Code: Select all

msg1()
{
   	while(1)
   	{
        		getEnt("msg1", "targetname") waittill ("trigger", player);
		if (!isDefined(player.cjmessage))
			player thread what_am_i_looking_for();
	}
}

what_am_i_looking_for()
{
	self.cjmessage = 1;
	self iprintlnbold("^7www.^1CoD^8Jumper^7.com - For all your CoDJumping needs!");
	wait 2;
	if (isPlayer(self)) self.cjmessage = undefined;
}
what this code does is printing the message every two seconds to the player while them touching the trigger. this is exactly what u wanted. if u aren't happy with this option, i can write a better code which would print the message only at the first touch, but if the player stopped touching the trigger, it would print again at a repeated touch.

User avatar
iCYsoldier
CJ Worshipper
CJ Worshipper
Posts: 289
Joined: December 5th, 2009, 7:12 am
Location: Australia

Re: Script problems

Post by iCYsoldier » August 22nd, 2010, 12:32 pm

Actually, what I had in mind was something like at the end of mp_peds_propel. All you get is one message for each player, which only happens once in the game. Would you know how to do that? Because I sure don't lol..

But thanks again :)

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

Re: Script problems

Post by Drofder2004 » August 22nd, 2010, 1:00 pm

msg1()
{
while(1)
{
getEnt("msg1", "targetname") waittill ("trigger", player);

Code: Select all

      if (!isDefined(player.cjmessage))
         player thread what_am_i_looking_for();
   }
}

what_am_i_looking_for()
{
   self.cjmessage = 1;
   self iprintlnbold("^7www.^1CoD^8Jumper^7.com - For all your CoDJumping needs!");
}
Fix of the above code. The message will only print once.
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
iCYsoldier
CJ Worshipper
CJ Worshipper
Posts: 289
Joined: December 5th, 2009, 7:12 am
Location: Australia

Re: Script problems

Post by iCYsoldier » August 22nd, 2010, 2:05 pm

Perfect Drofder, thanks alot man.. I haven't tested it with 2 people, but I'm sure it'll work. Also thanks megazor and buzzard :)

One last thing, can you explain what some of the script is actually doing? Because I'd like to use it in different situations and not have it stuff up when I play around with it..

Code: Select all

msg1()
{
	while(1) // Infinite loop
	{
		getEnt("msg1", "targetname") waittill ("trigger", player); // Gets entity from map and waits till player touches
		if (!isDefined(player.cjmessage))
			player thread what_am_i_looking_for();
	}
}

what_am_i_looking_for()
{
	self.cjmessage = 1;
	self iprintlnbold("^7www.^1CoD^8Jumper^7.com - For all your CoDJumping needs!");
}
And yeh, I'd just like to know.. But it does work, thanks

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

Re: Script problems

Post by Drofder2004 » August 22nd, 2010, 2:46 pm

iCYsoldier wrote:One last thing, can you explain what some of the script is actually doing? Because I'd like to use it in different situations and not have it stuff up when I play around with it..

Code: Select all

msg1()
{
	while(1) // Start of infinite loop
	{
		getEnt("msg1", "targetname") waittill ("trigger", player); // Gets entity from map and waits till player touches the trigger

		if (!isDefined(player.cjmessage)) // This will check if the variable in the brackets exists. the '!' means "not".
			player thread what_am_i_looking_for(); //Because the variable does not exist, this thread is run on the player
	} // The end of the loop
}

what_am_i_looking_for()
{
	self.cjmessage = 1; //This defines the variable above and makes it exist
	self iprintlnbold("^7www.^1CoD^8Jumper^7.com - For all your CoDJumping needs!"); // Prints the message
}
To summarise, the loops starts.
The trigger is defined (getent).
The trigger then pauses the function (waittill) unti the event (trigger) occurs.
When the even has occured, the IF statement checks for a variable (player.cjmessage).
If the variable does NOT (!) exist, the function is then threaded.
If the variable DOES exist, this function is skipped.
The loops is then restarted,

The other function creates the variable that did not exist.
The message is then played to the player.

Because now the variable exists, the loop simply does not thread the function to that player and will continously loop.
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
iCYsoldier
CJ Worshipper
CJ Worshipper
Posts: 289
Joined: December 5th, 2009, 7:12 am
Location: Australia

Re: Script problems

Post by iCYsoldier » August 22nd, 2010, 10:07 pm

I completely understand now :)

Thanks alot Drofder for the explanation.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests