//--------------------------------------------------
//RANKS
//--------------------------------------------------

$Ranks::MinPoints[0] = 0;
$Ranks::NewRank[0] = "Private";
$Ranks::NewItems[0] = "No New Items";
$Ranks::Number[0] = 1;
$Ranks::MinPoints[1] = 25;
$Ranks::NewRank[1] = "Private Grade I";
$Ranks::NewItems[1] = "No New Items";
$Ranks::Number[1] = 2;
$Ranks::MinPoints[2] = 50;
$Ranks::NewRank[2] = "Private Grade II";
$Ranks::NewItems[2] = "No New Items";
$Ranks::Number[2] = 3;
$Ranks::MinPoints[3] = 100;
$Ranks::NewRank[3] = "Private Grade III";
$Ranks::NewItems[3] = "No New Items";
$Ranks::Number[3] = 4;
$Ranks::MinPoints[4] = 150;
$Ranks::NewRank[4] = "Gunnary Private";
$Ranks::NewItems[4] = "MP12 SMG";
$Ranks::Number[4] = 5;
$Ranks::MinPoints[5] = 200;
$Ranks::NewRank[5] = "Gunnary Private Grade I";
$Ranks::NewItems[5] = "No New Items";
$Ranks::Number[5] = 6;
$Ranks::MinPoints[6] = 250;
$Ranks::NewRank[6] = "Gunnary Private Grade II";
$Ranks::NewItems[6] = "No New Items";
$Ranks::Number[6] = 7;
$Ranks::MinPoints[7] = 300;
$Ranks::NewRank[7] = "Gunnary Private Grade III";
$Ranks::NewItems[7] = "Dual MP12 Uzis";
$Ranks::Number[7] = 8;
$Ranks::MinPoints[8] = 400;
$Ranks::NewRank[8] = "Corporal";
$Ranks::NewItems[8] = "Commando Class Armor";
$Ranks::Number[8] = 9;
$Ranks::MinPoints[9] = 500;
$Ranks::NewRank[9] = "Corporal Grade I";
$Ranks::NewItems[9] = "No New Items";
$Ranks::Number[9] = 10;
$Ranks::MinPoints[10] = 600;
$Ranks::NewRank[10] = "Corporal Grade II";
$Ranks::NewItems[10] = "Flame Thrower";
$Ranks::Number[10] = 11;
$Ranks::MinPoints[11] = 700;
$Ranks::NewRank[11] = "Corporal Grade III";
$Ranks::NewItems[11] = "Bazooka";
$Ranks::Number[11] = 12;
$Ranks::MinPoints[12] = 900;
$Ranks::NewRank[12] = "Corporal Grade IV";
$Ranks::NewItems[12] = "Shot gun";
$Ranks::Number[12] = 13;
$Ranks::MinPoints[13] = 1150;
$Ranks::NewRank[13] = "Sergant";
$Ranks::NewItems[13] = "Support Class Armor";
$Ranks::Number[13] = 14;
$Ranks::MinPoints[14] = 1400;
$Ranks::NewRank[14] = "Sergant Grade I";
$Ranks::NewItems[14] = "No New Items";
$Ranks::Number[14] = 15;
$Ranks::MinPoints[15] = 1700;
$Ranks::NewRank[15] = "Sergant Grade II";
$Ranks::NewItems[15] = "Centaur Pistols";
$Ranks::Number[15] = 16;
$Ranks::MinPoints[16] = 2000;
$Ranks::NewRank[16] = "Sergant Grade III";
$Ranks::NewItems[16] = "No New Items";
$Ranks::Number[16] = 17;
$Ranks::MinPoints[17] = 2500;
$Ranks::NewRank[17] = "Sergant Grade IV";
$Ranks::NewItems[17] = "Sniper Rifle";
$Ranks::Number[17] = 18;
$Ranks::MinPoints[18] = 3000;
$Ranks::NewRank[18] = "Gunnary Sergant";
$Ranks::NewItems[18] = "Anti-Vehicle Missile Launcher";
$Ranks::Number[18] = 19;
$Ranks::MinPoints[19] = 3500;
$Ranks::NewRank[19] = "Gunnary Sergant Grade I";
$Ranks::NewItems[19] = "No New Items";
$Ranks::Number[19] = 20;
$Ranks::MinPoints[20] = 4000;
$Ranks::NewRank[20] = "Gunnary Sergant Grade II";
$Ranks::NewItems[20] = "No New Items";
$Ranks::Number[20] = 21;
$Ranks::MinPoints[21] = 4500;
$Ranks::NewRank[21] = "Gunnary Sergant Grade III";
$Ranks::NewItems[21] = "No New Items";
$Ranks::Number[21] = 22;
$Ranks::MinPoints[22] = 5000;
$Ranks::NewRank[22] = "Gunnary Sergant Grade IV";
$Ranks::NewItems[22] = "No New Items";
$Ranks::Number[22] = 23;
$Ranks::MinPoints[23] = 6000;
$Ranks::NewRank[23] = "Lieutenant";
$Ranks::NewItems[23] = "M32";
$Ranks::Number[23] = 24;
$Ranks::MinPoints[24] = 7000;
$Ranks::NewRank[24] = "Lieutenant Grade I";
$Ranks::NewItems[24] = "No New Items";
$Ranks::Number[24] = 25;
$Ranks::MinPoints[25] = 8000;
$Ranks::NewRank[25] = "Lieutenant Grade II";
$Ranks::NewItems[25] = "M32 w/ RPG";
$Ranks::Number[25] = 26;
$Ranks::MinPoints[26] = 9000;
$Ranks::NewRank[26] = "Lieutenant Grade III";
$Ranks::NewItems[26] = "No New Items";
$Ranks::Number[26] = 27;
$Ranks::MinPoints[27] = 10000;
$Ranks::NewRank[27] = "Lieutenant Grade IV";
$Ranks::NewItems[27] = "No New Items";
$Ranks::Number[27] = 28;
$Ranks::MinPoints[28] = 12500;
$Ranks::NewRank[28] = "Captain";
$Ranks::NewItems[28] = "Portible Chaingun Turret";
$Ranks::Number[28] = 29;
$Ranks::MinPoints[29] = 15000;
$Ranks::NewRank[29] = "Captain Grade I";
$Ranks::NewItems[29] = "Rotational Shot Gun";
$Ranks::Number[29] = 30;
$Ranks::MinPoints[30] = 20000;
$Ranks::NewRank[30] = "Captain Grade II";
$Ranks::NewItems[30] = "Incindinary Grenade";
$Ranks::Number[30] = 31;
$Ranks::MinPoints[31] = 25000;
$Ranks::NewRank[31] = "Captain Grade III";
$Ranks::NewItems[31] = "ZH7C8 Napalm Cannon, Nalcidic Armor";
$Ranks::Number[31] = 32;
$Ranks::MinPoints[32] = 30000;
$Ranks::NewRank[32] = "Major";
$Ranks::NewItems[32] = "Spec-Ops Class Armor, RX-12(SG), Portible Gauss Cannon";
$Ranks::Number[32] = 33;
$Ranks::MinPoints[33] = 37500;
$Ranks::NewRank[33] = "Major Grade I";
$Ranks::NewItems[33] = "RX-12(GL)";
$Ranks::Number[33] = 34;
$Ranks::MinPoints[34] = 45000;
$Ranks::NewRank[34] = "Major Grade II";
$Ranks::NewItems[34] = "Targeting Beacon (AC-130 Spectre Ops)";
$Ranks::Number[34] = 35;
$Ranks::MinPoints[35] = 52500;
$Ranks::NewRank[35] = "Major Grade III";
$Ranks::NewItems[35] = "Silenced USP-45 Pistol";
$Ranks::Number[35] = 36;
$Ranks::MinPoints[36] = 60000;
$Ranks::NewRank[36] = "Lieutenant Colonel";
$Ranks::NewItems[36] = "AT6 Rocket Launcher";
$Ranks::Number[36] = 37;
$Ranks::MinPoints[37] = 70000;
$Ranks::NewRank[37] = "Lieutenant Colonel Grade I";
$Ranks::NewItems[37] = "No New Items";
$Ranks::Number[37] = 38;
$Ranks::MinPoints[38] = 80000;
$Ranks::NewRank[38] = "Lieutenant Colonel Grade II";
$Ranks::NewItems[38] = "";
$Ranks::Number[38] = 39;
$Ranks::MinPoints[39] = 90000;
$Ranks::NewRank[39] = "Lieutenant Colonel Grade III";
$Ranks::NewItems[39] = "ES-73 Pulse Phaser Pistol / Scorcher (Need Fire Extinguisher Medal)";
$Ranks::Number[39] = 40;
$Ranks::MinPoints[40] = 100000;
$Ranks::NewRank[40] = "Colonel";
$Ranks::NewItems[40] = "Blitz Rifle";
$Ranks::Number[40] = 41;
$Ranks::MinPoints[41] = 125000;
$Ranks::NewRank[41] = "Colonel Grade I";
$Ranks::NewItems[41] = "Phantom Spiker SMG";
$Ranks::Number[41] = 42;
$Ranks::MinPoints[42] = 150000;
$Ranks::NewRank[42] = "Colonel Grade II";
$Ranks::NewItems[42] = "EX-73 Pulse Chaingun";
$Ranks::Number[42] = 43;
$Ranks::MinPoints[43] = 200000;
$Ranks::NewRank[43] = "Brigadier";
$Ranks::NewItems[43] = "RSA Scout Class Armor, Desert Eagle Pistol";
$Ranks::Number[43] = 44;
$Ranks::MinPoints[44] = 275000;
$Ranks::NewRank[44] = "Brigadier Grade I";
$Ranks::NewItems[44] = "RTM-85C Photon Laser Cannon";
$Ranks::Number[44] = 45;
$Ranks::MinPoints[45] = 350000;
$Ranks::NewRank[45] = "Brigadier Grade II";
$Ranks::NewItems[45] = "RSA Laser Rifle";
$Ranks::Number[45] = 46;
$Ranks::MinPoints[46] = 500000;
$Ranks::NewRank[46] = "General";
$Ranks::NewItems[46] = "Plasma Beam Cannon, Targeting Beacon (Missile Storm), Enemia Rocket Cannon";
$Ranks::Number[46] = 47;
$Ranks::MinPoints[47] = 650000;
$Ranks::NewRank[47] = "General 3 Stars";
$Ranks::NewItems[47] = "Targeting Beacon (Artillery Barrage)";
$Ranks::Number[47] = 48;
$Ranks::MinPoints[48] = 1000000;
$Ranks::NewRank[48] = "General 5 Stars";
$Ranks::NewItems[48] = "Volatge Cannon";
$Ranks::Number[48] = 49;
$Ranks::MinPoints[49] = 2500000;
$Ranks::NewRank[49] = "Commander In Chief";
$Ranks::NewItems[49] = "ALSWP";
$Ranks::Number[49] = 50;
exec( "prefs/Squads.cs" );
$canRecalcTop5 = 1;

