Game Development Community

dev|Pro Game Development Curriculum

Advanced Rank and Progression [Part 3: Getting it Going]

by Robert Fritzen · 06/01/2011 (11:38 am) · 1 comments

We're almost done, just one final part to install, and this system will be all set to go.

Just a little recap if you need to revisit the previous resources:

PART 1: Resource and C++ Code Installation.
PART 2: Web Server Installation, MySQL and PHP
PART 3: Finishing Up, Installing Ranks and Getting it Going

********************************

So, let's make some things happen now.

Create a new script file, and insert the following code:
function establishRankServerConnection(%type_variable) {
   %connection = PGDConnection();
   //
   %host = $PGD::Server;
   %location = "/battlelord/rank/";   //CHANGE THIS
   %connection.doSingleLineEval = 1;
   //depending on connection type, we will either GET or POST
   switch$(%type_variable) {
      case "send":
      
         StorageContainer("Package", "");
      
         //give the server my exp
         %host = $PGD::Server;
         %seperator = getRandomSeperator(16);
         %header = makeHeader("POST", %location, %host, "Battlelord Client", "Content-Type: multipart/form-data; boundary="@%seperator@"\r\n");

         %dispo = makeDisposition( %seperator, mode, "send");
         %dispo = %dispo @ makeDisposition( %seperator, guid, $ConnStore::guid);

         %dispo = %dispo @ makeDisposition( %seperator, data1, $RankPackaged, 1 );
         $RankPackaged = ""; //clean the store

         %header = %header @ "Content-Length:" SPC strLen(%dispo) @ "\r\n\r\n";

         %connection.request = %header @ %dispo;
      case "request":
         //request my exp from the server
         //this is called on sign-in, and it is used to also track that I am "online"
         //the player list updates begin here as well
         //schedule(10000, 0, "playerStatusUpdate");
         //
         %host = $PGD::Server;
         %seperator = getRandomSeperator(16);
         %header = makeHeader("POST", %location, %host, "Battlelord Client", "Content-Type: multipart/form-data; boundary="@%seperator@"\r\n");

         %dispo = makeDisposition( %seperator, mode, "request");
         %dispo = %dispo @ makeDisposition( %seperator, guid, $ConnStore::guid, 1);

         %header = %header @ "Content-Length:" SPC strLen(%dispo) @ "\r\n\r\n";

         %connection.request = %header @ %dispo;
   }
   //connect and handle functions
   
   %connection.onFinish = "rankConnectionCompleted";
   %connection.PerformConnect(%host);
}

function PGDConnection::rankConnectionCompleted(%this, %response) {
   %allowance = firstWord(%response);
   if(strcmp(%allowance, "INTERNAL_ERROR") == 0) {
      MessageBoxOk("Rank Server Error", "The Rank Server Encountered an Internal Error, please try again later.");
   }
   else if(strcmp(%allowance, "RANKUPDATE") == 0) {
      obtainLocalRank(); //update values on strings
   }
   else if(strcmp(%allowance, "OUTKEY") == 0) {
      %line = strReplace(%response, "OUTKEY ", "");
      StorageContainer("SetKey", %line);
   }
   else if(strcmp(%allowance, "RNKOUT1") == 0) {
      %line = strReplace(%response, "RNKOUT1 ", "");
      StorageContainer("ApplyCont", %line);
      if(!isSet($LocalRankNumber)) {
         obtainLocalRank();
      }
      for(%i = $LocalRankNumber; %i < 61; %i++) {
         $nextEXP_Game = OutRankEXP(%i);
         if(ObtainDE($ConnStore::guid) >= $nextEXP_Game && $GameRank < %i) {
            $GameRank = %i;
         }
      }
   }
   else if(strcmp(%allowance, "ERROR_NSP") == 0) {
      echo("No Rank File");
   }
   else if(strcmp(%allowance, "GEN_ERROR") == 0) {
      MessageBoxOk("Rank Server Error", "An unknown error occured, please try again later.\nIf problems persist, please report this to the developers.");
   }
}

This script is you central core. This handles the transmission and download of the rank data, so whenever you need to get/send rank data, invoke this command on the client.

establishRankServerConnection("send"); to upload
establishRankServerConnection("request"); to download

Now, let's add some stuff.

This resource gave you the following commands to use:

ObtainDE($ConnStore::guid), ObtainDO($ConnStore::guid), PromoteOfficer($ConnStore::guid)

making use of these commands will allow you to create GUI objects that reflect the user's current rank/EXP, and officer promotion level (think CoD Prestige Mode).

You can also add more fields to this class to handle things like kills/deaths, ect., just be sure to update the C++ code.

One thing I should mention though, Torque's string limit can cause some issues with the AES encrypts/decrypts, so if you have a ton of fields, you may need to split it into two separate parts.

If you need help doing this, just ask.

#1
06/01/2011 (11:43 am)
I should note, when a player grants enough EXP to get promoted, the function GetPromoted(%rankNumber) is called automatically, I added this if you wanted to make any GUI's for getting promoted.

Also, you should know this from part one, but to do EXP gain, join a server, get your client ID from the server, and call:

cid.expGrantingAction("Action", "Arg");, modify the C++ table to add action and testing arguments.