Item highlights

  • #1, by divas1980Tuesday, 03. June 2014, 13:17 11 years ago
    hi it's me again!
    I have a doubt for objects. I created some objects in the item. I wanted to make sure that when you passed the mouse over the object changed appearance with a slight edge. In actions on the object not find any enter or over object for chante image.
    How can I do?
    Thank you and sorry for my noob!

    Newbie

    46 Posts


  • #2, by afrlmeTuesday, 03. June 2014, 13:30 11 years ago
    are you talking about items in the inventory or scene objects?

    there is no inactive/active states for inventory items but I was planning on suggesting it for vs4.1, among with some other things.

    for now you could create an animation & force which animation frames should be shown by default & update which animation frames should be shown on mouse over/out.

    bit of a pain to do & I've just woken up not long ago, so I've not got my thinking cap on for creating an example right now.

    Imperator

    7285 Posts

  • #3, by divas1980Tuesday, 03. June 2014, 13:54 11 years ago
    tk for answer smile y ,was for items in the inventory. My problem is that in items section (the icon with the soccer ball) ,in action i dont find in list a enter area or leaves area.red

    i post a image

    Newbie

    46 Posts

  • #4, by afrlmeTuesday, 03. June 2014, 14:00 11 years ago
    Seems to be the case... same in my build but I have options for mouse wheel up, down & click in mine. You still using 3.7.1 or the 4.0 beta?

    Anyway it might not have mouse over/out action but can still be done via lua by checking if an item is currently under the cursor.

    Imperator

    7285 Posts

  • #5, by divas1980Tuesday, 03. June 2014, 16:20 11 years ago
    4.0 beta

    Newbie

    46 Posts

  • #6, by afrlmeTuesday, 03. June 2014, 17:42 11 years ago
    there was an RC release a few weeks back... just letting you know, in case you didn't already know. wink

    there will be another release shortly, with some more bug fixes.

    Imperator

    7285 Posts

  • #7, by divas1980Tuesday, 03. June 2014, 17:57 11 years ago
    ok tk! for the moment wait the new realease also grin

    tk !

    Newbie

    46 Posts

  • #8, by SimonSTuesday, 03. June 2014, 18:30 11 years ago
    I have written a script, that implements that. You just need to have an animation for the item with 2 frames. It's a definition script.
    oldItem = nil
    function mainLoop()
      local curObj=game:getLink(VGameCurrentObject)
      if oldItem~=nil then
        oldItem:setValue(VAnimationFirstFrame,1)
        oldItem:setValue(VAnimationLastFrame,1)
        oldItem=nil
      end
      if curObj:getId().tableId==eObjects then
       if curObj:getBool(VObjectIsItem) then
        local act = getObject("ActiveAnimations["..curObj:getName().."]")
        act:setValue(VAnimationFirstFrame,2)
        act:setValue(VAnimationLastFrame,2)
        oldItem = act
       end
      end
    end
    function animStartedH(anim)
      local data = anim:getLink(VAnimationSavedObject)
      local curObj = data:getParent()
      if curObj:getId().tableId==eObjects then
       if curObj:getBool(VObjectIsItem) then
        anim:setValue(VAnimationFirstFrame,1)
        anim:setValue(VAnimationLastFrame,1)
       end
      end
    end
    registerEventHandler("animationStarted", "animStartedH")
    registerEventHandler("mainLoop","mainLoop")
    

    Thread Captain

    1591 Posts

  • #9, by afrlmeTuesday, 03. June 2014, 18:43 11 years ago
    Why the mainLoop though Simon? could also be done via the mouseEvent handler? makes no real difference though really I guess. I try (myself) to avoid using the mainLoop handler when possible.

    I actually wrote a similar script ages ago for Reemus 2... I think the script is on my old laptop though.

    Speaking of inventory related scripts... I wrote 2 useful ones over the weekend. One lets you insert a new item before or after an existing item in the characters inventory & the other lets you swap an item in the inventory for another one, which is useful for items that have multiple states. i.e: a bucket with an hole in it that loses water over time.

    http://wiki.visionaire-tracker.net/wiki/Insert_Item_(CMS)
    http://wiki.visionaire-tracker.net/wiki/Replace_Item_(CMS)

    Imperator

    7285 Posts

  • #10, by SimonSTuesday, 03. June 2014, 19:10 11 years ago
    I really don't care with these things about if that is called just every second frame or every frame, because Lua is now very efficent, not like the times before.

    Very useful scripts you have there. But why all these tables, would be much easier with locals and I don't think these vars are persistent, so you would need to keep them and at the same time not save them.

    Thread Captain

    1591 Posts

  • #11, by afrlmeTuesday, 03. June 2014, 19:49 11 years ago
    the tables are same as the variables but they are all the same table. & temporary. I don't need the data to be saved, hence the use of the temporary local table, each time the function is called, it updates the data inside of the tables.

    sure I could have created empty local variables outside of the function but I wouldn't use them on the inside of a function as it creates a new table entry each time you call local inside of a function & not much point in that! wink

    I know Lua is pretty efficient now & I enjoy using whenever I can instead of using the pre-made editor action parts as it is just far quicker to type a few lines of code than it is to click here & there.

    Here's my version of the script you wrote above...
    prevItem = nil -- initial value of previously highlighted item
    
    function checkItemStatus()
     if prevItem ~= nil then prevItem:setValue(VAnimationFirstFrame, 1); prevItem:setValue(VAnimationLastFrame, 1); prevItem = nil end
     -- + --
     if game:getLink(VGameCurrentObject):getId().tableId == eObjects then
      if game:getLink(VGameCurrentObject):getBool(VObjectIsItem) then
       prevItem = getObject("ActiveAnimations[" .. game:getLink(VGameCurrentObject):getName() .."]"); prevItem:setValue(VAnimationFirstFrame, 2); prevItem:setValue(VAnimationLastFrame, 2)
      end 
     end
    end
    
    function onMouseEvent(eventType)
     if eventType == eEvtMouseMove then checkItemStatus() end
    end
    
    registerEventHandler("mouseEvent", "onMouseEvent", {eEvtMouseMove})
    

    my version uses the mouseEvent handler instead & is a little more compact.

    I'm not sure if you told him or not but he needs to add a line of code to the first frame of each item's animation to force it to only play the first frame.
    getObject("ActiveAnimations[item_name]"):setValue(VAnimationLastFrame, 1)
    

    Imperator

    7285 Posts