Page 1 of 1
Script problems
Posted: August 21st, 2010, 10:26 am
by iCYsoldier
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

Re: Script problems
Posted: August 21st, 2010, 11:28 am
by Opel
For the dvars i think you use setclientdvar.
Re: Script problems
Posted: August 21st, 2010, 11:44 am
by Buzzard
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.
Re: Script problems
Posted: August 21st, 2010, 12:49 pm
by iCYsoldier
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..
Re: Script problems
Posted: August 21st, 2010, 3:56 pm
by megazor
Code: Select all
msg1()
{
while(1)
{
getEnt("msg1", "targetname") waittill ("trigger", player);
player iprintlnbold("^7www.^1CoD^8Jumper^7.com - For all your CoDJumping needs!");
}
}
Re: Script problems
Posted: August 21st, 2010, 4:03 pm
by megazor
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.
Re: Script problems
Posted: August 22nd, 2010, 12:11 am
by iCYsoldier
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..
Re: Script problems
Posted: August 22nd, 2010, 1:41 am
by megazor
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.
Re: Script problems
Posted: August 22nd, 2010, 12:32 pm
by iCYsoldier
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

Re: Script problems
Posted: August 22nd, 2010, 1:00 pm
by Drofder2004
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.
Re: Script problems
Posted: August 22nd, 2010, 2:05 pm
by iCYsoldier
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
Re: Script problems
Posted: August 22nd, 2010, 2:46 pm
by Drofder2004
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.
Re: Script problems
Posted: August 22nd, 2010, 10:07 pm
by iCYsoldier
I completely understand now
Thanks alot Drofder for the explanation.