[Script] add all items to inventory

  • #1, by sebastianSaturday, 12. November 2016, 15:57 8 years ago
    Hello there,

    for debug purposes i wrote a little LUA script which adds all items to the current characters inventory. 
    Before this I had a normal action and added every item via an action part manually to it. Meh.

    Now this LUA script cycles to all available game items and adds them to the characters inventory. Also it skips items which begin with "-" (separators).

    To include this function just use it inside an "execute a script" action part:
    char = game.CurrentCharacter
    inv = {}
    
    for i = 1, #game.Items do
     if not string.starts(game.Items[i]:getName(),"-")then
       print("added '"..game.Items[i]:getName().."' to the inventory")
       table.insert(inv,game.Items[i])
     end
    end
    
    char:setValue(VCharacterItems, inv)

    Maybe some of you can use it, too smile

    kind regards
    Sebastian

    Thread Captain

    2346 Posts


  • #2, by afrlmeSaturday, 12. November 2016, 18:10 8 years ago
    That's a nice idea. smile

    Imperator

    7278 Posts

  • #3, by bananeisafreeMonday, 14. November 2016, 13:50 8 years ago
    Cheers mate, that will come in handy !

    Forum Fan

    120 Posts

  • #4, by sebastianMonday, 14. November 2016, 14:34 8 years ago
    oh derp.  I missed my string.starts function xD
    This is needed if you want to skip Items with "-"at the beginning of the name.  it needs to be a definitiom script:


    function string.starts(String,Start)
       return string.sub(String,1,string.len(Start))==Start
    end

    Thread Captain

    2346 Posts

  • #5, by afrlmeMonday, 14. November 2016, 16:34 8 years ago
    If you provide me with some instructions & info I can create a page on the wiki script section for it if you like? Just need a basic tutorial & any resource files (if you want to provide a working ved or video tutorial example, etc) - if not it doesn't matter. Just the main script & a basic guide is more than enough. wink

    Imperator

    7278 Posts

  • #6, by sebastianTuesday, 15. November 2016, 14:04 8 years ago
    sure. I will try to write down the needed stuff in the next days (very busy right now) 

    Thread Captain

    2346 Posts

  • #7, by afrlmeTuesday, 15. November 2016, 14:58 8 years ago
    Ok mate, no rush so take your time! wink

    Imperator

    7278 Posts

  • #8, by sebastianSaturday, 26. November 2016, 22:49 8 years ago
    So here are the insturcutions to get this working:

    For what is it for: For debug purposes. With this function you can give your character all available items in the game without adding them manually with action parts

    What is needed: Some kind of debug interface/scene where you have a button to click on.

    Instructions:


    Add this as a definition script in the scripts section of Visionaire Studio:
    function string.starts(String,Start)
       return string.sub(String,1,string.len(Start))==Start
    end

    Add this inside an "Execute a script" action part of your choice:
    char = game.CurrentCharacter
    inv = {}
    
    for i = 1, #game.Items do
     if not string.starts(game.Items[i]:getName(),"-")then
       print("added '"..game.Items[i]:getName().."' to the inventory")
       table.insert(inv,game.Items[i])
     end
    end
    
    char:setValue(VCharacterItems, inv)

    This action part should be placed when performing a speficic action like klicking on a button inside your debug interface:


    Items with an "-" (separator) at the beginning get skipped by the script and won't be added.

    Thread Captain

    2346 Posts