//::////////////////////////////////////////////////// //:: Created By: Valerio Santinelli - tanis@mediacom.it //:: Created On: 2002/08/09 //::////////////////////////////////////////////////// /* Persistent World DataBase module's OnHeartBeat script. Credits to E.J. Wilburn - zane@supernova.org for the original idea. Saves the changes to the persistant DBs. */ #include "pwdb_functions" void PWDB_SaveToDatabase() { WriteTimestampedLogEntry("PWDB_SaveToDatabase()"); // Set some test vars on PCs who haven't had them. object oPC = GetFirstPC(); while (oPC != OBJECT_INVALID) { if (GetLocalInt(oPC, "PV_TEST_VARS_SET")) { oPC = GetNextPC(); continue; } SetPersistentLocation(oPC, "PV_START_LOCATION", GetLocation(oPC)); SetPersistentString(oPC, "PV_TEST_STRING", "Testing"); SetPersistentInt(oPC, "PV_TEST_INT", 99); SetPersistentFloat(oPC, "PV_TEST_FLOAT", 9.9f); SetPersistentObject(oPC, "PV_TEST_OBJECT", GetArea(oPC)); SetLocalInt(oPC, "PV_TEST_VARS_SET", 1); oPC = GetNextPC(); } object oMod = GetModule(); int iHeartBeat = GetLocalInt(oMod, "TMP_HBMONITOR"); if (iHeartBeat == 0) { SetLocalInt(oMod, "TMP_HBMONITOR", 1); WriteTimestampedLogEntry("Saving ALL to PWDB"); PWDBSaveAll(); } else { SetLocalInt(oMod, "TMP_HBMONITOR", 0); WriteTimestampedLogEntry("Saving CHANGED to PWDB"); PWDBSaveChanged(); } // If all clients have left, save the entire database. object oTemp = GetFirstPC(); int iPlayerCount = 0; while (oTemp != OBJECT_INVALID) { iPlayerCount++; oTemp = GetNextPC(); } int iSavedAll = GetLocalInt(oMod, "PWDB_SAVEDALL"); if (iPlayerCount < 1 && !iSavedAll) { SetLocalInt(oMod, "PWDB_SAVEDALL", 1); PWDBSaveAll(); } else if (iPlayerCount > 0 && iSavedAll) { SetLocalInt(oMod, "PWDB_SAVEDALL", 0); } }