Game Development Community

dev|Pro Game Development Curriculum

Saving Inventory Between Missions

by Mark Harmon · 05/13/2003 (1:55 pm) · 2 comments

Download Code File

Here I am modifying Tim Newell's code again. Make sure to backup your code before trying these changes. This has not been tested in a multiplayer game.

This code resource requires that the Inventory Manager Tutorial
be added first.

So now you have the Inventory manager working, or are just skimming this resource looking for the meat.

Copy the zipped up Inventory.cc and Inventory.h files over the originals. These modified files add the save and load methods, as well as a few other changes. If you are worried about overwriting your own changes then do a diff to see the changes needed.

Optional Begin:
I didn't like the way it was required to call onInventory from scripts all the time so I moved it into the player.cc file.
Replace the lines of the player.cc with the ones in the included player.cc file. Remove all calls to onInventory() from your .cs files, DON'T remove the implementations.
:Optional End

Merge the lines from the included game.cc file with those in your project. This implements and exposes some functions to the scripting engine.

Now might be a good time to do a clean build of your executable.

The last changes to be made are the calls from script that load and save the player's inventory between levels/missions.

Open up fps\server\scripts\game.cs and find
function GameConnection::onClientEnterGame(%this)
Add these as the last lines in the onClientEnterGame method:

if (IsBetweenLevels())
{
   LoadPlayerBetweenLevels();
   
   // THIS IS A GOOD PLACE TO RESET CERTAIN INVENTORY ITEMS
   //%this.player.setInvItem(RedKey,0);
   //%this.player.setInvItem(BlueKey,0);
   //%this.player.setInvItem(GoldKey,0);
}

Find function endGame() and add this to it before the call to cancel($Game::Schedule)
SavePlayerBetweenLevels();

The last change to make is in the fps\client\ui\loadingGui.gui file.
Find the line
command = "disconnect();";

replace with
command = "disconnect(); SetIsBetweenLevels(0);";

#1
05/14/2003 (5:38 pm)
Anyone try this on a multiplayer game yet? If so please let me know how it works out.
#2
05/16/2003 (6:37 pm)
Thanks Mark!
I look forward to being involved with the rest of your series. If you need me to do any testing or anything just let me know. I believe that being able to save game data for a single player is very important. Some people, like myself, enjoy playing single player.