function ccCheckStats(%client, %args){
   if(%args $= ""){
	if(%client.GUID $= ""){
	   messageClient(%client, 'MsgClient', "\c2Please wait a minute for your stats to load");
    return 1;
	}
	%name = %client.NameBase;
	%Rank = $Rank::Rank[%client.GUID];
	%Stats = $Rank::XP[%client.GUID];
    %GUIDber = $Rank::Num[%client.GUID];
	for(%i = 49; %i >= 0; %i--){
	   if($Rank::XP[%client.GUID] >= $Ranks::MinPoints[%i]){
		%nextrank = $Ranks::NewRank[(%i + 1)];
		%nextrankXP = $Ranks::MinPoints[(%i + 1)];
		%i = 0;
	   }
	}
    if($Rank::XP[%client.GUID] >= $Ranks::MinPoints[49]) {
    messageClient(%client, 'MsgClient', "\c2Your Rank is "@%Rank@"("@%GUIDber+1@")[MAX], You Currently Have "@%stats@" XP.");
    return 1;
    }
    else {
	messageClient(%client, 'MsgClient', "\c2Your Rank is "@%Rank@"("@%GUIDber+1@"), You Currently Have "@%stats@" XP your next rank is "@%nextrank@" and you need "@(%nextrankXP - %stats)@" XP.");
    return 1;
    }
   }
   else{
      %nametotest=getword(%args,0);
      %target=plnametocid(%nametotest);
      if (%target==0) {
           messageclient(%sender, 'MsgClient', '\c2No such player.');
           return 1;
      }
		if(%target.GUID $= ""){
		   messageClient(%client, 'MsgClient', "\c2Please wait a minute for this persons stats to load");
           return 1;
		}
		%Rank = $Rank::Rank[%target.GUID];
		%Stats = $Rank::XP[%target.GUID];
        %GUIDber = $Rank::Num[%target.GUID];
		messageClient(%client, 'MsgClient', "\c2"@%target.namebase@"'s Rank is "@%Rank@"("@%GUIDber+1@") and "@%target.namebase@"'s XP is "@%stats@".");
        return 1;
	}
   }

