Changing NPC inventory

Started by Goot, Sat 12/06/2004 18:58:26

Previous topic - Next topic

Goot

I have a game when you can switch between controlling 2 characters. If one player goes somewhere and gets an inventory item or loses one, I want it to change in the otehr character's inventory too. Is there an easy way to do this? I've tried switching characters, adding or losing inventory, and then  switching back, but then the character I was originally controlling ends up in the room where the other character was, sometimes stuck in a place where he can't move.
Please help if you can.

Scorpiorus

Yes, to manipulate NPC inventory items use a character[].inv[] variable, like:


character[NPC].inv[ITEM] = 1; // will make appear one ITEM in the NPC's inventory bag

character[NPC].inv[ITEM] = 0; // will remove it

To add an item you can do:

character[NPC].inv[ITEM] = character[NPC].inv[ITEM]Ã,  + 1;

or the same but shorter:

character[NPC].inv[ITEM]Ã,  += 1;

to remove one

character[NPC].inv[ITEM]Ã,  -= 1;

to remove all dublicates of the inventory item ITEM:
character[NPC].inv[ITEM]Ã,  = 0;

Kelly

Oh my God, this may be the single most useful thing I've ever read on these forums!

My game has two playable characters that you switch back and forth between during the game. On several occasions, the other character appears while you are controlling the one that is most important to that aspect of the story at the moment. During these moments, the other character acts as sort of a sidekick/helper (when he's around) and you can give him inventory from your own items box.

The character you control changes several times over the course of the game. The sidekick changes accordingly, of course. In order to keep their inventory straight, I've had to resort to all sort of subtle SetPlayerCharacter commands to give me access to the sidekick's inventory when needed.

Thanks to you, Scorpiorus, I now have a much easier way to do that!

You have my eternal gratitude.

:-*

Scorpiorus

You are welcome, :)

The AddInventory and LoseInventory functions just do character[].inv[]++ and character[].inv[]-- respectively but also update the inventory window to reflect the changes. Thus we can write an Ex version of each one with scrpting:

function AddInventoryEx(int CharID, int item) {

   character[CharID].inv[item]++; // add one
   UpdateInventory(); // update inventory window
}

function LoseInventoryEx(int CharID, int item) {

   if (character[CharID].inv[item]>0) character[CharID].inv[item]--; //remove if any left
   UpdateInventory(); // update inventory window
}

...to enable us to add/remove inventory items for any character.

SMF spam blocked by CleanTalk