Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   putnpc2 problem (https://forums.graalonline.com/forums/showthread.php?t=75058)

Chompy 07-02-2007 05:50 PM

putnpc2 problem
 
PHP Code:

public function dropItem(id)
{
  
temp."object_item";

  
with(findplayer("Chompy")) {
    
with(putnpc2(3030"this.join(\"" "\" );")) {
      ...
    }
  }


I'm doing this from a weapon npc..
Any reason why this won't work?

Or do I have to change the npcs array (with(npcs[npcs.size() - 1]))?

Or is there any other methods?

Novo 07-02-2007 06:12 PM

It would be nice to know what doesn't work.

I'm personally not a fan about double-with's... Nor am I a fan of 'temp.n' mysteriously becoming 'n'.

It could be on a gmap, and showing at the top-left corner... As for the npcs array trick, that was before putnpc2 returned an object.

How I usually do it is:

PHP Code:

public function dropItemid )
  {
  
temp."object_item";

  
temp.obj putnpc23030"" );
  
temp.obj.jointemp.);
  
// ...
  



Chompy 07-02-2007 06:43 PM

Quote:

Originally Posted by Novo (Post 1325044)
It would be nice to know what doesn't work.

I'm personally not a fan about double-with's... Nor am I a fan of 'temp.n' mysteriously becoming 'n'.

It could be on a gmap, and showing at the top-left corner... As for the npcs array trick, that was before putnpc2 returned an object.

How I usually do it is:

PHP Code:

public function dropItemid )
  {
  
temp."object_item";

  
temp.obj putnpc23030"" );
  
temp.obj.jointemp.);
  
// ...
  



Oh yeah, the error was it would just return an error in rc.. :(

And, with your example I could do
PHP Code:

public function dropItem(id)
{
  
temp.obj putnpc2(3030"");
  
temp.obj.join("class name");
  
temp.obj.id id;


and then I would be able to do this.id in the class and return the id gived to the function dropItem?

Edit: Doesn't work in a WNPC :(

Novo 07-02-2007 08:48 PM

Quote:

Originally Posted by Chompy (Post 1325051)
Oh yeah, the error was it would just return an error in rc.. :(

And, with your example I could do
PHP Code:

public function dropItem(id)
{
  
temp.obj putnpc2(3030"");
  
temp.obj.join("class name");
  
temp.obj.id id;


and then I would be able to do this.id in the class and return the id gived to the function dropItem?

Edit: Doesn't work in a WNPC :(

id is a reserved variable. You can't overwrite it. ( Or is that npcid? or name? I'm not sure anymore. )

Inverness 07-02-2007 09:38 PM

id is a static variable in TServerPlayer and TServerNPC.
name is static in TGraalVar (everything).

Chompy 07-02-2007 11:11 PM

But, I still have the problem..
Inver told me to do level.putnpc2()

When using that no errors occured in rc, but it wouldn't put the class in the level

Problem solved:

two methods works: (Thanks Inver for the level.putnpc2())

PHP Code:

temp.obj findplayer(this.acct).level.putnpc2(3030"");
temp.obj.join("classname");
temp.obj.var = "foo"

or

PHP Code:

with(findplayer(this.acct)) {
  
temp.obj this.level.putnpc2(3030"");
  
temp.obj.join("classname");
  
temp.obj.var = "foo";



zokemon 07-02-2007 11:38 PM

Quote:

Originally Posted by Chompy (Post 1325116)
When using that no errors occured in rc, but it wouldn't put the class in the level

You can't "put a class in a level" (well, I guess you could do level.join(class) but that isn't what we are talking about). When you use join() you are only telling the script to append what is in the class to the current script. Of course it will overwrite function definitions and stuff but in essence, that is all that it is doing.

Classes are not objects.

Chompy 07-02-2007 11:54 PM

Quote:

Originally Posted by zokemon (Post 1325127)
You can't "put a class in a level" (well, I guess you could do level.join(class) but that isn't what we are talking about). When you use join() you are only telling the script to append what is in the class to the current script. Of course it will overwrite function definitions and stuff but in essence, that is all that it is doing.

Classes are not objects.

Hmm, you're right, I think I meant something more the lines of
"It didn't put the npc that had the class joined to itself at the given coords"

but it's fixed now :o

zokemon 07-02-2007 11:59 PM

Quote:

Originally Posted by Chompy (Post 1325132)
Hmm, you're right, I think I meant something more the lines of
"It didn't put the npc that had the class joined to itself at the given coords"

but it's fixed now :o

Alright ;)


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

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