Page 2 of 2

Re: Become invisible .. but how ?

Posted: March 18th, 2011, 9:13 pm
by <LT>YosemiteSam[NL]
Thx m8 it works, I had to change the code a bit ... 2 "{" removed and a few typo's. :) But it works fine now.
This is the final script;

Code: Select all

invisible() //only call this thread
//dont call any other threads, this one handles everything


{
   thread waitforconnect();
   thread monitortrig();
}

waitforconnect()
{
   for(;;)
   {
      level waittill("connecting",player);
      player thread waitforspawn();
   }
}

waitforspawn()
{
   self endon("disconnect");
   self.isInv=false;
   for(;;)
   {
      self waittill("spawned_player"); //might be "spawned" instead
      self.isInv=false;
   }
}

monitortrig()
{
   trigger=getent("invisible","targetname");
   for(;;)
   {
     trigger waittill("trigger",user);
     if(!user.isInv)

         user iprintlnbold("you are invisible");
         user thread makeinvisible(5); //for 5 seconds the user will be invisible remove the "thread" to make the trigger wait until the user is visible again
     }
   }

makeinvisible(time)
{
   self endon("disconnect");
   self endon("killed_player");
   self endon("spawned_player");
   
   self detachall();
   self setmodel("");
   self.isInv=true;

   wait time;
   
   self iprintlnbold("Invisibility has worn off");

   self.isInv=false;
   
   if(!isdefined(self.pers["savedmodel"]))
      maps\mp\gametypes\_teams::model();
   else
      maps\mp\_utility::loadModel(self.pers["savedmodel"]);
}

The only hickup now is that the sentence "invisibility has worn off" displays not once but more like 10 times. Have to look into that. Now I can combine this with the spawn/respawn weapon and trigger script and I'm good to go.

Re: Become invisible .. but how ?

Posted: March 18th, 2011, 11:32 pm
by IzNoGoD
yeah, you need those {} around

Code: Select all

         user iprintlnbold("you are invisible");
         user thread makeinvisible(5); //for 5 seconds the user will be invisible remove the "thread" to make the trigger wait until the user is visible again
else it will only use the "if" on the first line, and make the user invisible like 100 times

Re: Become invisible .. but how ?

Posted: March 19th, 2011, 12:18 am
by <LT>YosemiteSam[NL]
Aha ok.
When they were in the script it gave an error but now that the threading is ok it doesn't. I've put them back in and it works fine. Thx m8 !
I'll give you credit in the map for your hellp btw.
Here is a little demo;

Re: Become invisible .. but how ?

Posted: March 19th, 2011, 10:48 am
by IzNoGoD
Still has 2 "worn of" iprintlns.
Silly me, should have scripted the last 2 threads like this:

Code: Select all

monitortrig()
{
   trigger=getent("invisible","targetname");
   for(;;)
   {
     trigger waittill("trigger",user);
     if(!user.isInv)
     {
         user.isInv=true;
         user iprintlnbold("you are invisible");
         user thread makeinvisible(5); //for 5 seconds the user will be invisible remove the "thread" to make the trigger wait until the user is visible again
     }
   }

makeinvisible(time)
{
   self endon("disconnect");
   self endon("killed_player");
   self endon("spawned_player");
   
   self detachall();
   self setmodel("");

   wait time;
   
   self iprintlnbold("Invisibility has worn off");

   self.isInv=false;
   
   if(!isdefined(self.pers["savedmodel"]))
      maps\mp\gametypes\_teams::model();
   else
      maps\mp\_utility::loadModel(self.pers["savedmodel"]);
}
Moved self.isInv to the non-threaded one
Should work 100%

Re: Become invisible .. but how ?

Posted: March 19th, 2011, 4:17 pm
by <LT>YosemiteSam[NL]
Thx m8, works like a charm now.