//:://///////////////////////////////////////////// //:: Name Trinity Player Database Include //:: FileName tab_main_data //:: Copyright (c) 2001 Bioware Corp. //::////////////////////////////////////////////// /* This is the primarly include, this preforms allot of the maintnace for the the database */ //::////////////////////////////////////////////// //:: Created By: Donny Wilbanks Modified by Tab //:: Created On: 6/24/03 //::////////////////////////////////////////////// // * List of Varibles Used. Here is a good place to list your varibles used // * in your player Database. Good Way would to be list the strings and what // * type // *** Player "sPDB" // // Name Type Notes // // Last_Y_Play I Last Year Played // Last_M_Play I Last Month Played // // **** Character "varibles" // // Name Type Notes // PlayerID I Player Number // CharaceterID I Character Number // SP_RACE S Special Race, this goes a bit beyond // the "GetSubRace". Lets you add something // custom here. // SP_STATUS S Special Status, maybe used for like being // Undead... // SP_STATUSSUB S Another Special Status that can be used // NoC_KILL I Number of Creatures Killed // NoC_MosPHD I Most Powerful Creature HD killed. // NoC_MosName S Name of Most Powerful Creature Killed // NoP_MosPHD I Most Powerful PC killed // NoP_MosName S Name of Last PC Killed // NoP_KILLS I Number of PC's Killed // ASG_BANK F Hey Bank Access! Varible to Store Gold! // LastLocation L Last Location. // J_Year I Year Joined Server // J_Month I Month Joined Server // J_Day I Day Joined Server // HitPoints I Current Hit Points; // **** Moduble Database // // Name Type Notes: // // No_Players I Number of Players - Used to do searching // PL_XX I Basic Player ID Number // PL_XX_NAME S Player Login Name - Points to the Player Database // PL_XX_CDKEY S Public CD Key for Player XX // PL_XX_ACTIVE I is the Player Active, mostly used for place holding // ******************************************************************* // * // * ASG Player Database // * // This creates a serperate Database for EACH player storing characters // and special information pertaining to that PLAYER. Database Structure // // Module player Database - This holds allot of module related information // (sMDB) // : // : // \.......... Player Database - This holds his Characters and // (sPDB) other player and charater info. // #include "tab_custom_db" int DEBUG = TRUE; void PlayerDatabase(string sReadWriteInit,object oPlayer) { object oMOD = GetModule(); // Module Object string sMod = GetTag(oMOD); // Module Tag, used as part of the Database Name; string sMDB = "MDB_"+sMod; // Master Player Database name string sPDB = GetPCPlayerName(oPlayer); // Individule Player Database Name; // In order to try to create a Unique Key with limited Characters // Use the 1st and last 4 letters Characters Name and Public CD Key. // this will leave use 12 characters for varible information. string sName = GetName(oPlayer); string sLeft = GetStringLeft(sName,4); string sRight = GetStringRight(sName,4); string CDKey = GetPCPublicCDKey(oPlayer); string sID = GetStringLeft(sName,20); // Indivudual Character Used inside the string sHID = sName+CDKey; // Hcr Style; // Player Databse (sPDB) as Unique Varible name for player. int iPlayerIndex; // int iRWI = 0; // Defualt for Error Recoreding if (sReadWriteInit=="R") iRWI = 1; // Read from Player Database if (sReadWriteInit=="W") iRWI = 2; // Write to Player Databse if (sReadWriteInit=="I") iRWI = 3; // Intiatlise Global Varibles for Player if (sReadWriteInit=="S") iRWI = 4; // Setup New Character; if (sReadWriteInit=="M") iRWI = 5; // Purge Old Recored. // **************************** // * // * ASG Database for Player // * // ** Set up HCR ID system; int iCharacterIndex; // int iPlayedBefore = GetCampaignInt(sPDB,sID+"_CHINDEX"); switch(iRWI) { case(1): // * Read { if (DEBUG==TRUE) { PrintString("(*) Reading from "+sPDB+" database, character "+sID+"."); } SetLocalInt(oMOD,sHID+"PlayerID",GetCampaignInt(sPDB,sID+"PlayerID",oPlayer)); SetLocalInt(oMOD,sHID+"CharIndex",GetCampaignInt(sPDB,"CharIndex")); SetLocalInt(oMOD,sHID+"CharID",GetCampaignInt(sPDB,sID+"CharID",oPlayer)); // Go to Your Custom Information Asg_PB_CustomRead(oPlayer); } break; // * Save case(2): // * Write { if (DEBUG==TRUE) { PrintString("(*) Writing to "+sPDB+" database on character "+sID+"."); } SendMessageToPC(oPlayer,"Updating your database."); // Get Custom Infromation Asg_PB_CustomWrite(oPlayer); } break; case(3): // Intiate New Character { SendMessageToPC(oPlayer,"Updating "+sPDB+" for new Character "+sName); // Setting Up New Account - Create and Update Player Index. SetLocalInt(oMOD,sID+"PlayerID",GetCampaignInt(sPDB,"MDB_ID")); int iCharID = GetCampaignInt(sPDB,"CharIndex")+1; SetLocalInt(oMOD,sHID+"CharID",iCharID); // Setup New Player Index Card // * Welcome Message if (DEBUG==TRUE) { PrintString("New Character, "+sName+" being added to player "+sPDB+" database."); } // Special One Time Writing, Required by the Database SetCampaignInt(sPDB,sID+"PlayerID",GetLocalInt(oMOD,sHID+"PlayerID")); SetCampaignInt(sPDB,"CharIndex",iCharID); SetCampaignInt(sPDB,sID+"CharID",GetLocalInt(oMOD,sHID+"CharID"),oPlayer); if (DEBUG==TRUE) { PrintString(" Finished adding new Character."); } // *** Summon Up Custom Database Asg_PB_CustomConfig(oPlayer); // SendMessageToPC(oPlayer," Completed Update."); } break; case(4): // Setup a New Player { if (DEBUG==TRUE) { PrintString("Adding new Player "+sPDB+" to Database."); } SendMessageToPC(oPlayer,"(*) Creating a new Account for "+sPDB); // Add to Master Database The followin Information int iModPlayerIndex = GetCampaignInt(sMDB,"No_Players"); string sPlayerNum; string sPlayerModID; string sPlayerName; string sPlayerCDKey; string sPlayerActive; int iK; // Search for Holes in the MDB Database, Look for 1st Avaible Slot int iHole = 0; int iIndex = iModPlayerIndex; for (iK = iIndex;iK>0;iK--) { sPlayerNum = IntToString(iK); sPlayerModID = "PL_"+sPlayerNum; sPlayerActive = "ACTIVE_"+sPlayerModID; if (GetCampaignInt(sMDB,sPlayerActive)==FALSE) iHole = iK; } // Found hole or Create NEW recored if (iHole == 0) { iModPlayerIndex++; SetCampaignInt(sMDB,"No_Players",iModPlayerIndex); } else { iModPlayerIndex = iHole; } sPlayerNum = IntToString(iModPlayerIndex); if (DEBUG==TRUE) { PrintString(" (~) Player ID Number = "+sPlayerNum); } sPlayerNum = IntToString(iModPlayerIndex); sPlayerName = "NAME_PL_"+sPlayerNum; sPlayerCDKey = "CDKEY_PL_"+sPlayerNum; sPlayerActive = "ACTIVE_PL_"+sPlayerNum; SetCampaignInt(sPDB,"MDB_ID",iModPlayerIndex); SetCampaignString(sMDB,sPlayerName,sPDB); SetCampaignString(sMDB,sPlayerCDKey,CDKey); SetCampaignInt(sMDB,sPlayerActive,TRUE); SetCampaignInt(sPDB,"Last_Y_Play",GetCalendarYear()); SetCampaignInt(sPDB,"Last_M_Play",GetCalendarMonth()); if (DEBUG==TRUE) { PrintString(" Finsihed adding new player."); } // SendMessageToPC(oPlayer," Completed new Account."); } break; case(5): // Database Maintance { // This is designed to "Cleanup" in active accounts and automaticly // remove databases that are not in use. Good to use Module Load if (DEBUG==TRUE) { PrintString("(*) Start of Database Clean Up."); } string sPlayerNum; string sPlayerModID; string sPlayerName; string sPlayerCDKey; string sPlayerActive; int iDelete = GetLocalInt(oMOD,"TAB_MOD_CLEANYEAR"); int iLast; int iNow = (GetCalendarYear()*10000)+(GetCalendarMonth()*1000); int iK = 0; int iIndex = GetCampaignInt(sMDB,"No_Players"); for (iK = 1;iK<=iIndex;iK++) { sPlayerNum = IntToString(iK); sPlayerModID = "PL_"+sPlayerNum; sPlayerName = "NAME_PL_"+sPlayerNum; sPlayerActive = "ACTIVE_PL_"+sPlayerNum; // iLast = GetCampaignInt(sPDB,"Last_Y_Play")*10000; iLast += GetCampaignInt(sPDB,"Last_M_Play")*1000; iLast += iDelete; if (iLast>iNow) // Delete Old Recored; { if (DEBUG==TRUE) { PrintString(" Player Database Updated, Removing "+sPDB+" from database."); } DestroyCampaignDatabase(sPDB); DeleteCampaignVariable(sMDB,sPlayerName); DeleteCampaignVariable(sMDB,sPlayerCDKey); SetCampaignInt(sMDB,sPlayerActive,FALSE); if (DEBUG==TRUE) { PrintString("(!) End Database Clean Up."); } } } } break; default:; SendMessageToPC(oPlayer,"(!) Database Error, Unreconginsed Command "+IntToString(iRWI)+"."); PrintString("(!) ERROR: Database Command "+IntToString(iRWI)); } } /* USed ony to Debug the Script void main() { PlayerDatabase("W",OBJECT_SELF); } */