Help with a script

I want to run a script that will drop an object from the player's inventory if the object has a certain attribute.

Say I have an object that has the attribute 'weapon'

I want to have a command verb 'disarm' And I want that command to un-equip any weapons (I can do this bit, because my code will interpret having 0 'armed' attribute as being unarmed.) But I also want to drop all weapons in my inventory.

Can some kind soul please tell me how to drop all items with a certain attribute from a player's inventory? Thank you so much.

Something like
'If object in inventory has attribute x then drop object.'

Example where your character may disarm, but only under duress. (missing the drop script):

if (Yourself.armed = 0) {
msg ("You are already unarmed.")
}
else if (Yourself.duress = true) {
set (Yourself, "armed", 0)
msg ("You remove your weapons.")
}
else {
msg ("You have no reason to disarm yourself right now.")
}

Ps. It doesn't have to be an attribute. Any flag or other way of signifying the type of item would work.


You need to iterate through each item in the inventory (first line), and check each one in turn (second line), and if it has the attribute, change its location, which in Quest is the "parent" attribute (third line):

foreach (obj, ScopeInventory()) {
  if (HasAttribute(obj, "weapon")) {
    obj.parent = player.parent
  }
}

I hope that makes sense; please say otherwise!


I'm glad my game relies on minimal number of inventory items. With anything useless getting discarded or stored elsewhere. :D

Thank you!


Hold the horses. Seems I misunderstood something...

Anyway after giving it some thought I decided I should instead make a command that targets the weapon instead of the player... Makes more sense...


you can create a 'storage' system too, so not to have a cluttered 'inventory' (which is the 'player' Player Object's sub-Objects within it, and a hidden 'inventory' Objectlist Attribute).

if interested in doing a storage system, let me know
(basically, you just have a nested Objects (hidden from game play or apart of the game play: such as in your inventory), where you move Objects/your-in-game-items in and out of and/or view what Objects are in your 'storage' Objects and whatever other functionalities, and the scripting to handle doing this)


equipment systems coding is complicated... I'm still trying to do my own...

Pixie's already got a great equipment (and magic and etc, lol) system, so you should use his, if you can't create your own.


Speaking of which, I installed Pixies clothing library, and for some reason it seems the "TestRemove" function is nowhere to be found... Which is making my progress a bit jammy at the moment :D


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums