Invisible script bug

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

Moderator: Core Staff

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

Re: Invisible script bug

Post by Drofder2004 » April 15th, 2011, 9:54 pm

Code: Select all

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

Code: Select all

if(!isdefined(self.pers["savedmodel"]))
   self maps\mp\gametypes\_teams::model();
else
   self maps\mp\_utility::loadModel(self.pers["savedmodel"]);
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

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

Re: Invisible script bug

Post by megazor » April 16th, 2011, 7:02 am

i think you would rather add a few strings to the 'damage' or 'killed' callbacks.

using pseudocode:

Code: Select all

if player is invisible -> kill him
i also faced such an invulnerable bug, with player's health bar shown empty. when debugging, i noticed that the 'sessionteam' of such players was NOT "playing", it was "spectator". and the game doesn't kill players whose session team is spectator. that is because of the corresponding check in the 'killed' callback

im talking cod1 so the content of callbacks may vary.

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

Re: Invisible script bug

Post by megazor » April 16th, 2011, 8:22 am

Code: Select all

thread bla()
is the same as

Code: Select all

self thread bla()
except hard-coded functions.

example:

Code: Select all

func_1()
{
        players = getEntArray("player", "classname");
	if (players.size)
		players[0] thread func_2();
}

func_2()
{
	thread func_3();
        level thread func_4();
}

func_3()
{
	while(1)
	{
		wait 1;
	}
}

func_4()
{
	while(1)
	{
		wait 1;
	}
}
in func_1, self = level
in func_2, self = player
in func_3, self = player
in func_4, self = level

this is very important:
if, inside a function, self stands for the level, the function dies on map restart/change;
but if self stands for a player, the function dies after the player has disconnected.


so, func_3 will die on player's disconnect or, obviously, on map restart/change.
but func_4 will die only on map restart or change.

keep it in your mind.

if you don't want a function to stop upon player's disconnect, make sure its self is the level, not a player!

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: Invisible script bug

Post by IzNoGoD » April 16th, 2011, 8:55 am

thread does always run on level, wheter it is called from a level or a self thread.

Then, it doesnt simply die, because you need some "self endon("disconnect");" thing in there for it to die.
LMGTFY!

Its not a glitch... Its the future!

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

Re: Invisible script bug

Post by megazor » April 16th, 2011, 9:25 am

you are wrong. if there is nothing before "thread function()", then it will run on 'self', which may be either player or level.

i have just tested it on cod1 and the test confirmed what i wrote.

User avatar
<LT>YosemiteSam[NL]
Core Staff
Core Staff
Posts: 2155
Joined: December 7th, 2004, 2:07 am
Location: Netherlands
Contact:

Re: Invisible script bug

Post by <LT>YosemiteSam[NL] » April 16th, 2011, 12:10 pm

megazor wrote:i think you would rather add a few strings to the 'damage' or 'killed' callbacks.

using pseudocode:

Code: Select all

if player is invisible -> kill him
i also faced such an invulnerable bug, with player's health bar shown empty. when debugging, i noticed that the 'sessionteam' of such players was NOT "playing", it was "spectator". and the game doesn't kill players whose session team is spectator. that is because of the corresponding check in the 'killed' callback

im talking cod1 so the content of callbacks may vary.
Well, the script is working like it should (the one I posted earlier) but my main concern is that it (most likely it is this script) crashes the server with the error message "too many variables". I'll test it on monday when I play the map with friends again.

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

Re: Invisible script bug

Post by Drofder2004 » April 16th, 2011, 12:29 pm

megazor wrote:you are wrong. if there is nothing before "thread function()", then it will run on 'self', which may be either player or level.

i have just tested it on cod1 and the test confirmed what i wrote.
This is correct.
When no entity is given, the parent entity (I think this is the correct term) is taken.
If you call a thread by doing "self thread()", then you no longer need to reference "self" unless you are caling a stock function.

Although, again this is an aesthetics and etiquette position, where I will always place "self" before a function if self is not 'level'.
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

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

Re: Invisible script bug

Post by megazor » April 16th, 2011, 12:52 pm

Code: Select all

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

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

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

monitortrig()
{
       trigger=getent("invisible","targetname");
       fx = loadfx ("fx/dust/morpheus_spawnarmorinvis.efx");
       invissound = getent("invisible_sound","targetname");
       for(;;)
       {
         trigger waittill("trigger",user);
         if(!user.isInv)
         {
            user.isInv = true;
            user iprintln("^2 You have invisibility");
                 user thread makeinvisible(45);
               user playsound("invisibility");
            wait 150;
            invissound playsound("spawnsound");
            playfx (fx, (-100,-996,224));
   
        }
}

makeinvisible(time)
{
       //self endon("disconnect");
       self endon("killed_player");
       self endon("spawned");
       self endon("suicide");
   
       self detachall();
       self setmodel("");


       for (i = 0; i < time; i++)
       {
                wait 1;

             if (self.health <= 0) // caught fatal damage or joined spectators
            {
                        if (self.sessionstate == "playing")
                        {
                         self.health = 100;
                           self suicide();
                        }
             return;
        }
    }

        if (self.sessionstate != "playing")
                return;

        self.isInv = false;

       if(!isDefined(self.pers["savedmodel"]))
              mapsmpgametypes_teams::model();
       else
              mapsmp_utility::loadModel(self.pers["savedmodel"]);

       self iprintln("^2 Invisibility has worn off");  
} 
Last edited by megazor on April 16th, 2011, 1:06 pm, edited 2 times in total.

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: Invisible script bug

Post by Rezil » April 16th, 2011, 12:56 pm

Code: Select all

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

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

waitforspawn()
{
	self endon("disconnect");
	for(;;)
	{
		self waittill("spawned");
		self.isInv=false;
	}
}

monitortrig()
{
	trigger=getent("invisible","targetname");
	fx = loadfx ("fx/dust/morpheus_spawnarmorinvis.efx");
	invissound = getent("invisible_sound","targetname");
	for(;;)
	{
		trigger waittill("trigger",user);
		if(!user.isInv)
		{
			user.isInv=true;
			user iprintln("^2 You have invisibility");
			user thread makeinvisible(45);
			user playsound("invisibility");
			wait 150;
			invissound playsound("spawnsound");
			playfx (fx, (-100,-996,224));
		}
	}
}

makeinvisible(time)
{
	//time = 45; //<-lolwat
	self endon("disconnect");
	self endon("killed_player");
	self endon("spawned");
	self endon("suicide");

	self detachall();
	self setmodel("");

	self invHealth(time); //blocking for <time> seconds
	if(self.isInv) self.isInv=false;

	if(!isdefined(self.pers["savedmodel"])) self maps\mp\gametypes\_teams::model();
	else self maps\mp\_utility::loadModel(self.pers["savedmodel"]);
	self iprintln("^2Invisibility has worn off");

}

invHealth(time)
{
	for(i=0;i<time;i++)
	{
		if(self.health <= 0)
		{
			self.isInv=false;
			self suicide();
			self.health = 100;
			break;
		}
		wait 1;
	}
}
Try.

On a semi-related note: Code formatting sucks on these boards. It's high time the forums got an upgrade(some color schemes or something--I'm looking at you, Peds :)).

EDIT: No idea what's posted above me, so try his method first, then mine.
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.

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

Re: Invisible script bug

Post by megazor » April 16th, 2011, 1:11 pm

the problem of max variables is, most likely, your script attempts to set a model on a dead player :-)
so really try my script firstly.

User avatar
<LT>YosemiteSam[NL]
Core Staff
Core Staff
Posts: 2155
Joined: December 7th, 2004, 2:07 am
Location: Netherlands
Contact:

Re: Invisible script bug

Post by <LT>YosemiteSam[NL] » April 16th, 2011, 1:19 pm

