Wintermute Engine > Scripts, plugins, utilities, goodies

Managing multiple inventories

(1/1)

Jerrot:
Hiya,

this question came several times and although it will be implemented in a future version of WME, the script solution is quite easy.

I'll write it quite "straight", of course you can create a far more comfortable function of it. In this example we have two inventories - for Peter and Paul. And of course you have to make those internal inventories (inv_Peter / inv_Paul) global !


--- Code: ---// We need some variables...

var counter, counter2, amount;
var inv_Peter = new Array();
var inv_Paul = new Array();

// Peter is the current actor, so this becomes his inventory:

Game.TakeItem("book1");
Game.TakeItem("book2");
Game.TakeItem("book3");
Game.TakeItem("book4");

// And this will be the default inventory for Paul, assuming
// we didn't play with him yet.

inv_Paul[0] = "book5";
inv_Paul[1] = "book6";
inv_Paul[2] = "book7";
inv_Paul[3] = "book8";

// okay, now we switch from Peter to Paul.
// let's truncate the internal inventory of Peter,
// fill it with the current items and clear the
// current game inventory

inv_Peter = null;
amount = Game.NumItems;
for(counter=0; counter<(amount); counter=counter+1)
{
  inv_Peter[counter] = Game.GetItem(0);
  Game.DropItem(inv_Peter[counter]);
}

// now we just fill up the (currently empty) game inventory with the
// internal inventory of Paul

for(counter2=0; counter2<counter; counter2=counter2+1)
{
  Game.TakeItem(inv_Paul[counter2]);
}

// done.
--- End code ---

Not too beauty, but should work fine.

Jerrot.

Nihil:
Thanks!

I hope I can manage to try it out this weekend.

PS: You forgot Mary in your example :)

Jerrot:

--- Quote from: Nihil on December 19, 2003, 03:13:44 PM ---PS: You forgot Mary in your example :)

--- End quote ---

Well, she lost all her items when she did a job acting as "Wilma" in some Tetris game, so I had no use for her anymore...

Navigation

[0] Message Index

Go to full version