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 08-23-2009, 05:57 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
Array Search

Ok, nother problem. So out of scripting.
I can't by the slightest remember how to search an array and find out if a var is in it. Example. Have an array of account names and want to do and if account name is in array, then allow.
__________________
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 08-23-2009, 06:02 AM
oo_jazz_oo oo_jazz_oo is offline
Jazz teh Awesome
oo_jazz_oo's Avatar
Join Date: Jul 2006
Location: California
Posts: 596
oo_jazz_oo is a jewel in the roughoo_jazz_oo is a jewel in the rough
Send a message via MSN to oo_jazz_oo
PHP Code:
if (player.account in this.array)
  
//Your script here 
That?
__________________

Reply With Quote
  #3  
Old 08-23-2009, 06: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
Also remember you can do this for caps-insensitive searching...

PHP Code:
if (array.index(@ player.account) > (- 1)) {
 
// stuff

array.index(obj) returns the index that the object is located at within the array.
__________________
Reply With Quote
  #4  
Old 08-23-2009, 06:24 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
those b them, ty.
__________________
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
  #5  
Old 08-23-2009, 08:08 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Note that if you're working with a really, really big dataset, it may be faster to use something like a scripted binary search (I think there might be one in the code gallery, if not I could write one).
Reply With Quote
  #6  
Old 08-23-2009, 10:05 AM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Searching Arrays, like REALLY searching them is possible in PHP, not sure if it works in GS2
Reply With Quote
  #7  
Old 08-23-2009, 11:39 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
Its only going to be 10 accounts max probably, ever.
__________________
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
  #8  
Old 08-23-2009, 11:47 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
Another question arises, how do i add to a server array? i know how to set, serverr.whatever = {whatever, whatever} but if I want to add and delete from that, how should I go about it?
__________________
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 08-23-2009, 12:10 PM
Riot Riot is offline
Delteria Management
Join Date: Nov 2003
Location: Seminole County, Florida
Posts: 280
Riot is on a distinguished road
Quote:
Originally Posted by sssssssssss View Post
Another question arises, how do i add to a server array? i know how to set, serverr.whatever = {whatever, whatever} but if I want to add and delete from that, how should I go about it?
Take a look at: http://graal.net/index.php/Creation/...ject_functions

You'll find these functions which may be of use to you:
obj.add(obj2) - adds an object to an array
obj.delete(index) - deletes the object from an array at the specified index
obj.remove(obj2) - removes the first instance of the specified object from the array
obj.replace(index,obj2) - replace the object at the specified index
obj.insert(index,obj2) - insert the object at the index without replacing other indexes
Reply With Quote
  #10  
Old 08-23-2009, 12:16 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 Riot View Post
Take a look at: http://graal.net/index.php/Creation/...ject_functions

You'll find these functions which may be of use to you:
obj.add(obj2) - adds an object to an array
obj.delete(index) - deletes the object from an array at the specified index
obj.remove(obj2) - removes the first instance of the specified object from the array
obj.replace(index,obj2) - replace the object at the specified index
obj.insert(index,obj2) - insert the object at the index without replacing other indexes
and if u want to know how they work,
go to wiki.graal.us!
__________________
.
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
  #11  
Old 08-23-2009, 05:25 PM
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 Deas_Voice View Post
and if u want to know how they work,
go to wiki.graal.us!
He explained how they worked
__________________
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
  #12  
Old 08-24-2009, 09: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
thanks for the site! completely forgot about it.
__________________
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
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 03:45 AM.


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