Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Storing Information with DB-NPCs (https://forums.graalonline.com/forums/showthread.php?t=134263324)

iBeatz 05-23-2011 05:38 PM

Storing Information with DB-NPCs
 
I've been seeing a lot of posts about using DB-NPCs to store information, and I just wanted to know what is meant by this, and how it is accomplished, as it would be quite handy for a few things I've scripted already which require some method of storing information.
Can someone enlighten me?

cbk1994 05-23-2011 06:24 PM

Create a DB NPC named Test.

PHP Code:

Test.foo "bar";
echo(
Test.foo); // echoes bar 

you can right-click the DBNPC and choose "Edit Flags" to see what data is stored in it.

If you're having trouble with DBNPC flags resetting or rolling back (I haven't experienced this in the past few years, but I seldom use DBNPCs for data storage anymore), use:

PHP Code:

Test.trigger("update"); 

This should force it to save.

Keep in mind that you can only access DBNPC data from serverside.

iBeatz 05-23-2011 06:28 PM

So it's basically storing flags in a DB-NPC as opposed to saving them in the server flags?

cbk1994 05-23-2011 06:29 PM

Quote:

Originally Posted by iBeatz (Post 1651220)
So it's basically storing flags in a DB-NPC as opposed to saving them in the server flags?

Yes.

iBeatz 05-23-2011 06:37 PM

Thanks for the enlightenment.

Deas_Voice 05-24-2011 07:20 PM

Quote:

Originally Posted by cbk1994 (Post 1651219)
Create a DB NPC named Test.

PHP Code:

Test.foo "bar";
echo(
Test.foo); // echoes bar 

you can right-click the DBNPC and choose "Edit Flags" to see what data is stored in it.

If you're having trouble with DBNPC flags resetting or rolling back (I haven't experienced this in the past few years, but I seldom use DBNPCs for data storage anymore), use:

PHP Code:

Test.trigger("update"); 

This should force it to save.

Keep in mind that you can only access DBNPC data from serverside.

findNPC( str NPCname ) please :\ (since there could also be a weapon named "Test" with public functions...)

Crow 05-24-2011 08:24 PM

Quote:

Originally Posted by Deas_Voice (Post 1651349)
findNPC( str NPCname ) please :\ (since there could also be a weapon named "Test" with public functions...)

Preference.

fowlplay4 05-24-2011 09:22 PM

Doing this is cool too:

PHP Code:

// In a weapon or class:
function onCreated() {
  
this.db findnpc("Your Favorite DB for this kind of thing");
}

function 
otherCode() {
  
this.db.yeehaw();


or

PHP Code:

// In the DB:
function onInitialized() {
  
onCreated(); // Called when the NPC-Server starts up.
}

function 
onCreated() {
  
myFavDBlol this;
}

// Anywhere on the server-side:
function otherCode() {
  
myFavDBlol.rofl();


Directly referring to the DB's name kind of bottlenecks your script if you plan to release it for others who might want to use a different name for it.


All times are GMT +2. The time now is 12:05 PM.

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