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 :-)
You could use a Custom property (name "weight", type int, default value 0) and enter the weight for each inventory item.
Then:
// 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.
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 (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=28770.msg366090#msg366090)!
[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
Thanks for the advertising Trent, but what does the manual in PDF have to do with my RoomInv module (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=28770.msg366090#msg366090)? :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! :=