Hi!
Is there an EASY way of having multiple characters sharing one inventory?
Each character has their own inventory. Perhaps if you explain what you're trying to do, we can think of an easier solution.
make global ints that will remember what inventory items are currently in your players position, and when you change characters, you can do a check on all inventory items. small if statements asking if the global int X is 0 or 1,and then add inventory if 1
He means that he has like 3 characters, and when he opens the inventory it doesn't matter which character you're playing with they all have the same inventory items.
Hmm, I guess the best way would be always to add and remove items from one specific character's inventory, and show that to the player as the inventory window. Interesting point.
Maybe you could implement some way of bringing up a specified characters inventory rather then only having access to the inventory of the current player?
So if they want to access the inventory of the character ROGER then they could type InventoryScreen (ROGER),
but if they wanted to access the inventory of the character EGO then they could type InventoryScreen (EGO).
That's a good idea... Allthough you can probably do it by scripting already:
int CurrentCharID, invcharx, invchary, invcharroom;
function CharacterInventory(int InvCharID) {
// Get current player character
CurrentCharID = GetPlayerCharacter();
// Get inventory character's location
invcharx = character[InvCharID].x;
invchary = character[InvCharID].y;
// Move inventory character ot same location as player to prevent unwanted screen moving
character[InvCharID].x = character[CurrentCharID].x;
character[InvCharID].y = character[CurrentCharID].y;
// Get inventory character's current room, and make sure they are not visible in the screen
invcharroom = character[InvCharID].room;
character[InvCharID].room = -1;
// Open the inventory of the other character
SetPlayerCharacter(InvCharID);
InventoryScreen(); // or custom inv code here
SetPlayerCharacter(CurrenrCharID);
// Put inventory character back where they belongs to
character[InvCharID].x = invcharx;
character[InvCharID].y = invchary;
character[InvCharID].room = invcharroom;
}
I have not tested, but this should work...
Along with a couple of custom AddInventory and LoseInventory functions to add them to the correct player, that sort of thing should do the trick.
It's not easy though, I appreciate.
int CurrentCharID;
fucntion AddCharInv(int InvCharID, int invitem) {
// Get current player character
CurrentCharID = GetPlayerCharacter();
// Get inventory character's location
invcharx = character[InvCharID].x;
invchary = character[InvCharID].y;
// Move inventory character ot same location as player to prevent unwanted screen moving
character[InvCharID].x = character[CurrentCharID].x;
character[InvCharID].y = character[CurrentCharID].y;
// Get inventory character's current room, and make sure they are not visible in the screen
invcharroom = character[InvCharID].room;
character[InvCharID].room = -1;
// Add the inventory item
SetPlayerCharacter(InvCharID);
AddInventory(invitem);
SetPlayerCharacter(CurrentCharID);
// Put inventory character back where they belongs to
character[InvCharID].x = invcharx;
character[InvCharID].y = invchary;
character[InvCharID].room = invcharroom;
}
And:
fucntion LoseCharInv(int InvCharID, int invitem) {
// Get current player character
CurrentCharID = GetPlayerCharacter();
// Get inventory character's location
invcharx = character[InvCharID].x;
invchary = character[InvCharID].y;
// Move inventory character ot same location as player to prevent unwanted screen moving
character[InvCharID].x = character[CurrentCharID].x;
character[InvCharID].y = character[CurrentCharID].y;
// Get inventory character's current room, and make sure they are not visible in the screen
invcharroom = character[InvCharID].room;
character[InvCharID].room = -1;
// Add the inventory item
SetPlayerCharacter(InvCharID);
LoseInventory(invitem);
SetPlayerCharacter(CurrentCharID);
// Put inventory character back where they belongs to
character[InvCharID].x = invcharx;
character[InvCharID].y = invchary;
character[InvCharID].room = invcharroom;
}
Actually, this code:
character[InvCharID].room = -1;
// Add the inventory item
SetPlayerCharacter(InvCharID);
will crash the game, since the SetPlayerCharacter call will attempt to change to room -1 (and fail, obviously). You need to bring the InvCharID character into the same room as the player.
Also, AddCharInv is simpler than that:
function AddCharInv(int InvCharID, int invitem) {
character[InvCharID].inv[invitem]++;
UpdateInventory();
}
Whoops.... ;D