2 button Cursor change on mouseover

  • #1, by mulewaThursday, 17. February, 20:45 4 months ago
    Hello, i have seen in one of the manuals that their are some intersting cursors (see picture)
    I would like to change my cursors in something like this.
    My understanding is that on a mouseover the cursor is changing and than change leftclick and rightclick actions.
    My idea is to have 3 different cursors:
    1. on object (see; use) 
    2. on Character(see; talk to)
    3. on Items (use;use with) + mouseover = see
    inactive cusor is an arrow and the normal go to

    The problem is, how can i change generic on every object, Item, and character the cursor on mouseover

    Newbie

    20 Posts


  • #2, by SimonSSaturday, 19. February, 09:35 4 months ago
    The easiest way is to just use one cusor with multiple frames and a lua script that's selects them based on the object.

    function onMainLoop()
      local anim = ActiveAnimations["cursor"]
      if game.CurrentObject.empty then
        anim.FirstFrame = 1
        anim.LastFrame = 1
      elseif game.CurrentObject.tableId == eObjects then
        anim.FirstFrame = 2
        anim.LastFrame = 2
      elseif game.CurrentObject.tableId == eCharacters then
        anim.FirstFrame = 3
        anim.LastFrame = 3
      end
    end
    registerEventHandler("mainLoop", "onMainLoop")

    Thread Captain

    1543 Posts

  • #3, by mulewaSunday, 20. February, 02:06 4 months ago
    I am still an programming noop but
    in general i understand your idea,
    but it is not working on my side.
    The animation is always stepping all 3 animations in a loop as there were no lua script
    but the script is registered and i always get some errors:
    Unknown data-field "LastFrame" for object (-1,-1) Unnamed.
    I add some pictures, can you please have a look to it and give me a hint what could be wrong.

    Newbie

    20 Posts

  • #4, by SimonSSunday, 20. February, 09:37 4 months ago
    Yeah, the cursor name was just a dummy, the animation name is cursor (active) (you can also see that in the animation tab in the console).

    So change the line to:
    local anim = ActiveAnimations["cursor (active)"]

    Thread Captain

    1543 Posts

  • #5, by mulewaSunday, 20. February, 14:03 4 months ago
    Cool, now it is working,
    for sure the animation of emty i cannot see in the game but in the console also this is working.

    But is there a way to also compare between an object in the scene and an item in the inventory?

    game.CurrentObject.tableId == eObjects
    is triggering now the cursor  on items and objects.
    but i would like to compare between them.

    Newbie

    20 Posts

  • #6, by SimonSSunday, 20. February, 14:04 4 months ago
    Just check

    game.CurrentObject.IsItem

    Thread Captain

    1543 Posts

  • #7, by mulewaSunday, 20. February, 14:48 4 months ago
    so cool thx!!!

    My final code: 

    function onMainLoop()
      local anim = ActiveAnimations["cursor (active)"]
      if game.CurrentObject.tableId == eObjects then
          if game.CurrentObject.IsItem == true then
            anim.FirstFrame = 1
            anim.LastFrame = 1
          else
            anim.FirstFrame = 2
            anim.LastFrame = 2
          end
      elseif game.CurrentObject.tableId == eCharacters then
        anim.FirstFrame = 3
        anim.LastFrame = 3
      elseif game.CurrentObject.empty then
        anim.FirstFrame = 4
        anim.LastFrame = 4
      end
    end
    registerEventHandler("mainLoop", "onMainLoop")

    Newbie

    20 Posts

  • #8, by mulewaSunday, 20. February, 21:58 4 months ago
    small add on to my solution:

    My idea was to have these actions for the Items in the inventory:
    leftclick = use with
    rightclick=use
    mouseover=look

    the problem was that there is no execution-type: cursor enters  Item
    but for the inventory slots there is an execution-type: cursor enters button area
    So i created in every itemslot an action with an Execute script to call my Item-Look-action:

    startAction(game.CurrentObject.Actions["'Look' executed (immediate)"])

    Newbie

    20 Posts

Write post