Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-12-2009, 08:04 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Search array name

Is there a way to search and pull up all array names that would start with certain letters? Like there are the array Graalmember1, Graalmember2, Graalmember3, Cutfish, Bombs.
And I want to show the arrays that start with Graal in a gui?
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #2  
Old 09-12-2009, 08:15 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
Not a built-in way, but it's easy to script

PHP Code:
function searchArray(array, start) {
  
temp.new = null;
  
  for (
temp.: array) {
    if (
a.starts(start)) {
      new.
add(a);
    }
  }

  return new;

__________________
Reply With Quote
  #3  
Old 09-12-2009, 08:23 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
I leave the array part as array correct? being that there are many different array names?
and can call that function like:
searchArray(array, start);

correct?

bleh, to be more specific.
searching through the arrays ingraal1, ingraal2, ingraal3, graal4, cuddlefish, bombs, arrows, penguins

to pull up only the ones that have "ingraal" in the array name, then display the number after "ingraal".
so it finds ingraal1, ingraal2, ingraal3, then displays
1
2
3
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #4  
Old 09-12-2009, 10:20 PM
Cloven Cloven is offline
Delteria
Cloven's Avatar
Join Date: Dec 2006
Location: Florida, United States
Posts: 542
Cloven has a spectacular aura about
Send a message via AIM to Cloven
Hint: using .substring
Reply With Quote
  #5  
Old 09-12-2009, 10:32 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
Something like this I guess

PHP Code:
function searchArray(array, start) {
  
temp.new = null;
  
  for (
temp.: array) {
    if (
a.starts(start)) {
      new.
add(a.substring(start.length()));
    }
  }

  return new;

__________________
Reply With Quote
  #6  
Old 09-12-2009, 10:34 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Can you explain that though please? and how to call it correctly? I also dont wannt just copy, i wanna understand
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #7  
Old 09-12-2009, 10:41 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by sssssssssss View Post
Can you explain that though please? and how to call it correctly? I also dont wannt just copy, i wanna understand
Examples:

PHP Code:
echo(searchArray({ "ingraal1""ingraal2""ingraal3""graal4""cuddlefish""bombs""arrows""penguins" }, "ingraal"));

this.nameOfMyArray = { "fooBar1""barFoo1""baz""fooBar2" };
echo(
searchArray(this.nameOfMyArray"foo")); 
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #8  
Old 09-12-2009, 10:55 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
the problem is, that doesnt seem it will work. Im not trying to search for values in an array. Ill set it up more clear.
Array
ingraal1 {hi,how,he}
ingraal2 {k,m,c,b,d}
ingraal3 {op,asd,g,a}
cuddlefish {2,5,213,2,0}
bombs {sjd,23,6,a}
arrows {s,d,e,gf,a}

Trying to search the NAME of the array, not the names inside the array.
So i want to pull out the array names that have "ingraal" in them, which would pull ingraal1, ingraal2, ingraal3. Then, i was wanting to print out what is after "ingraal" so it would show up
1
2
3
from the "ingraal(1-3)" array names.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #9  
Old 09-12-2009, 10:59 PM
Cloven Cloven is offline
Delteria
Cloven's Avatar
Join Date: Dec 2006
Location: Florida, United States
Posts: 542
Cloven has a spectacular aura about
Send a message via AIM to Cloven
I meant that .substring functions essentially as #e did in gscript in this case. You can use that to compare clusters of letters to entries found within your array and then extract desired information from the matches.

It is .substring(start,len) after all.
Reply With Quote
  #10  
Old 09-12-2009, 11:12 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
That completely went over my head. Please explain in more simple words
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #11  
Old 09-12-2009, 11:16 PM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
if you have an array called this.arr, this.arr.name will return arr.

However, I can't see any useful implementation of what you're asking for since searching through the arrays to see what begins with "ingraal" requires you already knowing exactly where they are and searching each one manually.

If you were to pass an array of arrays to the function and check through all the arrays in there, this.collectedarrays[0].name returns nothing.
Reply With Quote
  #12  
Old 09-12-2009, 11:24 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Ive been just using examples. What im actually doing is i have guilds register on a server to have and give rights to members for certain things.
when it creates the array it creates it as
registeredguildsGUILDNAME={acct name, acct name}
so i need to search through the array names that are registeredguilds then find the GUILDNAME, so i can print out the entire list of the GUILDNAMES that are registered on my server in a gui.

any other ideas on how to go about that, please let me know.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #13  
Old 09-12-2009, 11:32 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
I'd recommend using TStaticVar's.

PHP Code:
this.registeredguilds = new TStaticVar();
this.registeredguilds.GUILDNAME1.members = { "acc1""acc2""acc3" };
this.registeredguilds.GUILDNAME2.members = { "acc1""acc2""acc3" };
this.registeredguilds.GUILDNAME3.members = { "acc1""acc2""acc3" };

// to read all guilds, use...
this.registeredguilds.getDynamicVarNames()
// to read guild members of a string defined guild, use...
temp.guildName "foobar";
this.registeredguilds.(@temp.guildName).members 
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #14  
Old 09-13-2009, 12:37 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
can that be used with server.var?
rather not use this.var b/c if the level is updated every single guild has to reregister.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #15  
Old 09-13-2009, 12:46 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
use a database NPC
Reply With Quote
  #16  
Old 09-13-2009, 12:54 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Been a while since i had a playerworld, it was right when npc servers came out, how you set up a db npc
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #17  
Old 09-13-2009, 01:25 AM
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
Click the Green Dragon DB-NPC button, then click Add in the NPCs window that pops up, fill in the appropriate information in the next window that pops up and click Apply.
__________________
Quote:
Reply With Quote
  #18  
Old 09-13-2009, 01:59 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
The level i add it on to start, is that the level it works on?
I dont want it to work everywhere.
If not, of if i guess, how do i "call" it in a level npc?
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #19  
Old 09-13-2009, 02:03 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Quote:
Originally Posted by sssssssssss View Post
The level i add it on to start, is that the level it works on?
I dont want it to work everywhere.
If not, of if i guess, how do i "call" it in a level npc?
it is accessible anywhere serverside, but to call it from a level NPC you can do something like

findnpc(dbnpcname).function()

or if you plan on calling the NPC a few times, store the npc in a var (cont = findnpc(dbnpcname) )
Reply With Quote
  #20  
Old 09-13-2009, 02:18 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
I read some stuff on graal.net, but still dont really understand this.
If i have this script in a db npc, how is the results going to show up on my gui in a level?

actually worded better:
how am i going to take this.vars from the db npc, and then pick out parts of the name, then show it up on a gui in a level npc.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #21  
Old 09-13-2009, 03:10 AM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Quote:
Originally Posted by fowlplay4 View Post
Green Dragon
BIG GREEN MONSTER AHHHH!
Quote:
Originally Posted by sssssssssss View Post
The level i add it on to start, is that the level it works on?
I dont want it to work everywhere.
If not, of if i guess, how do i "call" it in a level npc?
It works kind of like a level NPC except it can be accessed through findNPC("Database Name") serverside in any script.
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #22  
Old 09-13-2009, 03:35 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
so i can go
PHP Code:
findNPC("Database Name"
then pretend like the entire script of the DB npc is in the level npc.

so i could do
PHP Code:
say2(this.registeredguildsSDE); 
in the level npc after referring to the db npc and it would work?
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #23  
Old 09-13-2009, 03:43 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Actually, doesnt seem to be working. heres my script:

PHP Code:
function onCreated() {
  
this.setshape(13232);
  
this.registeredguilds = new TStaticVar();
}
function 
onActionRegistersdeServer(leader){
  
makevar("this.registeredguilds." player.guild ".member") = {leader};
  
say2("Guild " player.guild " is registered #b
  by " 
leader "!");
}
function 
onActionAddMemRegGuildServer(guildzzmember){
  
this.(@"registeredguilds." guildzz ".member").add(member);
  
say2("Rights of " member " have been added #b
  to " 
guildzz "!");
}
function 
onActionDelMemRegGuildServer(guildzremove){
  
this.(@"registeredguilds." guildz ".member").remove(remove);
  
say2("Rights of " remove " have been removed #b
  from " 
guildz "!");
}
function 
onActionSetTagServer(tag){
  
player.guild tag;
}

//#CLIENTSIDE
function onCreated() {
  
this.setshape(13232);
}

function 
onPlayerChats() {
  if (
player.chat == "registerguild"){
    if (
player.guild == ""){
      
say2("Put on guild tag first!");
    }else{
      
temp.checkregistry this.(@"registeredguilds." player.guild ".member");
      if (!(
checkregistry == "")){
        
say2("This guild is already registered");
      }else{
        
temp.owner player.account;
        
triggeraction(this.0.5this.0.5"RegistersdeServer"temp.owner);
      }
    }
  }
  if (
player.chat.starts("addmemberaccess")){
    if (
player.guild == ""){
      
say2("Put on guild tag first!");
    }else{
      
temp.checkregistry this.(@"registeredguilds." player.guild ".member");
      if (!(
player.account in checkregistry)){
        
say2("You do not have rights!");
      }else{
        
temp.addmemg player.guild;
        if (
player.guild == temp.addmemg){
          
temp.addmem player.chat.tokenize()[1];
          
triggeraction(this.0.5this.0.5"AddMemRegGuildServer"temp.addmemgtemp.addmem);
        }
      }
    }
  }
  if (
player.chat.starts("removememberaccess"))
    {
    if (
player.guild == ""){
      
say2("Put on guild tag first!");
    }else{
      
temp.checkregistry this.(@"registeredguilds." player.guild ".member");
      if (!(
player.account in checkregistry)){
        
say2("You do not have rights!");
      }else{
        
temp.delmemg player.guild;
        if (
player.guild == temp.delmemg){
          
temp.del player.chat.tokenize()[1];
          
triggeraction(this.0.5this.0.5"DelMemRegGuildServer"temp.delmemgtemp.del);
        }
      }
    }
  }
  if (
player.chat.starts("settag")){
    
temp.tag player.chat.tokenize()[1];
    
triggeraction(this.0.5this.0.5"SetTagServer"temp.tag);

  }

ignore the settag stuff, just to test other guilds registry besides my own. The starting level is not where the level npc is at, didnt think that should matter.

And i used this on a level npc:
PHP Code:
function onCreated() {
  
this.setshape(13232);
findNPC("db_registeredguilds")

}

//#CLIENTSIDE
function onCreated() {
  
this.setshape(13232);
}
function 
onPlayerTouchsMe(){
  
temp.checkregistry this.(@"registeredguilds." player.guild ".members");
  if (
player.account in checkregistry){
    
this.chat "YO";
  }

produces no results. when i used serverr.var all this worked fine.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #24  
Old 09-13-2009, 05:21 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
Why are you still using clientside for chat commands?
__________________
Reply With Quote
  #25  
Old 09-13-2009, 05:33 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
I did take it out, thats actually a bit old, same script just minus //#CLIENTSIDE
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #26  
Old 09-13-2009, 05:40 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
simply finding the NPC on it's own in your script will not do anything.

You need to have a var point to it after returning it.

Also, you cannot read this.vars from server to client like that.

My suggestions are to move nearly everything out of the clientside, store the few things you want accessible by GUI into the DB NPC's attribute array, copy the attribute array to the level NPC (although a weapon would probably be better for guild GUI related things), then display on clientside.

Example -

PHP Code:
function onCreated()
{
  
this.cont findnpc("mydbnpc");
  
copyAttrs();
}

function 
copyAttrs()
{
  for(
temp.030i++)
  {
    
this.attr[i] = this.cont.attr[i];
  }
}
//#CLIENTSIDE
function onCreated()
{
  
//GUI stuff here, use attrs as you please to sort things out...

Reply With Quote
  #27  
Old 09-13-2009, 06:12 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
The thing is, player has to chat to set it. Do i include that in the npc db too? see my script and what its doing. thats why i used a serverr.flag, its less of a pain, but if TStaticVar() is the only way to do what i need to do, compared to the script i posed before that one, then i guess i have to.
I guess Im lost enough to ask someone to show me, at the least, a full example. :/

The thing is, if you read the code i posted, its not just gui. That entire code sets a register server.flag for each guild registered, so playerchats and everything is involved. On a seperate npc i was using a gui to list the guilds that were registered. Im lost, and just getting confused even more now.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...



Last edited by sssssssssss; 09-13-2009 at 07:31 AM..
Reply With Quote
  #28  
Old 09-13-2009, 07:52 PM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
I worked with Cyril today, and got something working. He's currently working on interfacing with a GUI, so he might come up with some more questions. Here are the scripts, for future reference:

DB NPC (db_registeredguilds)
PHP Code:
function onInitialized() {
  
onCreated();
}

function 
onCreated() {
  if (
this.guilds.type() != 2) {
    
this.guilds = new TStaticVar();
  }
}

public function 
RegistersdeServer() {
  if (
player.guild == "") {
    
say2("Put on guild tag first!");
    return;
  }
  if (
this.guilds.(@player.guild) == null) {
    
this.guilds.(@player.guild) = {player.account};
    
say2("Guild " player.guild " is registered #bby " player.account "!");
  }
  else {
    
say2("This guild is already registered");
  }
}

public function 
AddMemRegGuildServer(member) {
  if (
player.guild == "") {
    
say2("Put on guild tag first!");
    return;
  }
  
  if (
hasAccess()) {
    if (!(
temp.member in this.guilds.(@player.guild))) {
      
this.guilds.(@player.guild).add(temp.member);
      
say2(temp.member "#badded to#b" player.guild);
    }
    else {
      
say2(temp.member "#bis already in#b" player.guild);
    }
  }
  else {
    
say2("You do not have rights!");
  }
}

public function 
DelMemRegGuildServer(member) {
  if (
player.guild == "") {
    
say2("Put on guild tag first!");
    return;
  }
  
  if (
hasAccess()) {
    
this.guilds.(@player.guild).remove(temp.member);
    
say2(temp.member "#bremoved from#b" player.guild);
  }
  else {
    
say2("You do not have rights!");
  }
}

public function 
hasAccess() {
  return (
player.account in this.guilds.(@player.guild));
}

public function 
getGuildList() {
  return 
this.guilds.getdynamicvarnames();

Level Script:
PHP Code:
function onCreated() {
  
this.db findnpc("db_registeredguilds");
}

function 
onPlayerChats() {
  if (
player.chat == "registerguild") {
    
this.db.RegistersdeServer();
  }
  if (
player.chat.starts("addmemberaccess")) {
    
this.db.AddMemRegGuildServer(player.chat.tokenize()[1]);
  }
  if (
player.chat.starts("removememberaccess")) {
    
this.db.DelMemRegGuildServer(player.chat.tokenize()[1]);
  }

There's a million other ways to do this, but I also wanted to show him how public functions worked. We'll leave SQL for another day .
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #29  
Old 09-13-2009, 08:16 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
Why are you using findNPC? There's no need to, you can simply reference it as an object.
__________________
Reply With Quote
  #30  
Old 09-13-2009, 08:50 PM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by cbk1994 View Post
Why are you using findNPC? There's no need to, you can simply reference it as an object.
I like doing it that way, so that if the DB changes for whatever reason, I just have to edit it in one place.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #31  
Old 09-13-2009, 08:58 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 cbk1994 View Post
Why are you using findNPC? There's no need to, you can simply reference it as an object.
Preference.
Reply With Quote
  #32  
Old 09-13-2009, 08:58 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 napo_p2p View Post
I like doing it that way, so that if the DB changes for whatever reason, I just have to edit it in one place.
Just do

PHP Code:
this.db db_registeredguilds
__________________
Reply With Quote
  #33  
Old 09-13-2009, 09:24 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
I personally don't trust DB-NPCs enough to do that.
__________________
Quote:
Reply With Quote
  #34  
Old 09-14-2009, 04:30 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by cbk1994 View Post
Why are you using findNPC? There's no need to, you can simply reference it as an object.
Why do you have to bring up that in every single thread and push your opinion down everyone else's throat? It is personal preference, and nothing you can say about it changes that.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #35  
Old 09-14-2009, 04:48 PM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Wouldn't findNPC() be less efficient because you're calling a function to get the object instead of just referencing it by name? Especially when people use findNPC(npcname) over and over again instead of assigning the npc to some variable.

I have no idea, but it just seems like it would be.
Reply With Quote
  #36  
Old 09-14-2009, 06:56 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
Quote:
Originally Posted by salesman View Post
Wouldn't findNPC() be less efficient because you're calling a function to get the object instead of just referencing it by name? Especially when people use findNPC(npcname) over and over again instead of assigning the npc to some variable.

I have no idea, but it just seems like it would be.
I wondered this as well so..

PHP Code:
function benchmark() {
  
// Iterations
  
temp.max 100000;
  
// Direct
  
temp.init timevar2;
  for (
temp.0temp.temp.maxtemp.i++) {
    
db_test.variable temp.i;
  }
  echo(
"dNPC" SPC timevar2 temp.init);
  
// findNPC
  
temp.init timevar2;
  for (
temp.0temp.temp.maxtemp.i++) {
    
findnpc("db_test").variable temp.i;
  }
  echo(
"fNPC" SPC timevar2 temp.init);
  
// Variable findNPC
  
temp.init timevar2;
  
temp.db findnpc("db_test");
  for (
temp.0temp.temp.maxtemp.i++) {
    
temp.db.variable temp.i;
  }
  echo(
"vNPC" SPC timevar2 temp.init);

Results:

NPC Code:

JerretNPC: benchmark()
dNPC 0.069311141 seconds
fNPC 0.10556817 seconds
vNPC 0.061683177 seconds



Specifying findNPC every time appears to take twice as long (in my benchmark anyway) compared to variable and direct methods.
__________________
Quote:
Reply With Quote
  #37  
Old 09-14-2009, 07:59 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by fowlplay4 View Post
Specifying findNPC every time appears to take twice as long (in my benchmark anyway) compared to variable and direct methods.
According to Stefan, it's similar to how it works when you check boolean values.

This:

PHP Code:
function onCreated() {
  
temp.bool true;
  if (
bool == true) {
    
//Stuff
  
}

Is supposed to take longer to process than this:

PHP Code:
function onCreated() {
  
temp.bool true;
  if (bool) {
    
//Stuff
  
}

Reply With Quote
  #38  
Old 09-14-2009, 08:27 PM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Quote:
Originally Posted by sssssssssss View Post
Ive been just using examples. What im actually doing is i have guilds register on a server to have and give rights to members for certain things.
when it creates the array it creates it as
registeredguildsGUILDNAME={acct name, acct name}
so i need to search through the array names that are registeredguilds then find the GUILDNAME, so i can print out the entire list of the GUILDNAMES that are registered on my server in a gui.

any other ideas on how to go about that, please let me know.
for starters, don't use examples when you're asking for help. If you want help, ask what you want help for.

Like I said in a post previously, what you are requesting assistance for seems dubious at best. I don't believe there is any way to collect all the server variables at once by function, and since there isn't, you would have to know the names of the variables before hand. That being the case, you aren't really yielding any benefit by doubly checking them to see if registeredguilds is a part of the name.

I don't know how to explain this any better.

If there is a way to return all the server flags at once, as was said, you could iterate through that array and check if the array at whatever index in the for loop's name starts with or contains whatever string (in this case, regsistered guilds).
Reply With Quote
  #39  
Old 09-14-2009, 08:57 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
temp.servervars = getstringkeys("server.");

may work.
Reply With Quote
  #40  
Old 09-14-2009, 09:18 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by Gambet View Post
According to Stefan, it's similar to how it works when you check boolean values.

This:

PHP Code:
function onCreated() {
  
temp.bool true;
  if (
bool == true) {
    
//Stuff
  
}

Is supposed to take longer to process than this:

PHP Code:
function onCreated() {
  
temp.bool true;
  if (bool) {
    
//Stuff
  
}

This is, in fact, because an if () statement is eventually evaluating down to true.
PHP Code:
if (bool) 
... is saying "Is bool true?", whereas
PHP Code:
if (bool == true
... is saying "Is bool == true true?" (two evaluations instead of one). The difference is not huge though and it is not worth complaining about.
__________________
Skyld
Reply With Quote
Reply


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 08:01 PM.


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