Page 1 of 2

Twirl.lua Rewritten 2.3 (NSMB Midair Spin)

Posted: Mon Jun 04, 2018 11:22 am
by MegoZ_
This script allows the player to twirl like in New Super Mario Bros. Wii/U.
Works for 2 players
v2.2: Now compatible with "dive.lua!"
v2.3: Changed audio file to .ogg and tweaked default settings.
* Press the Alt-Jump/Spin key in mid-air
* Only Mario, Luigi and Toad can do this

The twirl gives you a bit of momentum in mid-air. So it's useful for jumps that aren't high enough to reach certain places in a level, and it can save you from some otherwise hopeless situations.

How to install:
Spoiler: show
1. Extract both "twirl.lua" and the "twirl.flac" together into your episode/level folder.
2. Paste the following line into your level/episode's luna.lua file.

Code: Select all

twirl = require("twirl")

Gif Comparation:
Spoiler: show
The SMB1 coin makes Mario jump, as SMB2 coin triggers the spin key, both Marios are synchronized: Image
Video Preview:
Spoiler: show
Old Version:


Old Version (1.5.0):
Variables:
Spoiler: show
twirl.descent = Int | Sets this to the Y speed WHEN DESCENDING in order to achieve a slower fall.
twirl.impulsePercent = Int | Multiplies this with Y speed WHEN ASCENDING in order to reach a higher jump.
twirl.extraImpulse = Int | Substracts this to Y speed WHEN ASCENDING in order to reach an even higher jump.
twirl.cooldown = Int | Amount of ticks between twirls.

Animation Related:
twirl.frames = Table | Player's sprite sequence
twirl.animSpeed = Int | Animation Speed


Default Values:
Copy and paste these to your luna.lua file if you want to edit them:
twirl.descent = 1.5
twirl.impulsePercent = 1.5
twirl.extraImpulse = 1.3
twirl.cooldown = 10

twirl.frames = {15, -2,-2, 13, 2,2}
twirl.animSpeed = 2
[/code]

Writing this was a good way to spend my time. It has been interesting seeing myself grow up and learn lua every day since I was 16. Each time I went back to this I saw ways to shrink the code and improve my bad habits and It's been 4 years. It's always such a good feeling when something works!

This community has inspired me in a way you can't imagine. And although I barely like to socialize, I really wanted to thank you all so much for inspiring me! :D

Download (Zip file, v2.3):
MEGA: https://mega.nz/file/I9N3ACbR#ZMZASyljR ... wOAknk_aU4
MEDIAFIRE: https://www.mediafire.com/file/58gg94bg ... o.zip/file
Quick Pastebin (Only for Updates): https://pastebin.com/QJ5bFaL6


Re: Twirl.lua (NSMB Midair Spin)

Posted: Mon Jun 04, 2018 11:38 am
by Taycamgame
This looks useful, does it give the player an extra bit of momentum like it did in the NSMB games to allow the player to go a little bit further, or is it just an effect?

Re: Twirl.lua (NSMB Midair Spin)

Posted: Mon Jun 04, 2018 12:12 pm
by MegoZ_
Taycamgame wrote:
Mon Jun 04, 2018 11:38 am
This looks useful, does it give the player an extra bit of momentum like it did in the NSMB games to allow the player to go a little bit further, or is it just an effect?
Oh yeah. I did it intentionally so that when the player press to twirl, give him a bit of momentum.

Edit: I think i haven't said it clearly. Sorry, don't speak english frequently :oops: There's two types of momentum. Before he gets to the top of the jump and when he starts to fall.

When he's about to get to the maximum height after jumping and he presses to twirl in the middle of the action, it cancells the jump in midair and gives him a lower push upward.
When he falls, it restores the Y speed into 1 and removes the speed he gained through the fall.

(Also when i putted 0 instead he could spinjump in air which is a fun fact)

Re: Twirl.lua (NSMB Midair Spin)

Posted: Mon Jun 04, 2018 3:30 pm
by The0x539
Why does your "mem recognition function" use global variables? With the unusual but not-completely-insane structure of your code, it'd work to declare them as local to the whole file.

Conditions don't need to be a comparison.

Code: Select all

if foo == true then
is redundant in the same way that

Code: Select all

if (foo == true) == true then
is. If your value is just a boolean, you can just use `foo` and `not foo`.

Re: Twirl.lua (NSMB Midair Spin)

Posted: Wed Jun 06, 2018 1:55 pm
by MegoZ_
The0x539 wrote:
Mon Jun 04, 2018 3:30 pm
Why does your "mem recognition function" use global variables? With the unusual but not-completely-insane structure of your code, it'd work to declare them as local to the whole file.

Conditions don't need to be a comparison.

Code: Select all

if foo == true then
is redundant in the same way that

Code: Select all

if (foo == true) == true then
is. If your value is just a boolean, you can just use `foo` and `not foo`.
So... You're telling me to use "local function" instead of just a regular one for most of them, and...

Code: Select all

that "if var == false" is the same thing as "if not var"

Code: Select all

