Page 1 of 2
Become invisible .. but how ?
Posted: March 17th, 2011, 8:18 pm
by <LT>YosemiteSam[NL]
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");
}
}
Re: Become invisible .. but how ?
Posted: March 17th, 2011, 8:24 pm
by Drofder2004
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".
Re: Become invisible .. but how ?
Posted: March 17th, 2011, 8:27 pm
by Opel
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");
}
}
Re: Become invisible .. but how ?
Posted: March 17th, 2011, 9:01 pm
by IzNoGoD
Code: Select all
user setmodel("");
user detachall();
or maybe
Not sure about how to undo the effects of the showtoplayer() invisibility
Re: Become invisible .. but how ?
Posted: March 17th, 2011, 9:09 pm
by Rezil
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.
Re: Become invisible .. but how ?
Posted: March 17th, 2011, 10:18 pm
by IzNoGoD
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.
Re: Become invisible .. but how ?
Posted: March 18th, 2011, 12:21 am
by <LT>YosemiteSam[NL]
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
Re: Become invisible .. but how ?
Posted: March 18th, 2011, 7:24 am
by IzNoGoD
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"]);
}
Re: Become invisible .. but how ?
Posted: March 18th, 2011, 9:10 am
by <LT>YosemiteSam[NL]
OK, thx m8. I'll try it when I get home today.
Re: Become invisible .. but how ?
Posted: March 18th, 2011, 3:08 pm
by <LT>YosemiteSam[NL]
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.
Re: Become invisible .. but how ?
Posted: March 18th, 2011, 3:12 pm
by Opel
Try putting self.isInv = false; after iprintlnbold("Invisibility has worn off");
Re: Become invisible .. but how ?
Posted: March 18th, 2011, 4:40 pm
by <LT>YosemiteSam[NL]
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
Re: Become invisible .. but how ?
Posted: March 18th, 2011, 5:17 pm
by IzNoGoD
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...
Re: Become invisible .. but how ?
Posted: March 18th, 2011, 7:12 pm
by <LT>YosemiteSam[NL]
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...
Re: Become invisible .. but how ?
Posted: March 18th, 2011, 7:47 pm
by IzNoGoD
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...