Script for item scrolling via mouse wheel

  • #1, by marvelSunday, 18. January 2015, 17:36 9 years ago
    Has anyone a nice little script to scroll items of the inventory via mouse wheel? smile

    Key Killer

    598 Posts


  • #2, by afrlmeSunday, 18. January 2015, 17:50 9 years ago
    I believe I have already provided a [url=
    http://wiki.visionaire-tracker.net/wiki/Cycle_Inventory_Items_(CMS)]cycle item script[/url] to the wiki Thomas mate. wink

    Imperator

    7278 Posts

  • #3, by EinzelkämpferSunday, 13. August 2017, 16:59 7 years ago
    Sorry for digging out this old thread, but this belongs here.

    I have tried out AFRLme's script and you've done a good job on that. Very clever.

    However, it turns out there is a problem. The scrolling this script does is not matching with what I will be calling the "internal inventory scrolling" that the engine is capable of (through the special up/down buttons). While you can easily avoid using those buttons, the internal scrolling comes into effect when having more items than slots and adding a new item with the option "Scroll to added item" enabled.

    The two scrollings then differ, and when you remove an object from the inventory again, you may end up with an empty slot (although the amount of items is bigger than the amount of slots).

    I haven't found a way around that, because there seems to be no way to affect the internal scrolling through Lua or action part (which is of course the reason AFRLme chose a different approach in the first place).

    Also, I'd like the scrolling to stop at the first and last items respectively, which could be easily achieved using the internal scrolling, because it already does that.

    So my FEATURE REQUEST is: please provide an action part for scrolling through the inventory per Visionaire action that matches the function of the special up/down buttons. Or at least make the internal inventory scrolling scriptable.

    PS.
    You could possibly get around the problem by writing special lua functions for adding/removing items. But I'd like to keep the action parts, because they are easy to read and easy to handle.

    Newbie

    81 Posts

  • #4, by sebastianSunday, 13. August 2017, 21:16 7 years ago
    its possible via lua. it triggers the default inventory scrolling, not the cycling from the wiki. I have it in my game and its working nicely with scrolling wheel or gamepad. Sadly im not at my computer right now. Will post it asap smile 

    Thread Captain

    2346 Posts

  • #5, by afrlmeSunday, 13. August 2017, 22:20 7 years ago
    its possible via lua. it triggers the default inventory scrolling, not the cycling from the wiki. I have it in my game and its working nicely with scrolling wheel or gamepad. Sadly im not at my computer right now. Will post it asap smile 
    Only thing I'm seeing is CharacterItemsScrollPosition but it says it isn't scriptable. I guess you could increment that. Easy enough to get the total of character items. Maybe a function like this...

    function scrollItm(b)
     local itm = #(game.CurrentCharacter.CharacterItems)
     -- + --
     if b then and game.CurrentCharacter.ItemsScrollPosition < itm then  -- scroll right
      game.CurrentCharacter.ItemsScrollPosition = game.CurrentCharacter.ItemsScrollPosition + 1
     elseif not b and game.CurrentCharacter.ItemsScrollPosition > 0 then -- scroll left
      game.CurrentCharacter.ItemsScrollPosition = game.CurrentCharacter.ItemsScrollPosition - 1
     end
    end

    ... I've not used it before & it says it's not scriptable, so no idea if it's correct.


     

    Imperator

    7278 Posts

  • #6, by sebastianSunday, 13. August 2017, 22:23 7 years ago
    Here is the method with the interface scroll position:
    mouse wheel UP Action:
    1. Execute a script:
    if Values["inventar_open"].Int == 1 and game.Interfaces["inventory"]:getInt(VInterfaceItemsScrollPosition) > 0 then --if inside inventory and scroll position is not at top row
        local scrollposition = game.Interfaces["inventory"]:getInt(VInterfaceItemsScrollPosition) 
        game.Interfaces["inventory"]:setValue(VInterfaceItemsScrollPosition, scrollposition - 5) --scroll by 5 items up
        startAction(Actions["inventory_draw_up"])
    end

    2. Pause 100ms

    mouse wheel DOWN Action: 
    1. Execute a script:
    if Values["inventar_open"].Int == 1 and (table.maxn(game.CurrentCharacter:getLinks(VCharacterItems)) -15) > game.Interfaces["inventory"]:getInt(VInterfaceItemsScrollPosition) then --if inside inventory and scroll position is at the end (15 = max items on one page)
        local scrollposition = game.Interfaces["inventory"]:getInt(VInterfaceItemsScrollPosition)
        game.Interfaces["inventory"]:setValue(VInterfaceItemsScrollPosition, scrollposition + 5) 
        startAction(Actions["inventory_draw_down"])
    end

    2. Pause 100ms

    The Actions "inventory_draw_up" and "inventory_draw_down" are handling sound effects and play a short animation of the arrow blinking to give visual feedback.

    the name of the interface here is "inventory": you have to replace it if you named your interface otherwise.

    (i used a value to determine if inside inventory. You can also use a condition if you like)

    @AFRLme : maybe this can be added to the script index on the wiki?

    kind regards
    Sebastian

    Thread Captain

    2346 Posts

  • #7, by afrlmeSunday, 13. August 2017, 23:20 7 years ago
    Here is the method with the interface scroll position:
    mouse wheel UP Action:
    1. Execute a script:
    if Values["inventar_open"].Int == 1 and game.Interfaces["inventory"]:getInt(VInterfaceItemsScrollPosition) > 0 then --if inside inventory and scroll position is not at top row
        local scrollposition = game.Interfaces["inventory"]:getInt(VInterfaceItemsScrollPosition) 
        game.Interfaces["inventory"]:setValue(VInterfaceItemsScrollPosition, scrollposition - 5) --scroll by 5 items up
        startAction(Actions["inventory_draw_up"])
    end

    2. Pause 100ms

    mouse wheel DOWN Action: 
    1. Execute a script:
    if Values["inventar_open"].Int == 1 and (table.maxn(game.CurrentCharacter:getLinks(VCharacterItems)) -15) > game.Interfaces["inventory"]:getInt(VInterfaceItemsScrollPosition) then --if inside inventory and scroll position is at the end (15 = max items on one page)
        local scrollposition = game.Interfaces["inventory"]:getInt(VInterfaceItemsScrollPosition)
        game.Interfaces["inventory"]:setValue(VInterfaceItemsScrollPosition, scrollposition + 5) 
        startAction(Actions["inventory_draw_down"])
    end

    2. Pause 100ms

    The Actions "inventory_draw_up" and "inventory_draw_down" are handling sound effects and play a short animation of the arrow blinking to give visual feedback.

    the name of the interface here is "inventory": you have to replace it if you named your interface otherwise.

    (i used a value to determine if inside inventory. You can also use a condition if you like)

    @AFRLme : maybe this can be added to the script index on the wiki?

    kind regards
    Sebastian

    Sure just remind me about it later on in the week. Maybe you would like to provide a template ved & some resource files for it? or maybe some images to go along with the tutorial part of the script?

    P.S: not sure how I missed the ItemScrollPosition field in the wiki. I found the one under the characters section for some reason.

    Imperator

    7278 Posts

  • #8, by sebastianSunday, 13. August 2017, 23:41 7 years ago
    cant do a .ved right now, but made some screenshots:

    edit the Mouse wheel up and down actions

    up/down actions

    optional actions to play sound and animations for audo and visual feedback

    Thread Captain

    2346 Posts

  • #9, by EinzelkämpferSunday, 13. August 2017, 23:42 7 years ago
    @sebastian:
    You see me stunned. The luadocs say that ItemsScrollPosition is not scriptable, so I haven't tried that. I will do so at once.

    Thanks a lot for this hint.

    Edit:
    Works like a charm! And the behaviour is exactly how I wanted it. grin

    PS: In the code boxes above you have to delete the semicolons in the first lines. The screenshots are alright.

    Newbie

    81 Posts

  • #10, by afrlmeMonday, 14. August 2017, 00:13 7 years ago
    @sebastian:
    You see me stunned. The luadocs say that ItemsScrollPosition is not scriptable, so I haven't tried that. I will do so at once.

    Thanks a lot for this hint.

    Edit:
    Works like a charm! And the behaviour is exactly how I wanted it. grin

    PS: In the code boxes above you have to delete the semicolons in the first lines. The screenshots are alright.
    That's some bug with the forum. Sometimes when you post & you have added a code box it adds ; after some of the characters, mostly < or > - no idea why.

    Not scriptable doesn't mean it can't be scripted. Sometimes it just means that the new data won't get stored in the save game data & on load it will load default data contained in the ved/vis xml tables. Though in some cases it's quite literal, but most things can be scripted; even if only temporarily for the current game session.

    Imperator

    7278 Posts

  • #11, by EinzelkämpferMonday, 14. August 2017, 00:22 7 years ago
    Good to know.

    Newbie

    81 Posts