lua check item

  • #1, by sebastianSaturday, 31. October 2015, 17:45 9 years ago
    hey guys. short question regarding the data structure:

    when i use the "set item" action part (dragged item not ticked), in which datastructure object is this saved? (and how do i get/set it?)
    I want to use it in a loop where the cursor is permanently changed regarding which item is set but not using dragged items (so instead using a cursor representation).


    kind regards
    Sebastian

    Thread Captain

    2346 Posts


  • #2, by afrlmeSaturday, 31. October 2015, 18:39 9 years ago
    There's currently no available Lua script method for setting cursors. They can only be set via action part in editor.

    As for the currently held item...
    game.UsedItem
    

    ... will return the currently held item or nil (empty). I recommend adding :getName() to the end of the line though so that it only returns the string name of the item instead of the entire id, tableid & name etc.

    To set the cursor via a script you would need to create some called by other actions which contain set cursor action parts. You would need to name them something relevant so that when you execute a function it would update the cursor based on the returned string of the currently held item name.

    local itm = nil
    
    function cursorLoop()
     if not game.UsedItem:isEmpty()
      if game.UsedItem:getName() ~= itm then
       itm = game.UsedItem:getName(); startAction(Actions["cur_" .. itm])
      end
     elseif game.UsedItem:isEmpty() and itm ~= nil then
      itm = nil; startAction("Actions[cur_default]") -- replace default with name of default cursor 
     end
    end
    
    registerEventHandler("mainLoop", "cursorLoop")
    

    Long story short: you need to create some called by other actions somewhere in your ved & add the prefix cur_ to them followed by the exact name of each item. Remember that table / object names are case sensitive. As for the script... what that is doing is listening out for when an item is held & if the item is not the same as the variable itm then it updates the variable to the new item then calls the relevant called by other action to set the cursor. I know this is a pain in the arse method, but without being able to set cursors directly via Lua script, it's about the only way you can sort this out at the minute.

    Imperator

    7278 Posts

  • #3, by sebastianSaturday, 31. October 2015, 19:29 9 years ago
    Hey, thanks for the quick reply.
    Calling a action is ok for me.

    Backstory to that idea is my item dragging with inactive/active state. Problem was that the active state was set also on the item inside the inventory (of course).
    Idea is now to use the normal "no dragging" stuff and simulate the dragging via the cursor. Its a bit more work and i have to revisit every object and change the item drop actions to an executed command action but i think in the end it will look good. smile

    Thread Captain

    2346 Posts

  • #4, by afrlmeSaturday, 31. October 2015, 19:35 9 years ago
    Yep... you do know you could try using the same method as I am using. Don't bother setting item held. Create commands instead & set them inside of each item inside of an default command executed (immediate) action. The reason why it's nice to use commands is that you can specify the cursor inside of the buttons command properties tab, so when you change to said command it will automatically update the cursor.

    Imperator

    7278 Posts

  • #5, by sebastianSaturday, 31. October 2015, 19:41 9 years ago
    Im not sure if i understand your last comment correctly...
    Setting one command for each item ingame?
    Can you give sime example? Im not sure which method you are referring to...

    Thread Captain

    2346 Posts

  • #6, by afrlmeSaturday, 31. October 2015, 20:45 9 years ago
    Check screenshots & script I posted on this page: http://www.visionaire-studio.net/forum/thread/new-point-clic...

    It's the general idea of how I sort out a custom item / cursor system. It's not the entire thing though as I have if queries in my right click actions for objects to prevent actions being triggered if command is not my standard command. I also have a action in the right button click in mouse properties to reset to standard command if current command is not the standard command.

    It's a little complicated & long winded but you end up with a flawless system that doesn't update mouse cursor on mouse enters / leaves an object if the command does not equal the standard command. Basically if I'm holding something then I don't want it to change my cursor to one of my interaction cursors (use, take, examine, talk, etc).

    As for the right click... I wanted to prevent the right click actions from being executed if the character is stood in the interaction position of said object / character while holding something as I want the item to be dropped first then the command to be reverted back to the standard command.

    As I said it's complicated.

    Imperator

    7278 Posts

  • #7, by sebastianSaturday, 31. October 2015, 21:03 9 years ago
    Ill give it a look and try it out. Thanks so far smile

    EDIT: Ah, i see. you used for every item an own command which gets set when leftclicking (pseudo dragging) the item via a normal left-click.

    But the last part you made there with the update cursor stuff... i dont need this, right? i only need to update the command to the correct item (which is also a command) hwn leftclicking. The cursor is linked to the command, so i dont need a script or anything else i guess....

    EDIT2 : ok i may need this script to check if i really need to change the cursor/command

    Thread Captain

    2346 Posts

  • #8, by afrlmeSaturday, 31. October 2015, 21:11 9 years ago
    Do you have multiple cursors or commands? I don't know what sort of command interface you are using. The one I'm using is a single command interface (Broken Sword), which is left click for interaction & right click to examine or cancel held item.

    I needed the script (well I did before when I was using the command + item held method, but can do with action parts now, but I prefer scripting when possible anyway) to set one of my interaction cursors on mouse over seeing as I'm only using one single command for interaction, however I didn't want it to affect the cursor if an item was currently being held.

    Imperator

    7278 Posts

  • #9, by sebastianSaturday, 31. October 2015, 21:40 9 years ago
    I am using a coin interface like in monkey island 3.
    The normal left click (walk) should be used to "drag" the item.
    I think using for every item a specific commamd (and linked cursor to it) would be the best.

    I only have to add conditions to e.g. doorways where my cursor nirmally changes to an arrowand dont change it whan an "item command" is set.

    Also adding some actions to the right click mouse Option to set the command back to standard.

    Thread Captain

    2346 Posts

  • #10, by afrlmeSaturday, 31. October 2015, 22:43 9 years ago
    Oh the joys of making sure everything runs bug free in Visionaire Studio. Easier said than done! grin

    Imperator

    7278 Posts

  • #11, by sebastianSaturday, 31. October 2015, 22:57 9 years ago
    What do you think is better:
    Setting up commamd for every item and link a cursor to it
    Or
    Only setting up cursors and only change them + setitem action part

    Thread Captain

    2346 Posts