libsota - a helper library in lua for Shroud in lua.

Discussion in 'Lua Discussions' started by CatweazleX, Nov 14, 2019.

Thread Status:
Not open for further replies.
  1. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    I'm using your example from above...
    only difference is the name of the file.
     
  2. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
    Are you on Linux? Then you need to create a file named "Lua\error.png" in the <datafolder>. There is a bug with ShroudLoadTexture. This bug is reported and still present in QA900
    Another idea for Linux user is, to create a subfolder in the Lua directory and create a symlink in the <datafolder> that points to that subfolder. (eg.cd <datafolder>; mkdir Lua/share; ln -s Lua/share "Lua\share"). Then place the files in that subdirectory and load them from there (eg. ui.texture.add(0,0,"share/error.png")
     
  3. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
    ui.module and its utility functions will be move out of libsota. I will made this available as an extra lua script.
    There are also some issues with this. Require does not work as expected. Require can not be used earlier as ui.onInit is invoked. But i think that it is expected to use require at the top of a script, and that will very likely not work.
    I also do not want to invest to much time into this in favour of ui elements.
    For now, please place the libsota scripts directly in the Lua folder, so they are autoloaded by the game.
     
  4. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    Guilty

    Moving and renaming the file worked, but I couldn't get the symlinking idea to work at all.
     
  5. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    Do you have a link to that bug report? I can't find it in bug forums.
     
  6. Alley Oop

    Alley Oop Bug Hunter Bug Moderator

    Messages:
    15,679
    Likes Received:
    19,469
    Trophy Points:
    153
  7. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    @Alley Oop Thanks.
    It is so annoying not being able to search for 'lua' (or any three letter words) in the forums.
     
    StarLord and Anpu like this.
  8. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
    libsota.0.5.d
    New stuff in the dev folder.
    Sorry that it takes so long, but sometimes my boss want, that i work for him.

    For Linux users: open terminal.
    Code:
    cd <datafolder>
    mkdir Lua/share
    ln -s Lua/share "Lua\share"
    
    It assumes your Lua folder is named Lua (not lua or other casing)

    uitest.lua contains example code.
    Windows are moveable via mouse and offer the following events: onMouseEnter, onMouseLeave, onMouseMove and onMouseButton
    The dev version does not contain ui.module

    -----
    @Chris wrote on twitter that he will work on LUA : https://mobile.twitter.com/catnipgames
    I would be happy if there is something new in discord, that someone post it here. I still not know where to find the official docu. (at least function descriptions) Currently i get it from here: https://docs.google.com/document/d/1B24KOsc8dT-VZluxPMo3UgBPjyoCCT3IHMmDsT2kxUM/edit
    But that the io object and loadsafe is working i only get through the code from @devilcult

    ------
    i am on Linux, too :D
     
    Last edited: Dec 10, 2019
  9. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    How is the player object intended to be used? I am trying to use it for setting up my own tables but it does not seem to be initialised. i.e. player.name returns 'none' not the name of the current avatar
     
  10. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
    The player object should be initialized when ui.onInit is called. There is also a ui.onPlayerChanged event, that is called when something has changed in the player object. The player object is also a global variable/table that is maintained by libsota (incl. changes).

    If you want to store the player.name in one of your variables you may use it like this:
    Code:
    mytable = {}
    function ShroudOnStart()
       ui.onInit(function()
          mytable.playername = player.name
      end)
    end
    
    If you are interested in changes (flagging, name/character changed):
    Code:
    mytable = {}
    function ShroudOnStart()
       ui.onPlayerChanged(function(what)
          --- name, caption, flagging
          if what == "caption" then
            mytable.playername = player.name
            ....
          end
       end)
    end
    
    You can also send in the part of the code and i'll have a look at it. (PM or forum)
     
    Anpu and Paladin Michael like this.
  11. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    Thanks for the reply, it was helpful getting me started with that.

    Is the ui.onPlayerChanged() event called every time there is a change or just once?

    You might want to rethink that name. It's not when the Player changes, it's when their data changes. Only thought about that as I'm actually trying to detect when the Avatar is changed.
     
    Last edited: Jan 3, 2020
  12. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
    It is called whenever a change occurred. The "what" argument can contain:
    "caption" - player caption has changed (name, flagging)
    "moving" - player has start moving
    "standing" - player has stopped moving
    "stillness" - player has stillness bonus (stand around / don't has moved for more then 5 seconds)
    "location" - players location has changed (player.location x, y and/or z has changed). The new location is given as second argument.
    "damage" - the players health or focus are about to change. The "new" health and focus are given as second and third argument. The "old" values are available in player.health and player.focus. *
    "inventory" - the players inventory has changed. The second argument is the changeset. **

    * to compute the health / focus difference use health.current - player.health.current (it is positive when there was a heal or regen and negative when damage was taken). same for focus
    ** the changeset is a "array" of tables. A table contains the fields quantity and action. Currently only amounts of items are watched, durability changes are planned
    Code:
    function ShroudOnStart()
      ui.onPlayerChanged(function(what, arg1, arg2)
        if what == "damage" then
          -- arg1 = health, arg2 = focus
           local diff = arg1.current - player.health.current
           if diff > 0 then
               ui.consoleLog("You are healed by "..diff.." points")
           else
               ui.consoleLog("You gotten hit for "..(diff * -1).." points")
           end
        elseif what == "inventory" then
            -- arg1 = changeset
            for itemname, what in next, arg1 do
               ui.consoleLog(string.format("%s %d %s", itemname, what.quantity, what.action))
            end
        end
      end)
    end
    
    ui.onPlayerMove(action, loc) - action = "stop", "start", "move" or "stillness". loc is the location, same as player.location. Can be used instead of ui.playerChanged() what = "standing", "moving", "location" and/or "stillness"
    ui.onPlayerDamage(health, focus) - can also be used instead of ui.onPlayerChanged() what = "damage"
    ui.onPlayerInventory(changeset) - can also be used instead of ui.onPlayerChanged() what = "inventory"
     
    Last edited: Feb 21, 2020
    Browncoat Jayson likes this.
  13. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    It appears you have not accounted for players logging out to menu, switching avatars and returning to game. When I try \info player, it does not work. Should I assume the other player data is tied to the original avatar that is registered during script start up?
     
  14. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
    That is a problem with the command object, the ui events and player object works as expected. The commands does not update the player name, who is allowed to use them, upon character change.
    There is also another bug i need to fix.
     
  15. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    @CatweazleX is the onPlayerInventory event working or still in development?
    It seems to work intermittently, but I do not know what is causing it to fail.
     
    Last edited: Feb 20, 2020
  16. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
    The onPlayerInventory event should work.
    What you want to do with it? You have some code i may can look at?
     
  17. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    I'm trying to recreate the functionality you have in the ui_getPlayerInventory() function that determines if an item has been added, removed, or updated. My ShroudOnStart looks like this:


    ui.onInit(
    function()
    ShroudConsoleLog("Test script started.")
    table.sort(player.inventory,
    function(item1, item2)
    return compareItems(item1, item2)​
    end​
    )

    oldInventory = player.inventory

    ui.onConsoleCommand(
    function(source, cmd, tail)
    CommandParse(source, cmd, tail)​
    end​
    )

    ui.onPlayerInventory(
    function()
    ShroudConsoleLog("onPlayerInventory WORKED!!")
    --ChangedInventory()​
    end​
    )​
    end​
    )

    As you can see I have commented out a function call (ChangedInventory()). When it is commented out, the debug text is always output. When it is not commented it works intermittently, this makes me think it is a problem in my code. I narrowed it down that far last night ;)

    Am I trying to reinvent the wheel here? Is that functionality available outside that function?
     
  18. CatweazleX

    CatweazleX Avatar

    Messages:
    653
    Likes Received:
    777
    Trophy Points:
    93
    Location:
    Veritas Sanctuary
    The onPlayerInventory gives you the changeset as parameter. You do not need to recreate the functionality to determine what has changed.
    Code:
    ui.onPlayerInventory(function(changeset)
            for itemname, what in next, changeset do
               ui.consoleLog(string.format("%s %d %s", itemname, what.quantity, what.action))
            end
    end)
    
    That should show you what happend on the console.
     
    Last edited: Feb 21, 2020
  19. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    Excellent, thank you.
     
  20. Archer

    Archer Avatar

    Messages:
    285
    Likes Received:
    196
    Trophy Points:
    40
    Location:
    UK, EU, Terra
    By the way, is changeset sorted?
     
    Last edited: Feb 21, 2020
Thread Status:
Not open for further replies.