ID:39543
 
NOTE: Guilds were removed. This snippet will no longer work.

Since this uses world.Export(), it is recommended you check little guilds as possible (as well as use the simpler version, since very little will need the complex one) as it takes time to obtain the information!

Required knowledge:
Lists
Bit Flags [This is UnknownPerson's old article on it - the latest that was on BYONDscape no longer exists :( ] (heh, found my old dead one here)

client.IsGuildMember() Snippet:

Simple one (returns 1 if in any of the guild or 0 if not, comments only in complex):
client/proc/IsGuildMember()
if(!src.IsByondMember())return 0
for(var/ A in list("BYONDAction","BYONDAnime","BYONDCasual","BYONDRPG","BYONDStrategy"))
var/http[] = world.Export("http://www.byond.com/members/ [A]?command=view_guild_members")
if(!http) continue
if(findtext(file2text(http["CONTENT"]),src.key))
return 1
return 0



Complex one (returns bit value of specific guilds the client is in)
client/proc/IsGuildMember()                     //  Checks if the client belongs to certain groups/a group
if(!src.IsByondMember())return 0 // If not a BYOND member, 0 is returned
. = 0 // Making the default returned value 0
var/i=0 // The following defined values in the list are guilds that are going to be checked if a person belongs in it or not. The less amount there is, the faster calling this procedure will be
for(var/A in list("BYONDAction","BYONDAnime","BYONDCasual","BYONDRPG","BYONDStrategy"))
i++ // The value of i is increased by one
// The following retrieves the website data
var/http[] = world.Export("http://www.byond.com/members/[A]?command=view_guild_members")
if(!http) continue // If that page doesn't exist, it'll skip and continue on
if(findtext(file2text(http["CONTENT"]),src.key)) // If the member's key is found
.|= 1<<(i-1) // The default value is "OR" bitshifted by the value of i, according to the list value position
/* The following is a DEBUG statement that I had to use, if you are interested in knowing what is currently happening
world << "Found in [A], i = [i] (Bit: [1<<(i-1)]), . = [.]"
else world << "<b>NOT</b> Found in [A], i = [i] (Bit: [1<<(i-1)]), . = [.]"
*/

// . is automatically returned here (with either return, return . or nothing at all). The value returned will be a bit value of all guilds that the person is present for, depending the position of the guild in the list


Testing Snippet:
mob/verb/Check() world<<usr.client.IsGuildMember()



To understand more about what the heck happened, read the required knowledge section and world.Export() in the DM Reference.

Replace the list in the snippet (for/var A in list(...)) with the guild names that you want it to look in.

It is recommended that, if you use this for certain parts in your game, make a tmp variable on the client which you can refer back to it whenever you want for that session:
client
var/GuildMember

New() // Called when a client (player) logs in
GuildMember = src.IsGuildMember()


For the complex version, the value returned contains the bit value for all the guild the client is present for:

list("X","Z","A","B")

If the client is in X, Z, B; the returned value is 11 (1+2+8).
If the person is in all, it'll be 15 (1+2+4+8)
If the person is in A, the returned value is 4 (the position it is in the list - in bit value)
If the person is in none of those guild, it is 0

If the list is larger than 16 (well, 17)... it won't work correctly but I doubt you'll need to check that many guilds.
Wow, you totally overcomplicated that.
Foomer wrote:
Wow, you totally overcomplicated that.

True enough, just did a simpler return 1 or 0 version.
Well, I made my own version and, after simplifying it, I overcomplicated it some more.

I made it so that it will let you search a guild for by reference to any mob, client or key name, and I made it so that it will only find exact keys, not partial keys.

I also made it so, if you want, you can have it return the member's rank.

Unfortunately I can't post it here, so I'll have to find somewhere else to put it.

EDIT: Here: http://www.byond.com/developer/forum/?id=619970
They're going to include a built in proc to do this for us sometime sooner or later, I believe.

Good temporary though.