Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   passing vars -> putnpc (https://forums.graalonline.com/forums/showthread.php?t=67014)

AnarchySquare 06-28-2006 10:18 PM

passing vars -> putnpc
 
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 10:43 PM

If I understand you correctly, you can do something like...

NPC Code:

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



Then in a class npc...

NPC Code:

//#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 10: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-28-2006 11:18 PM

isn't that what playero.account is for?

Quote:

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-28-2006 11:18 PM

with(putnpc2(x, y, "join class")){ stuffs in here };

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

AnarchySquare 06-28-2006 11:29 PM

Quote:

Originally Posted by Snakeandy7
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.

[Edit] 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...[/Edit]

Yen 06-28-2006 11:52 PM

Oh, you silly geese.

PHP Code:

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


Yen 06-28-2006 11:52 PM

Oh, and with() can get ANY object.
Any object at all. GUI, NPCs, players, images, ganis, ect.

AnarchySquare 06-29-2006 03:44 AM

Quote:

Originally Posted by Yen
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 05:12 AM

Quote:

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

It does actually work exactly like that.

Yen 06-29-2006 03:32 PM

Quote:

Originally Posted by AnarchySquare
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:
PHP Code:

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 04:31 PM

Quote:

Originally Posted by Yen
Well, objects also have names.
You do normally need to do with (players[]), but you could also do something like:
PHP Code:

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.

PHP Code:

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


You can also do:

PHP Code:

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

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


would output:
PHP Code:

Wee
Woo 



All times are GMT +2. The time now is 11:01 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.