Skip to content

Instantly share code, notes, and snippets.

@asantoni
Last active August 29, 2015 14:14
Show Gist options
  • Save asantoni/d9911c636f72afabc27e to your computer and use it in GitHub Desktop.
Save asantoni/d9911c636f72afabc27e to your computer and use it in GitHub Desktop.
Zandronum ACS - Player saving and loading (persistent inventory), with new Zandronum 1.3 database functions
//This code is from the Survivalism WAD -- Hax Murderer
#define PERSISTENT_INVENTORY_LEN 5
int persistentInventory[PERSISTENT_INVENTORY_LEN] =
{
//YOU MUST UPDATE PERSISTENT_INVENTORY_TABLE_LENGTH WHEN YOU ADD
//NEW ITEMS TO THIS ARRAY!
//This is a list of inventory items you want to be able to save to and load from the database.
"XP",
"XPLevel",
"Pistol",
"Shotgun",
"Chaingun"
};
function void restorePersistentInventory (int playerTid)
{
if (!PlayerIsLoggedIn(PlayerNumber()))
{
Log(s:"If you were logged in, we would be restoring your inventory!");
return;
}
str accountName = GetPlayerAccountName(PlayerNumber());
str namespace = strparam(s:accountName, s:"_inventory");
print(s:"Restoring your inventory...", s:namespace);
for (int i = 0; i < PERSISTENT_INVENTORY_LEN; i++) {
GiveActorInventory(playerTid, persistentInventory[i], GetDBEntry(namespace, persistentInventory[i]));
}
print(s:"Inventory restored!");
}
script 810 /*savePersistentInventory*/ (void)
{
int playerTid = PLAYER_MIN_TID + PlayerNumber();
if (!PlayerIsLoggedIn(PlayerNumber()))
{
print(s:"You must be logged in save your inventory.");
ActivatorSound("menu/invalid", 127);
terminate;
}
str accountName = GetPlayerAccountName(PlayerNumber());
str namespace = strparam(s:accountName, s:"_inventory");
print(s:"Saving your inventory...");
BeginDBTransaction();
for (int i = 0; i < PERSISTENT_INVENTORY_LEN; i++) {
SetDBEntry(namespace, persistentInventory[i], CheckActorInventory(playerTid, persistentInventory[i]));
//print(s:persistentInventory[i], s:" amount:", d:CheckActorInventory(playerTid, persistentInventory[i]));
}
EndDBTransaction();
print(s:"Inventory saved!");
ActivatorSound("switches/normbutn", 127);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment