Wintermute Engine Forum

Wintermute Engine => Scripts, plugins, utilities, goodies => Topic started by: Jerrot on December 19, 2003, 03:10:19 PM

Title: Managing multiple inventories
Post by: Jerrot on December 19, 2003, 03:10:19 PM
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: [Select]
// 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.

Not too beauty, but should work fine.

Jerrot.
Title: Re:Managing multiple inventories
Post by: Nihil on December 19, 2003, 03:13:44 PM
Thanks!

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

PS: You forgot Mary in your example :)
Title: Re:Managing multiple inventories
Post by: Jerrot on December 19, 2003, 03:22:53 PM
PS: You forgot Mary in your example :)

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...