Add/Remove items with LUA (or similar)

  • #1, by cr34m3Sunday, 15. June 2014, 01:27 6 years ago
    I've got a trash can-like object in the game I'm working on. I'm trying to get the following behaviour to work:

    When using a dragged item on the trash can:
    * Action (at destination): Item dropped [any]
    - Speaker text will now display what you've discarded
    - The item that you discarded should be removed from your inventory

    When using the trash can without an item dragged:
    - Speaker text to display what you've picked up
    - All the items that you've discarded so far must now be added back to your inventory

    Now, with GameDestinationItem and some LUA I can get the speaker text working fine for the 'throw away' section. Also, with some conditions I can get the appropriate speaker text for the 'take stuff' section.

    My problem is that I don't know how to add/remove items to the character using LUA. Or alternatively, how to specify which item to remove when the action in VS is set up with "[any]".

    Any suggestions or help will be greatly appreciated. smile

    Newbie

    72 Posts


  • #2, by afrlmeSunday, 15. June 2014, 02:51 6 years ago
    Have you checked out the script index on the wiki? I recently wrote & added 2 scripts I think you will be very interested in.

    http://wiki.visionaire-tracker.net/wiki/Insert_Item_(CMS) & http://wiki.visionaire-tracker.net/wiki/Replace_Item_(CMS)

    Now they are not exactly what you are asking for, but they will give you a nod in the right direction for how to go about it. The first script I linked allows you to insert a new item before or after a specific item; as opposed to adding the new item to the end of the inventory. The second script allows you to replace a specific item with a new one; basically remove one item & place a new item in the position of the old item. The reason for this was for items that have different states to them, i.e: you have a bucket with a hole in it that you have just filled with water & the water is leaking out of it, or you have an item that can be separated into 2 items.

    It's almost 3am here now, so I'm not even going to attempt to write up a script. I'm pretty wiped, but hopefully what I've shared will put you on the right path. wink

    Imperator

    6842 Posts

  • #3, by cr34m3Sunday, 15. June 2014, 10:58 6 years ago
    Bookmarked.

    Don't how how I missed this page. grin
    Thanks for the direction, this should be what I need.

    Newbie

    72 Posts

  • #4, by afrlmeSunday, 15. June 2014, 13:07 6 years ago
    There's a lot of useful lua related scripts & functions on that page, & a lot more yet to come. wink

    Imperator

    6842 Posts

  • #5, by cr34m3Sunday, 15. June 2014, 16:14 6 years ago
    Thanks for those examples. Some table.insert and table.remove did the job. grin

    Newbie

    72 Posts

  • #6, by afrlmeSunday, 15. June 2014, 17:08 6 years ago
    no problem. wink

    Imperator

    6842 Posts

Write post