Picking up/adding item to inventory, then dropping it where ever You want

Started by Shockbolt, Tue 31/03/2009 22:27:46

Previous topic - Next topic

Shockbolt

So, if the main character or an npc for that matter, should add an object to the inventory:

How should I go about handling one or any of them dropping an object/item to the ground or placing it anywhere in a room, and it'd still
have to be able to be picked up again?

Example: Inventory(bag/backpack/chest/etc) has a limit to either weight/size or numbers, the item must be dropped but be able to be fetched again when there's room in the Inventory again.

And, how would I go about defining a limit to what the inventory could store, and assigning "size" to an item?
Would I have to create an int for each item to be picked up, and then compare the total size against an global var/int?

I would appreciate some pointers to this one :-)

Khris

You could use a Custom property (name "weight", type int, default value 0) and enter the weight for each inventory item.
Then:
Code: ags
// global script

int max_inv_weight = 20000;  // grams
int cur_inv_weight;

// this gets called by AGS automatically after the player lost an inv item
function on_event(EventType event, int data) {
  if (event == eEventLoseInventory) {
    InventoryItem*i = inventory[data];
    cur_inv_weight -= i.GetProperty("weight");
  }
}

void AddInv(this Character*, InventoryItem*i) {
  if (this != player) {
    this.AddInventory(i);
    return;
  }
  int w = i.GetProperty("weight");
  if (cur_inv_weight + w <= max_inv_weight) {
    this.AddInventory(i);
    cur_inv_weight += w;
  }
  else player.Say("I'm carrying too much already.");
}


Use the latter instead of player.AddInventory(...).
_________________________________________________________________

Creating additional room objects isn't possible.
You'd have to work around that using characters, i.e. create a lot of dummy characters starting out in room -1, then move them to the current room to represent the dropped objects, changing their standing frame to the object's sprite.
This requires managing an array of characters and additional data, e.g. which object they currently represent.
It's doable, but a lot of code-heavy work.

Trent R

Quote from: Shockbolt on Tue 31/03/2009 22:27:46
How should I go about handling one or any of them dropping an object/item to the ground or placing it anywhere in a room, and it'd still  have to be able to be picked up again?
Check out monkey's fancy RoomInv Module!

[Edit]: Gah! I was out of it yesterday... I copied that link to PM to Nickdude, apparently accidently pasted it here too.... Fixed now!

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

monkey0506

Thanks for the advertising Trent, but what does the manual in PDF have to do with my RoomInv module? :P

As Trent says it would solve the problem of dropping an InventoryItem off into any room. It would not however deal with the weight issue, but Khris provided the code for that. Combine the two and you should be good to go! :=

SMF spam blocked by CleanTalk