Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   PutNPC to DBNPC communication (https://forums.graalonline.com/forums/showthread.php?t=84996)

Tyhm 04-05-2009 06:26 AM

PutNPC to DBNPC communication
 
How would that be done? I tried having the putNPCs findNPC the DBNPC, but I don't think they're quite reaching...could someone provide a code sample? I mean, I could probably get the desired results with server strings, but eww...

putNPC:
on created, send the DBNPC some sorta ID.
on hit or whatever, right before destroying itself, let the DBNPC know

DBNPC:
When a request comes in from a player's weapon let's say, should be able to find and manipulate the putNPCs in its list no matter where they are. Like, the player says "NPC #6587, move to the right", and it should despite the DBNPC and the player being in different levels from the putNPC.

Or am I going about my ultimate goal in the silliest way possible, and the server side of a weapon can Easily search all NPCs on the server, compile a list, and tell them what to do? :-P

oo_jazz_oo 04-05-2009 06:56 AM

Well, in the DBNPC you can store the classes object. And manipulate it from there...

Like, in the class, you could have.
PHP Code:

function onCreated()
  
findNPC("npc_name").testvariable this

and in the dbnpc have
PHP Code:

function onManipulateClass()
{
  
with(this.testvariable)
    
this.chat "[test]";



Tyhm 04-05-2009 07:23 AM

Hmm, and npc_name is the dbNPC's name? I'll have to give that a try.

salesman 04-05-2009 08:13 AM

If you're trying to do what I think you're trying to do, I would probably do this:

In the class that is being joined via putnpc's
PHP Code:

//Store the NPC's name along with some way to indentify it in a database
function onCreated() {
  (@ 
"DBNPC_NAME").(@ this.level.name "_" this.id) = this.name;


In a weapon:
PHP Code:

function getNPCNPC_LEVELNPC_ID ) {
  
//Get the NPC's name
  
temp.npcname = (@ "DBNPC_NAME").(@ NPC_LEVEL "_" NPC_ID);
  
  
//Get the actual NPC object
  
temp.npc findNPCnpcname );

  
//Bam
  
npc.DoServerSideStuff();



Tyhm 04-05-2009 10:04 AM

Goodness! While elucidating, Jazz's solution works quite well as it stands; I think I have enough code now to lump together some sort of "Find all NPCs in the database, show an arrow pointing to the closest such NPC, tell that NPC to run the "stand still" script" code...

Skyld 04-05-2009 06:09 PM

I did, in fact, write an example implementation of this a while ago on the wiki: http://wiki.graal.net/index.php/Crea..._Communication

Inverness 04-05-2009 08:33 PM

You do not need to use findnpc or the (@ "var") syntax if the NPC or weapon name is standard.

Here is my implementation for the class, just showing how the NPC is registered:
PHP Code:

function onCreated() {
  
dbnpc_name.register(this);


In the dbnpc:
PHP Code:

public function register(npcobj) {
  
this.(@ "n" npcobj.id) = npcobj;


I think it is better to be using functions in this case.

Tyhm 04-05-2009 10:05 PM

Huh. I tried using functions in the first place and they didn't seem to findNPC each other...

Inverness 04-05-2009 11:49 PM

Quote:

Originally Posted by Tyhm (Post 1481329)
Huh. I tried using functions in the first place and they didn't seem to findNPC each other...

I don't know what you mean by "didn't seem to findNPC each other."

Tyhm 04-06-2009 02:23 AM

I mean I used to have it set up such that
the putnpc
function oncreated(){
//etc
ZombieControl.addMob(this);
//etc
}

ZombieControl
public function addMob(param1){
this.mobs.add(param1);
}

Maybe I didn't have it as a public function, maybe that was the whole problem. Pretty sure I did, but I've been wrong before. ^^;

[email protected] 04-06-2009 09:45 AM

Hrm... a mob? Maybe you don't actually need a database and to just trigger the other monsters in the mob, if that makes any sense?

Tyhm 04-06-2009 11:21 AM

The mob's just one NPC that displays multiple items in its area, and the trouble with triggering is telling NPCs in other levels what to do.

[email protected] 04-06-2009 07:39 PM

Hmm you could just do something like this in the class script

HTML Code:

//NPC.addMember(this); to call it
public function addMember(id) {
  this.moblist.add(id);
}

public function onCallMob() {
  for (temp.npc: this.moblist) temp.npc.trigger("YourTrigger", "");
}

public function onYourTrigger() {
  //Hell Yeah!
}


Inverness 04-06-2009 09:39 PM

Quote:

Originally Posted by Tyhm (Post 1481388)
I mean I used to have it set up such that
the putnpc
function oncreated(){
//etc
ZombieControl.addMob(this);
//etc
}

ZombieControl
public function addMob(param1){
this.mobs.add(param1);
}

Maybe I didn't have it as a public function, maybe that was the whole problem. Pretty sure I did, but I've been wrong before. ^^;

That looks fine to me, also make sure you check if it is already in the list.


All times are GMT +2. The time now is 10:23 PM.

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