and "if var == true" is the same thing as "if var"
If so, i see your point. And it doesn't make much sense that i haven't did it before because i knew it. However, i was scared to make a dumb mistake somewhere, lost the mistake (That doesn't necessarily needs to be a crash), and rewrite for the 4th time.

Re: [1.1] twirl.lua (NSMB Midair Spin)

Posted: Thu Jul 19, 2018 12:50 am
by aero
I noticed you did this with your If statements:

If var == true then
var2 == true
else
var2 == false
end

This can be done on one line like this:
var2 = var

It's a lot easier to keep track of what your code is doing with the second way, and it's generally good practice to do that if your only going to be changing a boolean type within a conditional. For the parts of your code that did this, I rewrote what it would look like with the second format and it should produce the same results as your code but done more concisely.

https://pastebin.com/jyUcPGGN

Re: [1.1] twirl.lua (NSMB Midair Spin)

Posted: Sat Jul 28, 2018 11:48 am
by MegoZ_
GhostHawk wrote:
Thu Jul 19, 2018 12:50 am
I noticed you did this with your If statements:

If var == true then
var2 == true
else
var2 == false
end

This can be done on one line like this:
var2 = var

It's a lot easier to keep track of what your code is doing with the second way, and it's generally good practice to do that if your only going to be changing a boolean type within a conditional. For the parts of your code that did this, I rewrote what it would look like with the second format and it should produce the same results as your code but done more concisely.

https://pastebin.com/jyUcPGGN
I'll use this info on my future projects. This is very useful and can shorten my code. Thanks a lot!

Re: [1.2] twirl.lua (NSMB Midair Spin)

Posted: Sat Apr 13, 2019 1:48 am
by MegaDood
This is so cool. Subtle differences like this might change up the game a bit more.

Re: [1.2] twirl.lua (NSMB Midair Spin)

Posted: Sat Apr 13, 2019 7:09 am
by Eri7
MegaDood wrote:
Sat Apr 13, 2019 1:48 am
This is so cool. Subtle differences like this might change up the game a bit more.
Well i used this script for my cancelled 2.0 project but the people who played it never used the twirl for some weird reason so idk if it will change anything that much.

Re: [1.2] twirl.lua (NSMB Midair Spin)

Posted: Sun Apr 14, 2019 12:06 am
by MegaDood
Eri7 wrote:
Sat Apr 13, 2019 7:09 am
MegaDood wrote:
Sat Apr 13, 2019 1:48 am
This is so cool. Subtle differences like this might change up the game a bit more.
Well i used this script for my cancelled 2.0 project but the people who played it never used the twirl for some weird reason so idk if it will change anything that much.
Huh, that's interesting. I would have thought people would make the most use out of a feature.

midAirTwirl.lua 1.3.1 update!

Posted: Wed Feb 19, 2020 12:25 pm
by MegoZ_
Hey! I just updated this script to be compatible with peach and other characters. Other cool stuff on the changelog which is in the .lua file itself! Just redownload it from the same links provided in the post above!

Re: midAirTwirl.lua (NSMB Midair Spin) 2 PLAYER SUPPORT

Posted: Sun Feb 23, 2020 10:27 pm
by DrLugawi
Hi, I see you're making an experimental ground pound API, if you want, can you post some progress images, or like logs?

Re: midAirTwirl.lua (NSMB Midair Spin) 2 PLAYER SUPPORT

Posted: Mon Feb 24, 2020 5:27 am
by MegoZ_
DrLugawi wrote:
Sun Feb 23, 2020 10:27 pm
Hi, I see you're making an experimental ground pound API, if you want, can you post some progress images, or like logs?
Sadly that groundpound API got lost... I will search for it and if I find it, i will rewrite it since it has a lot of problems

Re: midAirTwirl.lua (NSMB Midair Spin) 2 PLAYER SUPPORT

Posted: Mon Feb 24, 2020 7:07 am
by DrLugawi
MegoZ_ wrote:
Mon Feb 24, 2020 5:27 am
DrLugawi wrote:
Sun Feb 23, 2020 10:27 pm
Hi, I see you're making an experimental ground pound API, if you want, can you post some progress images, or like logs?
Sadly that groundpound API got lost... I will search for it and if I find it, i will rewrite it since it has a lot of problems
That's unfortunate, but if you ever find it'll be awsome to use

Re: midAirTwirl.lua (NSMB Midair Spin) 2 PLAYER SUPPORT

Posted: Thu May 21, 2020 1:55 pm
by Neon358
Is there a version for SMBX 38A 1.4.5? Just curious.

Re: midAirTwirl.lua (NSMB Midair Spin) 2 PLAYER SUPPORT

Posted: Thu May 21, 2020 9:08 pm
by Bomb Kicker DX
As far as i know no

Re: midAirTwirl.lua (NSMB Midair Spin) 2 PLAYER SUPPORT

Posted: Fri May 22, 2020 9:57 am
by Cedur
Will it be also possible to change constantly between normal jump and spinjump, as in the SMW hack Invictus?

Re: midAirTwirl.lua (NSMB Midair Spin) 2 PLAYER SUPPORT

Posted: Fri May 07, 2021 7:46 pm
by MrCool422
MegoZ_... I been using the midAirTwirl.lua And pressing the alt jump button 500 times and still no mid air twirl!

Re: midAirTwirl.lua (NSMB Midair Spin) 2 PLAYER SUPPORT

Posted: Sat May 08, 2021 2:30 am
by Marioman2007
MrCool422 wrote:
Fri May 07, 2021 7:46 pm
MegoZ_... I been using the midAirTwirl.lua And pressing the alt jump button 500 times and still no mid air twirl!
Are you even loading the library.

Re: midAirTwirl.lua (NSMB Midair Spin) 2 PLAYER SUPPORT

Posted: Sun Jun 13, 2021 12:50 am
by MrCool422
Image
Ok so i've reloaded the libary after this happended!