Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   isGlobalGuild(guildname) (https://forums.graalonline.com/forums/showthread.php?t=86508)

fowlplay4 06-24-2009 04:19 AM

isGlobalGuild(guildname)
 
I figured this would be handy for those who want to have a local guild system that allows people to name their own guilds without conflicting with global ones.

The only issue with it at the moment is that it doesn't auto-update, but that can be fixed if you have a loop check the count every hour or so. I'll leave that part up to you.

After the script pulls all the guild information from the Graal website it's ready to be manipulated, and compared.

Enjoy.

PHP Code:

// Store it in a DB-NPC called GlobalGuilds or something..
function onCreated() {
  
onPopulateDB();
}

function 
onCheckCount() {
  
temp.oldcount this.guildcount;
  
getGuildCount();
  
waitfor(this"CompletedPhase");
  if (
this.guildcount != oldcountonPopulateDB(true);
}

function 
onPopulateDB(silent) {
  
// Clear DB
  
this.clearvars();
  
// Specify temp file
  
this.parsefile "cartridge/testfile.txt";
  
// Get Global Guild Count
  
getGuildCount();
  
waitfor(this"CompletedPhase");
  
// Determine Pages
  
temp.pages ciel(this.guildcount 50);
  
// Begin crawling through pages
  
for (temp.1temp.<= pagestemp.i++) {
    
getGuildList(i);
    
waitfor(this"CompletedPhase");
  }
  
// Get Special Guilds
  
getGuildList("1&type=special");
  
waitfor(this"CompletedPhase");  
  
// Delete temp file
  
deletefile(this.parsefile);
  
this.parsefile "";
  
// Finished
  
if (!silent) echo("Finished Populating Global Guilds DB");
}

function 
ciel(val) {
  if (
val.pos(".") >= 0) {
    
val int(val)+1;
  }
  return 
val;
}

/*
   Determine Active Global Guild Count
*/

function getGuildCount() {
  
temp.link "http://www.graalonline.com/zone/guilds/guildslist?type=OK&sort=created_gmt&order=descending&p=1";
  
temp.req requesturl(link);
  
this.catchevent(temp.req"onReceiveData""onGuildCountData");
}

function 
onGuildCountData(obj) {
  
obj.fulldata.savestring(this.parsefile0);
  
onParseCountData();
}

function 
onParseCountData() {
  
temp.lines.loadlines(this.parsefile);
  
temp.gcstr "<span class=\"values\">";
  for (
temp.llines) {
    if (
l.pos(gcstr) >= 0) {
      
temp.gcount l.substring(l.pos(gcstr)+gcstr.length());
      
temp.gcount gcount.substring(0gcount.pos("<"));
      
this.guildcount gcount;
      break;
    }
  }
  
this.trigger("CompletedPhase""");
}

/*
   Parse Guilds List
*/

function getGuildList(page) {
  
temp.link "http://www.graalonline.com/zone/guilds/guildslist?type=OK&sort=created_gmt&order=descending&p=" page;
  
temp.req requesturl(link);
  
this.catchevent(temp.req"onReceiveData""onGuildListData");
}

function 
onGuildListData(obj) {
  
// Saves it into a parseable format.
  
obj.fulldata.savestring(this.parsefile0);
  
// Parse list
  
onParseListData();
}

function 
onParseListData() {
  
temp.lines.loadlines(this.parsefile);
  for (
temp.llines) {
    
// Check for Guild Tag Line
    
if (l.pos("<td class=\"guildtag\">") >= 0) {
      
// Record Guild Data
      
temp.guildnext true;
      continue;
    }
    else if (
guildnext) {
      
// Unset Boolean
      
temp.guildnext false;
      
// Get Guild ID
      
temp.gid l.substring(l.pos("gid=") + "gid=".length());
      
temp.gid gid.substring(0gid.pos(">")-1);
      
// Get Guild Name
      
temp.gname l.substring(l.pos(">")+1);
      
temp.gname gname.substring(0gname.pos("<"));
      
// Ignore Column Heading
      
if (gname == "Guild") continue;
      
// Record Data
      
onRecordGuild(gidgname);
    }
  }
  
this.trigger("CompletedPhase""");
}

function 
onRecordGuild(gidgname) {
  
this.("guildid_" gid) = gname;
  
this.("guildname_" gname) = gid;
}

public function 
getGuildName(gid) {
  return 
this.("guildid_" gid);
}

public function 
getGuildID(gname) {
  return 
this.("guildname_" gname);
}

public function 
isGlobalGuild(gname) {
  return (
getGuildID(gname) > 0);
}

/*
   Unused but nifty, Check if Guild Exists by Guild ID
*/

function onCheckGuild(temp.gid) {
  
this.sid gid;
  
temp.link http://www.graalonline.com/guilds/viewguild.php?full=0&gid=" @ gid;
  
temp.req requesturl(link);
  
this.catchevent(temp.req"onReceiveData""onGuildData");
}

function 
onGuildData(obj) {
  if (
obj.fulldata.pos("<H3>Invalid Guild ID!</H3>") >= 0) {
    echo(
"Invalid Guild ID");
    return;
  }
  
temp.idstr "<B>Guild Tag</B></TD><TD class=\"aListBL\">";
  
temp.idpos obj.fulldata.pos(idstr);
  
temp.idscp obj.fulldata.substring(idpos+idstr.length());
  
temp.gname idscp.substring(0idscp.pos("</TD></TR>"));
  
onRecordGuild(this.sidgname);



Crow 06-24-2009 12:31 PM

Awesome, just what I need! Thanks for sharing :)

Gambet 06-24-2009 04:08 PM

You sure do enjoy using the link functionality of the new engine (such as the dictionary you released some time ago). :p


Nice work, definitely has some good use.

fowlplay4 06-24-2009 04:32 PM

Quote:

Originally Posted by Gambet (Post 1501403)
You sure do enjoy using the link functionality of the new engine (such as the dictionary you released some time ago). :p

Yeah, when Stefan fails to provide something for awhile I usually go the requesturl route.

[email protected] 06-24-2009 06:43 PM

I think this is quite good actually, nice job ^^

Skyld 06-24-2009 06:56 PM

There is already functionality for checking what a player's rank is in a global guild, you might consider using that. It will return blank values if the player is not a member of that guild. http://forums.graalonline.com/forums...03&postcount=1

fowlplay4 06-24-2009 07:16 PM

Quote:

Originally Posted by Skyld (Post 1501432)
There is already functionality for checking what a player's rank is in a global guild, you might consider using that. It will return blank values if the player is not a member of that guild. http://forums.graalonline.com/forums...03&postcount=1

I played around with it, and have concluded that..

The sendtext method combined with my isGlobalGuild() solution should allow global guilds to be setup to use local guild-based systems. ( Minus the add/remove member features )

Perhaps if there was one for like.. checkguild guildname, then we wouldn't have to use my solution.

Thus, we all profit.

Ronnie 08-13-2009 08:46 PM

Quick Note:
Not sure if this is just an error on my side, but I found out that if you have an already global guild name, and try to check a guild name that isnt the same case as one of the global guilds stored but is the same exact text, It will say it is not a global guild.

I.e say I use btk and see if it is a global guild (The case is actually BTK)
It will return as no it's not a global guild.

fowlplay4 08-13-2009 09:40 PM

Quote:

Originally Posted by Ronnie (Post 1514528)
Quick Note:
Not sure if this is just an error on my side, but I found out that if you have an already global guild name, and try to check a guild name that isnt the same case as one of the global guilds stored but is the same exact text, It will say it is not a global guild.

I.e say I use btk and see if it is a global guild (The case is actually BTK)
It will return as no it's not a global guild.

If don't want it to be case sensitive replace the originals up top with these functions:

PHP Code:

function onRecordGuild(gidgname) {
  
this.("guildid_" gid) = gname.lower();
  
this.("guildname_" gname.lower()) = gid;
}

public function 
getGuildID(gname) {
  return 
this.("guildname_" gname.lower());


You'll have to reset the DB and let it reload the guild lists though.

salesman 08-14-2009 02:36 AM

Would one be able to check the guild's creator/owner through this, too?

Rufus 08-14-2009 03:00 AM

Quote:

Originally Posted by salesman (Post 1514580)
Would one be able to check the guild's creator/owner through this, too?

You check to see who is ranked first using:

Quote:

Originally Posted by Skyld (Post 1501432)
There is already functionality for checking what a player's rank is in a global guild, you might consider using that. It will return blank values if the player is not a member of that guild. http://forums.graalonline.com/forums...03&postcount=1

Couldn't you?

salesman 08-14-2009 03:14 AM

Dunno, I'll check it out whenever I have time. I'm making a local guild system and would like to reserve global guilds for their owners.

papajchris 08-14-2009 03:36 AM

Quote:

Originally Posted by salesman (Post 1514583)
Dunno, I'll check it out whenever I have time. I'm making a local guild system and would like to reserve global guilds for their owners.

What if a local guild is made first but then someone random makes it a global guild?

fowlplay4 08-14-2009 04:34 AM

Quote:

Originally Posted by papajchris (Post 1514585)
What if a local guild is made first but then someone random makes it a global guild?

He'd have write in some script to prevent the random from taking over the local guild which won't be a problem at all.


All times are GMT +2. The time now is 11:23 PM.

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