IdleAnimations.lua

Share and discuss custom LunaLua code and content packs for SMBX2.
Master of Disaster
Rex
Rex
Posts: 35
Joined: Sun Nov 28, 2021 9:29 am
Flair: Average Koopa Fan
Pronouns: he/him

IdleAnimations.lua

Postby Master of Disaster » Wed Mar 15, 2023 1:08 pm

----- IdleAnimations.lua v1.1 -----
If you think people will do something else while playing your episode (or the actual reason you want this, if you just like polish), this library is for you!
Make Mario taunt you, Luigi get pranked, make Toad cook, or let them blink or look at you; give your characters a little bit more life!

---- What changed in version 1.1? ----
Mostly bug fixes:
- Fixed an issue where sometimes Tie-ins give an error at the start of the level.
- Added IdleAnimations.IdleCooldown. Change this to have a longer waiting time after finishing an idle animation
- Fixed an issue where sometimes an idle animation plays right after another if it repeats at least once
- Idle Animations don't play anymore when holding something or riding a Yoshi/Shoe.
- Fixed multiple issues with IdleAnimations.playAnim().
- IdleAnimations.playAnim() also can't get interrupted anymore. (It's tie-ins still do, though!)

See some examples of the characters doing their own thing:
Spoiler: show
When Mario is bored...
Image

Those boos are traumatising...
Image

What is he cooking?
Image

What you have to use when working with this library:
Spoiler: show
IA = require("IdleAnimations") -- first you'll have to load the library

To register an idle animation, use this function (preferably in function onStart()):
IA.registerIdleAnimation(
[IdleAnimationName],
[Graphics File;] Graphics.loadImageResolved("[yourFilename]"),
[Amount of Frames of your spritesheet],
[Time you need to be idle until it triggers at minimum; if it's -1 it will not trigger by staying idle],
[Maximum amount of time you have to wait on top of that (random range)],
[Time your idle animation takes; if 0, it lasts as long as you are staying idle] {[time on frame 1], [time on frame 2], [...]},
[player character; 1 for Mario, 2 for Luigi, 3 for Peach, 4 for Toad aso. (or you can use CHARACTER_MARIO aso)],
[How many the idle animation should repeat itself; if set to -1 it will repeat infinitely as long you are staying idle],
[If the idle animation should stop when you get airborn],
[OPTIONAL: Tie-in: the name of the idle animation that should play next; nil if nothing],
[OPTIONAL: gfxoffsetX: set a different offset than the norm (IA.gfxoffsetX)],
[OPTIONAL: gfxoffsetY: set a different offset than the norm (IA.gfxoffsetY)]
)

To play an Animation (doesn't need to be registered), use this function:
IA.playAnim(
[IdleAnimationName] (string),
[Graphics File;] Graphics.loadImageResolved("[yourFilename]"),
[Amount of Frames of your spritesheet] (number),
[(useless, but needs to be set anyways) Time you need to be idle until it triggers at minimum; if it's -1 it will not trigger by staying idle (number)],
[(useless, but needs to be set anyways) Maximum amount of time you have to wait on top of that (random range) (number)],
[Time your idle animation takes; if 0, it lasts as long as you are staying idle] {[time on frame 1], [time on frame 2], [...]},
[player character; 1 for Mario, 2 for Luigi, 3 for Peach, 4 for Toad aso. (or you can use CHARACTER_MARIO aso)],
[How many the idle animation should repeat itself; if set to -1 it will repeat infinitely as long you are staying idle (number)],
[If the idle animation should stop when you get airborn (true or false)],
[OPTIONAL: Tie-in: the name of the idle animation that should play next; nil if nothing],
[OPTIONAL: gfxoffsetX: set a different offset than the norm (IA.gfxoffsetX)],
[OPTIONAL: gfxoffsetY: set a different offset than the norm (IA.gfxoffsetY)]
)

You can execute code in these functions:

function onIdleAnimation(animName, animFrame, animTimer, animDuration, isRepeating) -- triggers while the idle animation is playing
-- animName: The name of the current Idle Animation
-- animFrame: The frame of the animation. Starts at 0
-- animTimer: A timer that counts up until it plays the next frame
-- animDuration: the amount of ticks the current Frame is shown before proceeding
-- isRepeating: only true when the idle animation repeats itself
end

function onIdleEnd(animName) -- triggers when the idle animation ends
-- animName: The name of the current Idle Animation
end

The following variables can be edited:
IA.isIdle = false / true -- you can manually make the player play an idle animation or stop an idle animation
gfxoffsetX = number -- set the offset so your spritesheet matches with the actual position of the player
gfxoffsetY = number -- ^
gfxwidth = number -- the width of the spritesheet itself. You probably doesn't need to change it, but if you need to, you can!
gfxheight = number -- the height of the spritesheet itself. ^
IdleCooldown = number -- Additional frames the player has to stay idle after finishing an idle animation without interrupting it.

The example level has some examples that should help you get it to work, so I'd recommend you to check out the luna.lua file

Remember to credit me when you use this library.

You want Luigi to drink coffee? Then here you go!
https://www.dropbox.com/scl/fo/ecj64e46 ... jsp4j&dl=0

If you want, for whatever reason, download the older version, here you go, I guess??
https://www.dropbox.com/sh/eaylbku7mh2v ... ElDya?dl=0
Last edited by Master of Disaster on Thu Nov 02, 2023 3:20 pm, edited 1 time in total.

Hoeloe
Foo
Foo
Posts: 1463
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: IdleAnimations.lua

Postby Hoeloe » Fri Mar 17, 2023 8:48 pm

The technical term for these kinda of animations is "idle fidgets". This is a pretty neat idea.

cold soup
Rex
Rex
Posts: 33
Joined: Wed May 13, 2020 8:29 pm
Flair: yeah
Pronouns: he/him
Contact:

Re: IdleAnimations.lua

Postby cold soup » Sun Oct 15, 2023 10:11 pm

i've ran into an issue using this script for my episode. at complete random, i get this error message upon starting a level. from what i can tell this does not happen with the default animations and it still happens even without any other libraries loaded. did i do anything wrong registering my idle animations?
error:
Spoiler: show
Image
code:

Code: Select all

function onStart()
    Player.setCostume(CHARACTER_MARIO,"SMW-Mario")

    -- idle animations ----------------------------------------------

    -- look around
    IA.registerIdleAnimation(
	"Look",
	Graphics.loadImageResolved("spike_idle_look.png"),
	4,
	260,
	0,
	{120,50,120,100},
	CHARACTER_MARIO,									
	0,
	true,
    	"BustAMove",
    	-30,
    	-18
	)

    -- funny dance 
    IA.registerIdleAnimation(
	"BustAMove",
	Graphics.loadImageResolved("spike_idle_bustmove.png"),
	4,
	-1,
	0,
	{10,10,10,10},
	CHARACTER_MARIO,									
	-1,
	true,
   	 nil,
    	-30,
  	  -18
	)
end

Master of Disaster
Rex
Rex
Posts: 35
Joined: Sun Nov 28, 2021 9:29 am
Flair: Average Koopa Fan
Pronouns: he/him

Re: IdleAnimations.lua

Postby Master of Disaster » Sun Oct 29, 2023 7:04 am

hmm I think this has to do with idle animations having multiple parts.
I'll look into that and make an update to try to fix that in the coming week if everything goes well.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 0 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari