Become invisible .. but how ?

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

Moderator: Core Staff

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

Become invisible .. but how ?

Post by <LT>YosemiteSam[NL] » March 17th, 2011, 8:18 pm

I know you can become invisible in CoD2 (hide and seek mod). But how do they script that.
I wrote this script but it gives an error saying "Self is not an entity" when I touch the trigger. Does someone know how to do this ?

Code: Select all

thread invisible();

}
invisible()
{
self endon ( "disconnect" );
self endon( "death" ); 
trigger = getent("invisible","targetname");
while(1)
{
trigger waittill ("trigger");
self hide();
self iPrintlnBold("You are Invisible");
wait 5;
self show();
self iPrintlnBold("Invisibility has warn off");
}
}

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

Re: Become invisible .. but how ?

Post by Drofder2004 » March 17th, 2011, 8:24 pm

At a guess, you need to hide the model (or remove it).

Its been a while, but try and find how the body is created (self.model and self.head, or something similar).
And then just change the model to "undefined".
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
Opel
CJ Fan
CJ Fan
Posts: 188
Joined: September 15th, 2008, 12:28 pm
Location: Scotland

Re: Become invisible .. but how ?

Post by Opel » March 17th, 2011, 8:27 pm

I'm not exactly sure but that should work by making the trigger waittill have user but i think i may be thinking about something completely different.

Code: Select all


invisible()
{
trigger = getent("invisible","targetname");
while(1)
{
trigger waittill ("trigger", user);
user hide();
user iPrintlnBold("You are Invisible");
wait 5;
user show();
user iPrintlnBold("Invisibility has warn off");
}
}

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

Re: Become invisible .. but how ?

Post by IzNoGoD » March 17th, 2011, 9:01 pm

Code: Select all

user setmodel("");
user detachall();
or maybe

Code: Select all

user showtoplayer(user);
Not sure about how to undo the effects of the showtoplayer() invisibility
LMGTFY!

Its not a glitch... Its the future!

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: Become invisible .. but how ?

Post by Rezil » March 17th, 2011, 9:09 pm

Here's how I did it, and it's the best way to make someone invisible for me:

Code: Select all

makeInvisible(arg)
{
	if(!isdefined(self.isInv)) self.isInv= false;
	
	if((arg) && (!self.isInv))
	{
		self detachall();
		self setmodel("");
		self.isInv= true;
	}
	else
	{
		if(self.pers["team"]=="allies") 
		{
			self setmodel(level.american_xmodel);
			self attach(level.german_xmodel_head, "", true);
			self attach(self.hatModel, "", true);
		}
		else if(self.pers["team"]=="axis") 
		{
			self setmodel(level.german_xmodel);
			self attach(level.german_xmodel_head, "", true);
			self attach(self.hatModel, "", true);
		}
		self.isInv= false;
	}
}
You need to call makeInvisible(true) on a player to make him invisible and then when you want him visible again, set makeInvisible to false. Now you do need to edit these four global variables:

Code: Select all

	level.german_xmodel = "xmodel/playerbody_german_normandy01";
	level.german_xmodel_head = "xmodel/head_german_normandy_josh";
	
	level.american_xmodel = "xmodel/playerbody_default";         
	level.american_xmodel_head = "xmodel/head_us_ranger_preston";
The presets here are for the default american model and the default german model. You might need to alter this if you're using different allies. Other than that, this code is pretty much fool proof.
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.

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

Re: Become invisible .. but how ?

Post by IzNoGoD » March 17th, 2011, 10:18 pm

Code: Select all

makeInvisible(arg)
{
	if(!isdefined(self.isInv)) self.isInv= false;
	
	if((arg) && (!self.isInv))
	{
		self detachall();
		self setmodel("");
		self.isInv= true;
	}
	else
	{
		if(!isdefined(self.pers["savedmodel"]))
			maps\mp\gametypes\_teams::model();
		else
			maps\mp\_utility::loadModel(self.pers["savedmodel"]);
		self.isInv= false;
	}
}
Using a bit of stock code might help a lot, in order to make the code more understandable and more compatible.
GL with it

PS no need to change any vars.
Just make sure you set self.isInv=false; on every spawn, and on every connect too, just to be on the safe side.
LMGTFY!

Its not a glitch... Its the future!

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

Re: Become invisible .. but how ?

Post by <LT>YosemiteSam[NL] » March 18th, 2011, 12:21 am

Ok , so let me get this straight;

This is my code in my main gsc;

Code: Select all

thread invisible();

}
invisible()
{
trigger = getent("invisible","targetname");
while(1)
{
trigger waittill ("trigger");
thread maps\mp\invisible_true::main();
self iPrintlnBold("You are Invisible");
wait 5;
thread maps\mp\invisible_false::main();
self iPrintlnBold("Invisibility has warn off");
}
}
And for invisible true;

Code: Select all

main()
{
thread makeinvisible(true);
}
makeInvisible(arg)
{
   if(!isdefined(self.isInv)) self.isInv= false;
   
   if((true) && (!self.isInv))
   {
      self detachall();
      self setmodel("");
      self.isInv= true;
   }
   else
   {
      if(!isdefined(self.pers["savedmodel"]))
         maps\mp\gametypes\_teams::model();
      else
         maps\mp\_utility::loadModel(self.pers["savedmodel"]);
      self.isInv= false;
   }
}
I'm not new to scripting but I'm not good at it :)

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

Re: Become invisible .. but how ?

Post by IzNoGoD » March 18th, 2011, 7:24 am

Code: Select all

init() //only call init();
{
	thread waitforconnect();
	thread invisible();
}

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;
	}
}



invisible()
{
	trigger=getent("invisible","targetname");
	for(;;)
	{
		self waittill("trigger",user);
		if(!user.isInv)
			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
	}
}

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

	wait time;

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

Its not a glitch... Its the future!

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

Re: Become invisible .. but how ?

Post by <LT>YosemiteSam[NL] » March 18th, 2011, 9:10 am

OK, thx m8. I'll try it when I get home today.

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

Re: Become invisible .. but how ?

Post by <LT>YosemiteSam[NL] » March 18th, 2011, 3:08 pm

I tested the code but the trigger doesn't work when using the "self waittill" code.

Code: Select all

invisible()
{
   trigger=getent("invisible","targetname");
   for(;;)
   {
     trigger waittill("trigger",user);
	iprintlnbold("you are invisible");
	if(!user.isInv)
         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;
   
   iprintlnbold("Invisibility has worn off");
   
   if(!isdefined(self.pers["savedmodel"]))
      maps\mp\gametypes\_teams::model();
   else
      maps\mp\_utility::loadModel(self.pers["savedmodel"]);
}
I've changed the self into trigger but than it doesn't do anything (the player should be invisible to the player itself aswell right?).
It shows the "you are invisible" text I added and after the 5 seconds waittime it shows the "invisibilty has worn off" text. But the second text shows up only once. I mean when I trigger again the "you are invisible" text comes up but not the other text.

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

Re: Become invisible .. but how ?

Post by Opel » March 18th, 2011, 3:12 pm

Try putting self.isInv = false; after iprintlnbold("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: Become invisible .. but how ?

Post by <LT>YosemiteSam[NL] » March 18th, 2011, 4:40 pm

Opel wrote:Try putting self.isInv = false; after iprintlnbold("Invisibility has worn off");
Tried it, doesn't work. :(

The map building is going faster than my scripting :-)
You do not have the required permissions to view the files attached to this post.

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

Re: Become invisible .. but how ?

Post by IzNoGoD » March 18th, 2011, 5:17 pm

Sory, previous script was buggy indeed. Should indeed have made the code with the 2 proposed changes included. Will look at it once more when im at my pc, scripting from an ipod toich is kinda a bad idea...
LMGTFY!

Its not a glitch... Its the future!

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

Re: Become invisible .. but how ?

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

IzNoGoD wrote:Sory, previous script was buggy indeed. Should indeed have made the code with the 2 proposed changes included. Will look at it once more when im at my pc, scripting from an ipod toich is kinda a bad idea...
:)

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

Re: Become invisible .. but how ?

Post by IzNoGoD » March 18th, 2011, 7:47 pm

I think I know whats bugging you: What happens if you start it with developer 1? Does it error on some "cannot cast undefined to bool" error?

Then you should use my whole code, which i included below, with all fixes etc already in it.

Code: Select all

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


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

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"]);
}
If it was indeed the "undefined to bool" error, the script was unable to set the user to invisible, as it didnt know wheter the user already was invisible or not...
LMGTFY!

Its not a glitch... Its the future!

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests