Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Npc db (https://forums.graalonline.com/forums/showthread.php?t=83590)

Seich 01-10-2009 02:04 AM

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

Tigairius 01-10-2009 04:19 AM

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


Pelikano 01-10-2009 04:59 PM

Awesome.

And can those variabled be accessed anytime, anywhere?

ServerSide, Clientside, etc.?

Can I also add NEW variables to it, without rightclicking, edit etc..?

cbk1994 01-10-2009 07:21 PM

Quote:

Originally Posted by Pelikano (Post 1455940)
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; 


Seich 01-11-2009 02:46 AM

Quote:

Originally Posted by Tigairius (Post 1455877)
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?

cbk1994 01-11-2009 05:18 AM

Quote:

Originally Posted by Seich (Post 1456114)
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; 


Seich 01-11-2009 05:48 AM

That's Perfect, thanks Chris.


All times are GMT +2. The time now is 02:15 AM.

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