Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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:49 PM.


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