PDA

View Full Version : passing vars -> putnpc


AnarchySquare
06-28-2006, 11:18 PM
I'm trying to pass a varible (account name) through putnpc so that the NPC can have a "master" when it's created. I know a few ghetto ways of doing, like putting a flag in the "master"'s account and having the NPC scan through players in the level to detect that flag, and after using the putnpc doing a triggeraction on the NPC setting the "master"'s account there.

Is there a more effecient way of doing this?

Gambet
06-28-2006, 11:43 PM
If I understand you correctly, you can do something like...


function onCreated()
{
putnpc2(x,y,"join(\"classname\");
this.master = player.account;
");
}


Then in a class npc...


//#CLIENTSIDE
function onPlayerChats()
{
if ( player.chat == "/test" ) {
if ( this.master == player.account ) {
chat = "Hello, Master!";
} else {
chat = "You are not my master!";
}
}
}




It all depends on how you want to do it.

AnarchySquare
06-28-2006, 11:50 PM
That won't work. When the putnpc is placed it has no communication between itself and your account...it's like a blank script...so you can't pass the account.

That's the problem I ran into.

Giltwist2k1
06-29-2006, 12:18 AM
isn't that what playero.account is for?

playero.var variables of the original player object, in generally the player who has invoked the event (e.g. playertouchsme)

Failing that, you could triggeraction it right after you placed it.

Snakeandy7
06-29-2006, 12:18 AM
with(putnpc2(x, y, "join class")){ stuffs in here };

edit to the post below: try it and find out :], it works wonders.

AnarchySquare
06-29-2006, 12:29 AM
with(putnpc2(x, y, "join class")){ stuffs in here };

Wouldn't work exactly like that, but yeah...I get the concept...smart.

Gilt, That wouldn't work. It's not like playertouchsme...it's a fresh NPC with and it's had no communication with another NPC or player.

Actually I don't even think that would work...in order to use with() on an NPC it has to be a) a database NPC or b) you have to have the index of the NPC in combination with npcs[] I do believe...

Yen
06-29-2006, 12:52 AM
Oh, you silly geese.

this.pet = putnpc2(x,y,"join(\"class\");");
this.pet.owner = player.account;

Yen
06-29-2006, 12:52 AM
Oh, and with() can get ANY object.
Any object at all. GUI, NPCs, players, images, ganis, ect.

AnarchySquare
06-29-2006, 04:44 AM
Oh, and with() can get ANY object.
Any object at all. GUI, NPCs, players, images, ganis, ect.


But if you're using with() don't you need to specify what you're searching for? Like with (players[])?


Thanks for the answer.

ApothiX
06-29-2006, 06:12 AM
Wouldn't work exactly like that, but yeah...I get the concept...smart.
It does actually work exactly like that.

Yen
06-29-2006, 04:32 PM
But if you're using with() don't you need to specify what you're searching for? Like with (players[])?


Thanks for the answer.

Well, objects also have names.
You do normally need to do with (players[]), but you could also do something like:
reference = findplayer("Yen");
with (reference) {

}
You can also just put in the name of a GUI object, and it will automatically refer to that GUI.

ApothiX
06-29-2006, 05:31 PM
Well, objects also have names.
You do normally need to do with (players[]), but you could also do something like:
reference = findplayer("Yen");
with (reference) {

}
You can also just put in the name of a GUI object, and it will automatically refer to that GUI.
Just for clarification, it doesn't have to be a variable either. If a function returns an object, you can use the function itself.

with(findPlayer("Yen")) {
player.chat = "Hi thar";
}

You can also do:

this.foo = new TStaticVar();
this.foo.bar = "Wee"
this.foo.baz = "Woo";

with(this.foo) {
echo(bar);
echo(this.baz);
}

would output:
Wee
Woo