2 button Cursor change on mouseover

  • #1, z mulewaThursday, 17. February 2022, 20:45 hodinky 2 years 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

    Bažant

    21 Posts


  • #2, z SimonSSaturday, 19. February 2022, 09:35 hodinky 2 years 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")

    Kapitán

    1582 Posts

  • #3, z mulewaSunday, 20. February 2022, 02:06 hodinky 2 years 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.

    Bažant

    21 Posts

  • #4, z SimonSSunday, 20. February 2022, 09:37 hodinky 2 years 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)"]

    Kapitán

    1582 Posts

  • #5, z mulewaSunday, 20. February 2022, 14:03 hodinky 2 years 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.

    Bažant

    21 Posts

  • #6, z SimonSSunday, 20. February 2022, 14:04 hodinky 2 years ago
    Just check

    game.CurrentObject.IsItem

    Kapitán

    1582 Posts

  • #7, z mulewaSunday, 20. February 2022, 14:48 hodinky 2 years 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")

    Bažant

    21 Posts

  • #8, z mulewaSunday, 20. February 2022, 21:58 hodinky 2 years 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)"])

    Bažant

    21 Posts