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 01-10-2009, 02:04 AM
Seich Seich is offline
Noctorious' NeoHunter
Seich's Avatar
Join Date: Jun 2008
Location: Honduras
Posts: 193
Seich will become famous soon enough
Send a message via MSN to Seich Send a message via Yahoo to Seich
Npc db

Ok, I was working on some random scripts, mainly for practice, and I have come to realize that I have never used a DB NPC, and I have a couple of questions I would love to get an answer to.

How can I use variables when using DB NPCs as flag holders
for example if i wanted to do something like:

PHP Code:
function onCreated(){
   
this.number 1;
}

function 
onPlayerChats(){
   if(
player.chat == "/test"){
      
something findNpc("Test");
      
something. [I want to use this.number in here].test "This is a test";
  }


How do I modify Flags on the DB NPC from itself? for example if i wanted to schedule something, like deleting flags or changing their values, how would I do this? or is there a better way for me to do this?

This might or might not be related to DB NPCs but I would like to know, what's the best way to work with comma separated values like for example in a variable.

something like:
PHP Code:
this.lol "something, goes, in, here, lol"
Because I wanted to store multiple things on a flag separating them with commas...

I have some other questions, but I won't ask them until I am done organizing my ideas.

Thanks,
Seich
Reply With Quote
  #2  
Old 01-10-2009, 04:19 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Well, the multiple flag variables that you're talking about are called arrays and this is the format:

PHP Code:
this.array = {"One""two""three"}; 
and to access the data within the array you would do something like:

PHP Code:
this.chat this.array[1]; 
Which would return "two" because all arrays start with 0.

In a DB NPC (which is similar or exactly the same to a local npc, ie: putnpc2) each NPC has it's own ID which can be used to identify the DB NPC. When you store a flag using a DBNPC it stores to that DB NPC, naturally. You can access it remotely by using
PHP Code:
 findNPC("DB NPC NAME").flag 
So, let's say we want our DBNPC to be specifically used to hold flags and information. This is an easy way we could set it up:

Step one, create the DB NPC, right click it and click edit flags.

Step two, add all of your this. variables in to the DB NPC without the this. prefix.

Step three, access your variables by using findNPC(Obj) or findNPCById(Obj). You can view the DBNPC's ID by displaying the list of DBNPCs in RC. The ID of the DBNPC is aligned on the right side of the text list. Here is my last example to show you how to access variables within the DBNPC.

PHP Code:
temp.npc findNPC("MyDB");
npc.variable1 123;
npc.string1 "hello";
npc.array1 = {"one""five""fifteen"};
npc.flag true
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #3  
Old 01-10-2009, 04:59 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano can only hope to improve
Awesome.

And can those variabled be accessed anytime, anywhere?

ServerSide, Clientside, etc.?

Can I also add NEW variables to it, without rightclicking, edit etc..?
Reply With Quote
  #4  
Old 01-10-2009, 07:21 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 Pelikano View Post
Awesome.

And can those variabled be accessed anytime, anywhere?

ServerSide, Clientside, etc.?

Can I also add NEW variables to it, without rightclicking, edit etc..?
Just on serverside. You can change variables from any script serverside.

PHP Code:
findNPC("MyDB").flag = var; 
__________________
Reply With Quote
  #5  
Old 01-11-2009, 02:46 AM
Seich Seich is offline
Noctorious' NeoHunter
Seich's Avatar
Join Date: Jun 2008
Location: Honduras
Posts: 193
Seich will become famous soon enough
Send a message via MSN to Seich Send a message via Yahoo to Seich
Quote:
Originally Posted by Tigairius View Post
Well, the multiple flag variables that you're talking about are called arrays and this is the format:

PHP Code:
this.array = {"One""two""three"}; 
and to access the data within the array you would do something like:

PHP Code:
this.chat this.array[1]; 
Which would return "two" because all arrays start with 0.

In a DB NPC (which is similar or exactly the same to a local npc, ie: putnpc2) each NPC has it's own ID which can be used to identify the DB NPC. When you store a flag using a DBNPC it stores to that DB NPC, naturally. You can access it remotely by using
PHP Code:
 findNPC("DB NPC NAME").flag 
So, let's say we want our DBNPC to be specifically used to hold flags and information. This is an easy way we could set it up:

Step one, create the DB NPC, right click it and click edit flags.

Step two, add all of your this. variables in to the DB NPC without the this. prefix.

Step three, access your variables by using findNPC(Obj) or findNPCById(Obj). You can view the DBNPC's ID by displaying the list of DBNPCs in RC. The ID of the DBNPC is aligned on the right side of the text list. Here is my last example to show you how to access variables within the DBNPC.

PHP Code:
temp.npc findNPC("MyDB");
npc.variable1 123;
npc.string1 "hello";
npc.array1 = {"one""five""fifteen"};
npc.flag true

Thank you, that's great, I didn't know that I could store arrays in flags, well I simply never tried that.

I still have one question, how can I use a dynamic flag name? like on my example with the number or, that isn't possible?
Reply With Quote
  #6  
Old 01-11-2009, 05:18 AM
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 Seich View Post
Thank you, that's great, I didn't know that I could store arrays in flags, well I simply never tried that.

I still have one question, how can I use a dynamic flag name? like on my example with the number or, that isn't possible?
PHP Code:
this.(@ "foo_" s) = var;
(@ 
"this." "_foo") = var;
findNPC("NPC").(@ "foo_" s) = var;

// You can also use makevar, but the above way is generally preferred:

makevar("this.foo_" s) = var; 
__________________
Reply With Quote
  #7  
Old 01-11-2009, 05:48 AM
Seich Seich is offline
Noctorious' NeoHunter
Seich's Avatar
Join Date: Jun 2008
Location: Honduras
Posts: 193
Seich will become famous soon enough
Send a message via MSN to Seich Send a message via Yahoo to Seich
That's Perfect, thanks Chris.
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 06:40 PM.


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