Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-23-2011, 05:38 PM
iBeatz iBeatz is offline
Kavan
iBeatz's Avatar
Join Date: Dec 2010
Location: Northern Ireland, UK
Posts: 154
iBeatz will become famous soon enough
Send a message via Yahoo to iBeatz
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?
__________________

Intelligence without ambition is like a bird without wings.

Reply With Quote
  #2  
Old 05-23-2011, 06:24 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #3  
Old 05-23-2011, 06:28 PM
iBeatz iBeatz is offline
Kavan
iBeatz's Avatar
Join Date: Dec 2010
Location: Northern Ireland, UK
Posts: 154
iBeatz will become famous soon enough
Send a message via Yahoo to iBeatz
So it's basically storing flags in a DB-NPC as opposed to saving them in the server flags?
__________________

Intelligence without ambition is like a bird without wings.

Reply With Quote
  #4  
Old 05-23-2011, 06:29 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by iBeatz View Post
So it's basically storing flags in a DB-NPC as opposed to saving them in the server flags?
Yes.
__________________
Reply With Quote
  #5  
Old 05-23-2011, 06:37 PM
iBeatz iBeatz is offline
Kavan
iBeatz's Avatar
Join Date: Dec 2010
Location: Northern Ireland, UK
Posts: 154
iBeatz will become famous soon enough
Send a message via Yahoo to iBeatz
Thanks for the enlightenment.
__________________

Intelligence without ambition is like a bird without wings.

Reply With Quote
  #6  
Old 05-24-2011, 07:20 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Quote:
Originally Posted by cbk1994 View Post
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...)
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #7  
Old 05-24-2011, 08:24 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Deas_Voice View Post
findNPC( str NPCname ) please (since there could also be a weapon named "Test" with public functions...)
Preference.
__________________
Reply With Quote
  #8  
Old 05-24-2011, 09:22 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:13 AM.


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