Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-24-2009, 04:19 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
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);

__________________
Quote:
Reply With Quote
  #2  
Old 06-24-2009, 12:31 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
Awesome, just what I need! Thanks for sharing
Reply With Quote
  #3  
Old 06-24-2009, 04:08 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
You sure do enjoy using the link functionality of the new engine (such as the dictionary you released some time ago).


Nice work, definitely has some good use.
Reply With Quote
  #4  
Old 06-24-2009, 04:32 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 Gambet View Post
You sure do enjoy using the link functionality of the new engine (such as the dictionary you released some time ago).
Yeah, when Stefan fails to provide something for awhile I usually go the requesturl route.
__________________
Quote:
Reply With Quote
  #5  
Old 06-24-2009, 06:43 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
I think this is quite good actually, nice job
Reply With Quote
  #6  
Old 06-24-2009, 06:56 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
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
__________________
Skyld
Reply With Quote
  #7  
Old 06-24-2009, 07:16 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 Skyld View Post
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.
__________________
Quote:
Reply With Quote
  #8  
Old 08-13-2009, 08:46 PM
Ronnie Ronnie is offline
Registered User
Join Date: Jun 2008
Location: Nj, USA
Posts: 48
Ronnie is on a distinguished road
Send a message via AIM to Ronnie
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.
Reply With Quote
  #9  
Old 08-13-2009, 09:40 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 Ronnie View Post
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.
__________________
Quote:
Reply With Quote
  #10  
Old 08-14-2009, 02:36 AM
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
Would one be able to check the guild's creator/owner through this, too?
Reply With Quote
  #11  
Old 08-14-2009, 03:00 AM
Rufus Rufus is offline
Registered User
Join Date: Jun 2004
Location: United Kingdom
Posts: 4,698
Rufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud of
Quote:
Originally Posted by salesman View Post
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 View Post
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?
__________________
Quote:
Originally Posted by Loriel View Post
Seriously, you have ****-all for content and you're not exactly pulling in new developer talent, angling for prestigious titles should be your last concern.
Reply With Quote
  #12  
Old 08-14-2009, 03:14 AM
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
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.
Reply With Quote
  #13  
Old 08-14-2009, 03:36 AM
papajchris papajchris is offline
Zeus Condero
papajchris's Avatar
Join Date: Jan 2006
Location: Michigan
Posts: 1,600
papajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to behold
Quote:
Originally Posted by salesman View Post
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?
__________________
Reply With Quote
  #14  
Old 08-14-2009, 04:34 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
Quote:
Originally Posted by papajchris View Post
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.
__________________
Quote:
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 01:09 AM.


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