[Script] add all items to inventory

  • #1, z sebastianSaturday, 12. November 2016, 15:57 hodinky 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

    Kapitán

    2346 Posts


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

    Imperátor

    7285 Posts

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

    Fanoušek fóra

    120 Posts

  • #4, z sebastianMonday, 14. November 2016, 14:34 hodinky 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

    Kapitán

    2346 Posts

  • #5, z afrlmeMonday, 14. November 2016, 16:34 hodinky 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

    Imperátor

    7285 Posts

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

    Kapitán

    2346 Posts

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

    Imperátor

    7285 Posts

  • #8, z sebastianSaturday, 26. November 2016, 22:49 hodinky 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.

    Kapitán

    2346 Posts