Showing a menu of player inventory
Atokrad
26 Feb 2021, 00:19Is there a way to print out a menu that shows a player's inventory, I am adding an upgrade mechanic into my game so I want the player to be able to choose a weapon to upgrade.
mrangel
26 Feb 2021, 01:06Something like:
ShowMenu ("Choose an item to upgrade", ScopeInventory(), true) {
// the variable 'result' here is the *name* of the chosen item
// Use 'GetObject(result)' to get the actual item
}
mrangel
26 Feb 2021, 01:12You might also want to do something like:
weapons = NewObjectList()
foreach (item, ScopeInventory()) {
if (some way to test if an item is a weapon that can be upgraded) {
list add (weapons, item)
}
}
if (ListCount (weapons) > 0) {
ShowMenu ("Pick a weapon to upgradeā¦", weapons, true) {
// as before, result is the *name* of the chosen item
// Doing it this way, only the relevant type of items are listed
}
}
else {
msg ("You don't have anything you can upgrade.")
}
Atokrad
26 Feb 2021, 02:26How would I test if an object is a weapon? I know about flags but I don't know how to test for multiple objects.
mrangel
26 Feb 2021, 09:30If you've got an "is a weapon" flag, the expression in that if statement would just be GetBoolean(item, "isweapon")
, or whatever the name of the flag is. Although in that case there's a function to do the first loop for you:
weapons = FilterByAttribute (ScopeInventory(), "isweapon", true)
if (ListCount (weapons) > 0) {
ShowMenu ("Pick a weapon to upgradeā¦", weapons, true) {
// code to upgrade result goes here
}
}
else {
msg ("You don't have anything you can upgrade.")
}
Atokrad
26 Feb 2021, 19:53So can I have this work for a section in the inventory, I am organizing the inventory into sections so I have a container in the inventory for weapons.
mrangel
26 Feb 2021, 19:57In that case, just replace ScopeInventory()
with GetDirectChildren (weapons)
(or whatever your weapons container is called).
Atokrad
26 Feb 2021, 22:45If I use an if script how would I get the result, or is there a better way?
Atokrad
26 Feb 2021, 23:45I found a way to do it, thanks for the help!