Page 1 of 1

Directed more towards drofter... Script Question

Posted: July 4th, 2007, 4:14 pm
by Lethal323
Drofter is possible to make a trigger that when activated it will start a thread over even if it is in the middle of threading that thread?


:) Asked peds dude got this respawns

PeЧĐuĐe@CoDJumper.com: i'm not that great with scripting
PeЧĐuĐe@CoDJumper.com: post on the codjumper forums - drofder will know


:) Thanks in advance

Posted: July 4th, 2007, 4:43 pm
by Drofder2004
So you want a thread that restarts when called?

Ok, using the endon/notify feature

Code: Select all

function()
{
   level endon ("thread_restart");

   // add the rest of what you wanted here
}
Now, to call the thread, and the restart it.

Code: Select all

another_function()
{
   thread function();

   // Add any thing you here (maybe an if statement to restart the thread).
   level notify ("thread_restart");
   thread function();
}
Basically, how this works is simple. You tell the function which you threaded to wait until it is notified of a thread restart call.
(level endon ("thread_restart");)
Then when you want to restart the thread, you use the notify function.
(level notify ("thread_restart");)

You could also do the same thing using another method (it all depends on what you want to do with the thread and why it restarts...

A double for() loop

Code: Select all

function()
{
   for(;;)
   {
      for(;;)
      {
         // Add what you want in the function here
 
         // Add an if statement to tell the loop when/why it should restart, for example.
         if(level.timer < 1)
            break;
      
         wait 0.05;
      }
      wait 0.05;
   }
}
Basically the way this works is more simple but cannot be used in all circumstances.
The thread starts an infinite loop, the loop is immediately paused and another infinite loop starts inside.
Inside the 2nd loop is where you place your thread, and whatever you want to do, at the end of the thread, an if statement is called. If the statement is true, then the 2nd for loop breaks and the first loop is restarted. The loop continues and restarts the 2nd loop again.

Posted: July 5th, 2007, 7:25 am
by Lethal323
Cool that really helped drofter thanks once again :)

This one may be more complicated :) Boy am I testing you...


I need this... There is a room an I need it so if you walk into the room, It will say user.name has entered the room but if you leave it then it will say user.name has left the room... the thing is I dont need it to say it to anybody I need it to say it to a person in another room... Not the person leaving and entering the room... Person in a hidden area... They way I was thinking of it is almost by putting 2 triggers and than an if statement saying if you know this trigger and then this trigger say... you know.. (accept that be in scripting terms :)) So anyways, thats my latest and greatest question, If you want so we dont half to chat on here add me to one of my contacts...
I will put Special Thanks To: Drofter on my dds layout... Thanks in advance


Lethal

Code: Select all

Contacts:

Xfire: shadowsniper327
Aim: sexystud323327
Msn: lethalgoa@hotmail.com
Email: Lethal@theprogamers.com

Posted: July 5th, 2007, 8:46 pm
by Drofder2004
Ok, this will require a slightly more complex script.

Ok, check who is in room B first...

Code: Select all

RoomB()
{
   level.triggerB = getent("triggerB","targetname");
   while(1)
   {
      level.triggerB waittill("trigger", user);
      
      if(!isDefined(user.watched) || user.watched == 0)
         user thread _watched();
   }
}
While player is touching the triggerB.

Code: Select all

_watched()
{
   self.watched = 1;
   while(self isTouching(level.triggerB))
   {
       wait 1;
   }
   
   self.watched = 0;
}
Ok, now to monitor triggerA for enter/exit

Code: Select all

roomA()
{
   level.triggerA = getent("triggerA","targetname");
   
   while(1)
   {
      level.triggerA waittill("trigger", user);
      if(!isDefined(user.roomA) || user.roomA == 0)
         user thread _triggerA();
   }
}

Code: Select all

_triggerA()
{
   self.roomA = 1;
   // Message those in roomB
   players = getentarray("player","classname");
   for(i=0;i<players.size;i++)
   {
      if(isDefined(players[i].roomB))
         if(players[i].roomB == 1)
            players[i] iprintlnbold(self.name + "^7 has entered room A");
   }
   
   while(self istouching("level.triggerA")
   {
      wait 1;
   }
   
   for(i=0;i<players.size;i++)
   {
      if(isDefined(players[i].roomB))
         if(players[i].roomB == 1)
            players[i] iprintlnbold(self.name + "^7 has left room A");
   }

   self.roomA = 0;
}
This is all untested, and striahgt off the top of my head. There will be errors more than likely (I doubt I got this correct first time).
Report back...

Posted: July 5th, 2007, 10:10 pm
by Lethal323
The only problem is... I need it to display only to people in a secret room... I will draw you a quick piture...



Image






**EDIT** of, drr i was thinking trigger B was level 2, im being stupid. It can be what ever I want it to be... lol **EDIT**

You should add one of my contacts...

Posted: July 6th, 2007, 12:05 am
by Drofder2004
Room A = level 1
Room B = hidden room

(And sorry, I dont use any contact apps)

Posted: July 6th, 2007, 1:12 am
by Lethal323
oh alright...


If you have a moment can you tell me alot of the import level.(things)


The level.time... astuff like that, things that come in handy


And also, Have you seen in nightmares map dual how he has his passcode thing, ya think you could help me a lil with one of tho


What I dont understand about his, is where did he defined what each number is...

Posted: July 6th, 2007, 2:58 am
by Nightmare
it was defined in a for loop. I had the names as nm_dual_button_# and it just looped through them.

Posted: July 6th, 2007, 3:02 pm
by Drofder2004
the term "level." is used when you want a variable to be accessed globally.

If I have a variable called "var_01", then I could only use it in the thread it was defined.
But if I name it "level.var_01", then I can sue it anywhere in the entire script.
And the same goes for "self.var_01" can be used whenever self is referenced.

The script above uses 2 level variables...

level.TriggerA (the trigger which covers the entire area inside RoomA)
level.TriggerB (the trigger which covers the entire area inside roomB)

and 2 self variables.

self.watched (this stops the thread from being run multiple times)
self.roomA (while the player is in RoomA this is equal to 1)

you will only need to chang ethe "getent" of the 2 triggers, to match the names of your triggers.

Posted: July 6th, 2007, 4:19 pm
by Lethal323
alright, I appriciate everything drofter, Thanks for the help, Someone can lock this now... I also got that password thing working :)

:) x 100

Posted: July 6th, 2007, 4:55 pm
by Nightmare
wheres Pac-man when you need him 0_o

Posted: July 6th, 2007, 6:55 pm
by Drofder2004
Nightmare wrote:wheres Pac-man when you need him 0_o
I just arrived :P

Good luck with the code, hope it works as intended.