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

  • #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


  • #31, by AkcayKaraazmakFriday, 28. August 2015, 11:01 9 years ago
    Bro this is realy great!!! Thank you so much. You saved many people's lifesmile very appreciate it!

    Great Poster

    440 Posts

  • #32, by afrlmeFriday, 28. August 2015, 16:09 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.






    Hmm why do you need so many frames playing the same thing?

    Simplest solution is 2 frames. 1 for active & 1 for inactive. Inside the first frame (inactive) you create an execute a script action to set the first & last frame of the animation to 1. I don't see the need for having a value.
    -- set animation of currently held item to active frame (2)
    ActiveAnimations[game.UsedItem:getName()].AnimationFirstFrame = 2 
    ActiveAnimations[game.UsedItem:getName()].AnimationLastFrame = 2
    

    You would add that into a on mouse over action part. Resetting the animation is irrelevant as it will automatically reset back to default when you unload it. Well in the case of dragged items anyway. You could always query inside of the animation frames if item is held or not to control which frames should be shown.

    Alternatively you could even setup a Lua table system in conjunction with the mouse event handler & have that listen for when an item is held & when it is currently over an object / character / item interaction polygon.

    Lots of methods.

    P.S: I've not read the entire thread, so what I've written is based on the initial few posts & the final page.

    Imperator

    7278 Posts

  • #33, by sebastianFriday, 28. August 2015, 17:55 9 years ago
    i need the frame value because i want to store the amount of all frames (inactive + active) when the item is ANIMATED (more than 2 frames). By default this is stored inside "AnimationLastFrame" inside ActiveAnimations. But because we are modifying the last frame, this value gets lost.

    I reset the frames to default because i don't know if the animations are really unloaded (when the inventory is visible all time the animation is active all the time)...

    Testproject btw is without animated items...

    Thread Captain

    2346 Posts

  • #34, by tutnichtwehWednesday, 30. August 2017, 06:36 7 years ago
    I'm sorry for my grave desecration of this thread, but I found the topic quite interesting.

    I want to create two items, both actually the "same" just with 5 different symbols on it, beeing chosen in another action. Now I simply could create 10 items with different pictures (5 different pictures for each item) - but thought it would be very more efficient and nicer to just set different animation-frames for the items.
    getObject("ActiveAnimations[big jar]"):setValue(VAnimationFirstFrame, 1)
    getObject("ActiveAnimations[big jar]"):setValue(VAnimationLastFrame, 1)
    

    I've put an action in the first frame and call a script to stop the animation at a desired frame. I'm new to LUA and not able to find my mistake apparently.

    The animation doesn't stop at the desired frame and is looped instead.

    What am I doing wrong?

    Newbie

    11 Posts

  • #35, by sebastianWednesday, 30. August 2017, 08:11 7 years ago
    try this:

    ["animation_name"].AnimationFirstFrame = 1

    ["animation_name"].AnimationLastFrame = 1

    Thread Captain

    2346 Posts

  • #36, by afrlmeWednesday, 30. August 2017, 16:51 7 years ago
    try this:

    ["animation_name"].AnimationFirstFrame = 1

    ["animation_name"].AnimationLastFrame = 1
    You have to put ActiveAnimations if using shorthand @Sebastian.

    ActiveAnimations["example"].AnimationFirstFrame = 1
    ActiveAnimations["example"].AnimationLastFrame = 2


    I highly recommend creating a Lua function that you can use to shorten the amount of code you have to type in the long run.

    -- create a new script in the script section on the editor & add this to it. Leave as definition type script.
    function setAnimFrames(anim, ff, lf)
     ActiveAnimations[anim].AnimationFirstFrame = ff
     ActiveAnimations[anim].AnimationLastFrame = lf
    end

    To use... type something like this inside of an execute a script action block...
    setAnimFrames("hamster_running_wheel", 3, 5) -- set hamster_wheel_running animation to loop between frames 3-5.

    Imperator

    7278 Posts

  • #37, by sebastianWednesday, 30. August 2017, 16:57 7 years ago
    thats odd... i remember having ActiveAnimations in front of it after posting... 

    Thread Captain

    2346 Posts

  • #38, by afrlmeWednesday, 30. August 2017, 17:46 7 years ago
    Maybe you did same thing I do sometimes. My brain reads that I've typed it, but I haven't - or I ended up typing a completely different word than what I was intending to use because something random popped into my head.  

    Imperator

    7278 Posts

  • #39, by tutnichtwehFriday, 01. September 2017, 00:17 7 years ago
    Thank you for your answers!

    I didn't know you could create own functions - this is great!

    ---

    Unfortunately it doesn't work yet and still loops the whole animation. Can it be that the script is looking for an animation - but can't find it?

    Is it possible to name the animations? I know it's possible for objects to have multiple, named animations - but items?

    My brain reads that I've typed it, but I haven't - or I ended up typing a completely different word than what I was intending to use because something random popped into my head.
    Oh, I definitely know that! It happens to me quite often. smile

    Newbie

    11 Posts

  • #40, by afrlmeFriday, 01. September 2017, 00:25 7 years ago
    Whatever you named the item in the editor is what the name will be. The interface has to be active/visible for the animation to be manipulated. Names are also case sensitive when it comes to accessing them with Lua script, so make sure you type the name in the exact same way with capitals, lowercase, underscores, white space, dashes, symbols or whatever the names included.

    Imperator

    7278 Posts