function findTopRanks() {
   DeleteFile(""@$TWM::RanksDirectory@"/TopRanks.TWMSave");
   for(%x = 1; %x <= $Rank::numplayers; %x++){
      %file = ""@$TWM::RanksDirectory@"/"@$Rank::AssignedGUID[%x]@"/Saved.TWMSave";
      exec(%file);
   }
   %noabove = 10000000;   //Highest Rank Level XP
   for(%i = 1; %i <= $Rank::numplayers; %i++){
	  for(%j = 1; %j <= $Rank::numplayers; %j++) {
         %XPA = $Rank::XP[$Rank::AssignedGUID[%j]];
	     if((%XPA >= %highest || %highest $= "") && (%XPA < %noabove) && %XPA > 0){
            %highest = %XPA;
            %player = $Rank::AssignedGUID[%j];
         }
      }
      $Rank::Top[%i] = $Rank::Name[%player];
      $Rank::TopXP[%i] = $Rank::XP[%player];
      $Rank::TopRank[%i] = $Rank::Rank[%player];
      $Rank::TopPlPosition[%player] = %i;
      echo("Top Rank Position "@%i@": "@$Rank::Name[%player]@", XP: "@$Rank::XP[%player]@", Rank: "@$Rank::Rank[%player]@"");
	  %noabove = %highest;
	  %highest = "";
      //File stuff here
      //Start by Deleting
      new fileobject(BaseToLoad);
      BaseToLoad.openforAppend(""@$TWM::RanksDirectory@"/TopRanks.TWMSave");
      BaseToLoad.writeline("// Rank Position "@%i@"");
      BaseToLoad.writeline("$Rank::Top["@%i@"] = \""@$Rank::Name[%player]@"\";");
      BaseToLoad.writeline("$Rank::TopXP["@%i@"] = "@$Rank::XP[%player]@";");
      BaseToLoad.writeline("$Rank::TopRank["@%i@"] = \""@$Rank::Rank[%player]@"\";");
      BaseToLoad.writeline("$Rank::TopRankGUID["@%i@"] = "@%player@";");
      BaseToLoad.writeline("// ");
      BaseToLoad.close();
      BaseToLoad.delete();
      exec(""@$TWM::RanksDirectory@"/TopRanks.TWMSave");
      //then update the client's file
      UpdateRankFileGUID(%player);
   }
}

function ccTop5(%client,%args){
   messageClient(%client, 'MsgClient', "\c2Top Players are:");
   for(%i = 1; %i <= 5; %i++){
	messageClient(%client, 'MsgClient', "\c2"@%i@":"@$Rank::Top[%i]@",XP:"@$Rank::TopXP[%i]@","@$Rank::TopRank[%i]@".");
   }
   return 1;
}

function ccTop10(%client,%args){
   messageClient(%client, 'MsgClient', "\c2Top Players are:");
   for(%i = 1; %i <= 10; %i++){
	messageClient(%client, 'MsgClient', "\c2"@%i@":"@$Rank::Top[%i]@",XP:"@$Rank::TopXP[%i]@","@$Rank::TopRank[%i]@".");
   }
   return 1;
}

//--------------------------------------
//Misc
//--------------------------------------

function getNumberOfWords(%path){
   %number = 0;
   for(%i = 0; %i < 1000; %i++){
	if(getWord(%path,%i) !$= "")
	   %number++;
	else
	   return %number;
   }
}

