Changing the image of the inventory item when it comes over a scene object?

  • #20, by AkcayKaraazmakFriday, 21. August 2015, 20:42 9 years ago
    I wrote to Simon, hope he will sort it out.

    Great Poster

    440 Posts


  • #21, by sebastianFriday, 21. August 2015, 20:58 9 years ago

    EDITED THE POST + CODE!!!



    i got it working now! But only for ONE item...
    Also that the item in the inventory also gets the active state (of course) is getting on my nerves.
    I thint the best to do here is to replace the just clicked item (to drag it) with an "empty" Item and when combining any item with the "empty" item it gets replaced again....So it isnt duplicated.

    here is the modified script:
    function onItemDrag(eventType)
    
        -- set object under cursor and item which is (maybe) dragged
        local curObj=game:getLink(VGameCurrentObject)
        
        
        if not game.UsedItem:isEmpty() then
    -- if an item gets dragged, get its animation
    local anim = getObject("ActiveAnimations["..game:getLink(VGameUsedItem):getName().."]")
    
    -- if mouse moves over an object or NPC character
    if eventType == eEvtMouseMove and (curObj:getId().tableId == eObjects or curObj:getId().tableId == eCharacters ) then
    -- set animation to second frame
      anim:setValue(VAnimationFirstFrame,2)
      anim:setValue(VAnimationLastFrame,2)
    else
    -- else set animation to first frame to reset it
      anim:setValue(VAnimationFirstFrame,1)
      anim:setValue(VAnimationLastFrame,1)
    end
    
    -- if an item gets dragged and a a CLICK action was used, the animation of the item should also be resetted (scrolling flags was removed from the eventhandler register)
     if eventType ~= eEvtMouseMove and anim ~= nil then
          anim:setValue(VAnimationFirstFrame,1)
          anim:setValue(VAnimationLastFrame,1)
       
     return true
     end 
    
         end
    end
    
    registerEventHandler("mouseEvent", "onItemDrag", {eEvtMouseMove, eEvtMouseLeftButtonDoubleClick, eEvtMouseLeftButtonDown, eEvtMouseLeftButtonUp, eEvtMouseLeftButtonHold, eEvtMouseLeftButtonHolding, eEvtMouseRightButtonDoubleClick, eEvtMouseRightButtonDown, eEvtMouseRightButtonUp, eEvtMouseMiddleButtonDown, eEvtMouseMiddleButtonUp})
    
    
    
    


    I only cant get it working when 2 Items have these animations... Any Ideas?


    EDITED THE POST + CODE!!!

    Thread Captain

    2346 Posts

  • #22, by AkcayKaraazmakSaturday, 22. August 2015, 00:18 9 years ago
    Ovv mate, I tried many ways but couldnt make it work. Achh

    Great Poster

    440 Posts

  • #23, by sebastianSaturday, 22. August 2015, 07:47 9 years ago
    dont forget to set an action in the first frame of any item animation like i wrote on page 1. Also make sure that therr is no "Image" for that item.

    Thread Captain

    2346 Posts

  • #24, by sebastianSaturday, 22. August 2015, 16:55 9 years ago
    i got it working now without errors (i guess). The problem that it worked for only one item, was that the other item(s) had a very high pause[msec] in ther frames, so that it got played even if it should show the active state animation.

    So what you could check, Akçay, are the item properties ^^
    I set mine to 80msec and infinite
    ... code didn't change since last time.

    Make sure this is also an action in the first part of each item:
    Execute Script:
    getObject("ActiveAnimations[my_item_name]"):setValue(VAnimationLastFrame, 1)
    

    change my_item_name to the name of the specific item.

    Thread Captain

    2346 Posts

  • #25, by AkcayKaraazmakSunday, 23. August 2015, 14:22 9 years ago
    Hey bro, when ever I open the inventory, animation with 2 frames for the item starts to play in a loop. Showing the 1st frame and then 2nd and then 1st again.

    And the other thing is, item changed to 2nd frame image on any object on the scene. How we can make it work just on the scene object that we want? smile Too much things bro? smile


    Great Poster

    440 Posts

  • #26, by sebastianSunday, 23. August 2015, 14:33 9 years ago
    to prevent the frame_1 / frame_2 flickering you have to add the above mentioned frame_action to the items, so it stops at the first frame as soon as is shown.

    For making the item only get active on specific objects you have to edit the following if condition:
    if eventType == eEvtMouseMove and (curObj:getId().tableId == eObjects or curObj:getId().tableId == eCharacters ) then
    
    ...
    
    end
    

    maybe add some kind of
    "if used item is ITEM A and current object under cursor is OBJECT B"

    Thread Captain

    2346 Posts

  • #27, by AkcayKaraazmakSunday, 23. August 2015, 14:41 9 years ago
    I wrote this on the first frame of the item's animation as execute script action " getObject("ActiveAnimations[my_item_name]"):setValue(VAnimationLastFrame, 1) " ... But it doesnt stop the animation loop, dont know why :\

    And how I can write "if used item is ITEM A and current object under cursor is OBJECT B" as code, under the modified if eventType == ... ?

    Great Poster

    440 Posts

  • #28, by AkcayKaraazmakSunday, 23. August 2015, 14:42 9 years ago
    Sure I wrote the item name. its "Key"

    Great Poster

    440 Posts

  • #29, by sebastianSunday, 23. August 2015, 15:27 9 years ago
    hmm.... cant guess whats wrong then... you used the object name, not the language text, right?
    can you make some screenshots where you put which scripts?

    --

    Now i try to update my script, so that animated items are also possible. By that i devide the amount of frames in the whole animation by 2. The first frames are for inactive the second for active .
    Expected result: Items like a torch or lighter can be animated and are possible to get an active state.

    Thread Captain

    2346 Posts

  • #30, by sebastianThursday, 27. August 2015, 20:34 9 years ago
    I did a Test project with my script. Maybe you guys can use it and/or improve it more...
    http://cl.ly/3m1T1b0c0J1U
    Every Item needs a Value called FRAMES which is the same amount of Frames inside the whole animation on that item (at least 2. One for inactive state, one for active state).

    Example:
    when you want to have an animated Item with 10 frames, you set that value to 20. Also inside the animation you have the first 10 frames displaying the inactive images and the second 10 the active ones.
    Include the script from the project as a definition script.




    Thread Captain

    2346 Posts