megazor wrote:the problem of max variables is, most likely, your script attempts to set a model on a dead player :-)
so really try my script firstly.
aha, ok. I tried yor script m8. But you do not become visible and don't die when getting more than 100 damage.
Gonna try Rezil's script now.

Tried Rezil's cript and when you get over 100 damage you become visible, the health get's set to 0 (=self suicice) and then to 100.
You don't die.
I tried putting the self suicide line after where the health is put to 100 but that doesn't kill the player. The health then gets set to zero.

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: Invisible script bug

Post by Rezil » April 16th, 2011, 2:13 pm

Code: Select all

      if(self.health <= 0)
      {
         self.isInv=false;
         self suicide();
         //self.health = 100; <- remove this part and try again
         break; 
      }
@KS: yeah, but all of the other colors are different than the original php code scheme so using php, while it does color the code, makes it even less readable:

Code: Select all

      if(self.health <= 0)
      {
         self.isInv=false;
         self suicide();
         //self.health = 100; <- remove this part and try again
         break; 
      } 
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.

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

Re: Invisible script bug

Post by megazor » April 16th, 2011, 2:50 pm

try this one

Code: Select all

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

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

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

monitortrig()
{
       trigger=getent("invisible","targetname");
       fx = loadfx ("fx/dust/morpheus_spawnarmorinvis.efx");
       invissound = getent("invisible_sound","targetname");
       for(;;)
       {
         trigger waittill("trigger",user);
         if(!user.isInv)
         {
            user.isInv = true;
            user iprintln("^2 You have invisibility");
                 user thread makeinvisible(45);
               user playsound("invisibility");
            wait 150;
            invissound playsound("spawnsound");
            playfx (fx, (-100,-996,224));
   
        }
}

makeinvisible(time)
{
       	//self endon("disconnect");
       	self endon("killed_player");
       	self endon("spawned");
       	self endon("suicide");
   
       	self detachall();
       	self setmodel("");

       	for (i = 0; i < time; i++)
      	{
                		wait 1;

             		if (self.health <= 0) // caught fatal damage or joined spectators
            		{
                        		
                                        self.health = 100;
                           		self suicide();
             		                return;
        		}
    	}

        	if (self.sessionstate != "playing")
                		return;

        	self.isInv = false;

       	if(!isDefined(self.pers["savedmodel"]))
              		maps\mp\gametypes\_teams::model();
       	else
              		maps\mp\_utility::loadModel(self.pers["savedmodel"]);

       	self iprintln("^2 Invisibility has worn off");  
}

User avatar
<LT>YosemiteSam[NL]
Core Staff
Core Staff
Posts: 2155
Joined: December 7th, 2004, 2:07 am
Location: Netherlands
Contact:

Re: Invisible script bug

Post by <LT>YosemiteSam[NL] » April 16th, 2011, 7:18 pm

Tried both but they don't work.
The megazor script keeps you invisible and your health goes to zero. If you get hit again your health goes into the negatives.

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

Re: Invisible script bug

Post by Drofder2004 » April 16th, 2011, 10:46 pm

Ok, lets try again :P
Change only the "makeInvisble" function from Megaz script.
There are two "wait" calls, commented out, these may be required or may not. Try them without first.

Code: Select all

makeinvisible(time)
{
	//self endon("disconnect");
	self endon("killed_player");
	self endon("spawned");
	self endon("suicide");
	
	self detachall();
	self setmodel("");
	
	for (i = 0; i < time; i++)
	{
		wait 1;
		if (self.health <= 0)
		{
			self makevisible();
			// wait 0.05; // Uncomment line if code does not work and retry
			
			self.health = 100;
			// wait 0.05; // Again, if not working, remove comment and retry
			self suicide();
			return;
		}
	}
	
	self makeVisible();
	self iprintln("^2 Invisibility has worn off"); 
}

makeVisible()
{
	if(!isDefined(self.pers["savedmodel"]))
		maps\mp\gametypes\_teams::model();
	else
		maps\mp\_utility::loadModel(self.pers["savedmodel"]);
		
	self.isInv = false;
}
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

Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests