Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Communication between a Class and DB NPC? (https://forums.graalonline.com/forums/showthread.php?t=134270541)

maximus_asinus 08-28-2017 02:26 AM

Communication between a Class and DB NPC?
 
Goal: For this example each time a player says "debug" the database is triggered which it in turn triggers back to the class and updates every NPC that is joined to it.

So this is where I started which works.
PHP Code:

function onPlayerChats() {
  if (
player.chat == "debug") {
    
DATABASE.triggerdatabase(); // database has the public function 
  
}


My Problem: Now I want the database to trigger back to the class in order to update it. I've tried sending it back a public function but without an identifier the database can't find the class. For whatever reason level NPCs and classes can't have identifiers, and you can't use the class name as an identifier. I've tried to use triggerAction. I've also tried to join the database to the class, but the database catches the update and applies it to itself and doesn't update the other classes.

So bottom line is I need help again. Can what I'm trying to do be accomplished?

Kirko 08-28-2017 04:10 AM

One way to do it is to use trigger()

PHP Code:

// DbNpc "Kirko"
public function doSomething(cool)
{
  
this.trigger("onDidSomething"temp.cool);
}

// lvel npc
function onCreated()
{
  
Kirko.doSomething("Test");
}

function 
Kirko.onDidSomething(cool)
{
  
this.chat temp.cool// Will beset to "test"


or you can pass the npc just by using "this"
PHP Code:

// Dbnpc
public function doSomething(npc)
{
  
temp.npc.chat "I did something";
}

// level npc
function onCreated()
{
  
Kirko.doSomething(this);


orrrr
PHP Code:

// dbnpc
public function doSomething()
{
  
temp.callstack getCallStack();
  
temp.npc temp.callstack[temp.callstack.size() - 1].scriptcallobject;
  
temp.npc.chat "test";
}

// level npc
function onCreated()
{
  
Kirko.doSomething(); // npc chat now set to "Test"



maximus_asinus 08-28-2017 08:31 PM

Very interesting stuff happening there. I wasn't aware of the trigger command. It will be useful to know for the future.

I did have trouble with the 1st and 3rd example. The 1st example wouldn't execute Kirko.doSomething("Test") outside of the onCreated() function. The 3rd example just didn't work period. The 2nd method worked but didn't have the effect I was looking for.

So I'm still looking to find a way to update every NPC that has joined a specific class. These methods seem to only impact the specific NPC that triggers the doSomething command.

MysticalDragon 08-29-2017 01:32 AM

There is other methods

example

PHP Code:

// Database NPC name = Kirko 

const CLASS = "kirko_test";
public function 
update(temp.lvl)  {
  for(
temp.npcfindlevel(temp.lvl).npcs)  {
    if (!
temp.npc.isinclass(CLASS)) continue;
    
//Update all Classes that are joined to kirko_test
    
temp.npc.trigger("Update"this);
  }


// Class name = kirko_test
// level npc
function onCreated()  { 
  
Kirko.update(this.level.name); 
}  

public function 
onUpdate() {
  
this.chat "Database Updated me";




All times are GMT +2. The time now is 09:06 PM.

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