I want to put in a bar UI to show how full the player's inventory is, but there doesn't seem to be an attribute for this.
This isn't stored in an attribute because it is calculated whenever the player tries to take an object. This is why a script that adds an object to the inventory won't be noticed until they try to pick up something else.
There are two ways in which the inventory is limited. If the number of objects is limited, the limit will be stored in the attribute game.pov.maxobjects
, and this is just compared to the total given by GetDirectChildren (game.pov)
. This seems weird to me because it includes invisible objects; but that's how it works.
If you're using object weight/volume, the limit is stored in the attribute game.pov.maxvolume
. The script loops over all objects in the inventory and adds up their volume
attributes every time this is checked.
Therefore I think the best way to deal with this is to have a script which runs every time the player gains or drops an object, which adds up this total and stores it in an attribute. Or maybe making it a turnscript would be simpler; if less efficient. Something like:
game.pov.carriedvolume = 0
foreach (obj, GetAllChildObjects(game.pov)) {
if (HasInt(obj, "volume")) {
game.pov.carriedvolume = game.pov.carriedvolume + obj.volume
}
}
Then you could use the attribute carriedvolume
to find out how much the player is carrying.
Yes, thats basically how i did it, but I put it as a function:
vol = 0
foreach (o, GetAllChildObjects(player)) {
if (HasInt(o, "volume")) {
vol = vol + o.volume
}
}
return (vol)