Page 1 of 1

modernReserveItems.lua - SM3DL/SM3DW reserve mechanics

Posted: Tue Sep 29, 2020 7:45 am
by KBM-Quine
credits to the following for massive amounts of code help: rixithechao, Enjl, Hoeloe, PixelPest, and MrDoubleA.
as you'd guess from the title, this aims to make the reserve box function like it does in SM3DL/SM3DW, with some added SMBX mannerisms.
such as:
  • items default to being held (barring some already defined exceptions)
  • auto held when first spawned (configurable)
  • if riding yoshi, any holdable items are placed in yoshis mouth. (given yoshi can eat them in the first place)
  • if in a clowncar, it spawns the npc on the players car on the side the player is facing.
  • can spawn a holdable item while warping, only if the warp allows items.
  • near every aspect is configurable. (see documentation for more)
some scenarios where the player can't use the reserve box:
Spoiler: show
  • if in a launch barrel.
  • all forced animation states. (aside from warping/using a clearpipe) all states can be found here.
  • if a warp doesn't allow items or modernReserveItems.allowHeldItemsInWarps is false.
  • is climbing on a vine. (held only)
  • if yoshi's mouth is full. (held only)
  • if mounted in a boot. (held only)
  • if the player's hands are full. (held only)

this mainly came about as a accessibility option for DA:E, but upon thinking about the best implementation, i figured others may also like said feature.
here's a showcase video for all the action:https://streamable.com/whte3v
documentation: show
this section assumes you have some knowledge of lunalua/lua. if not, then the only thing you need is the next two lines.
to start (as any library would) use this to load it

Code: Select all

local modernReserveItems = require("modernReserveItems")
after which you can be on your way if your content with the default settings.
but if you'd rather do some tinkering, here's a few of available customization options:

Code: Select all

modernReserveItems.setThrowSettings(npcID, {speedX=number, speedY=number, isHeld=bool, isContained=bool, isThrown=bool, containedID=number, isMega=bool, doesntMove=bool, SFX=number or sound file, yoshiSFX=number or sound file, isEgg=bool, ai={ ai1=ai1, ect.}, data={variable=value}, pattern=modernReserveItems.patterns.pattern)
(not every value needs to be set here)
let's go over all that:
  • npcID - fill this with the npc ID you want to change the settings for.
  • speedX/speedY - sets the speedX/Y upon it's spawn.
  • isHeld - is used to determine if the item should be held upon spawning it. set to false if you intend to use one of the two other flags to determine behavior.
  • isContained - (currently only used by the reserve stopwatch) is used to determine misc behavior upon spawning it. set to false if you intend to use one of the two other flags to determine behavior.
  • isThrown - is used to determine if the item should be thrown upon spawning it. set to false if you intend to use one of the two other flags to determine behavior.
  • containedID - (currently only used by the reserve stopwatch) sets what the item is contained in. you can read more here under "Forced State" in the offsets. (cannot be used with isHeld while riding yoshi.)
  • isMega - (currently only used by the mega mushroom) changes how the positioning of the npc is done upon spawning.
  • doesntMove - (only applies to isThrown items.) if the item should not move upon spawning. sets the projectile flag for this to work properly, may lead to accidental npc kills. you have been warned.
  • SFX - the sound played upon the npc's spawn. does not play if modernReserveItems.playSounds is false, also doesn't play a sound for isContained items.
  • yoshiSFX - the sound played upon a held npc's spawn while riding yoshi. does not play if modernReserveItems.playSounds is false.
  • isEgg - spawns an egg instead of the npc. to behave properly, it needs ai1 to be set along side it. (currently only used for proper yoshi spawning. lest we forget...)
  • ai - the ai values to be set upon spawning. see this page for more information.
  • data - variables to set in the npc's data fields upon spawn. (not used by anything predefined, mainly added for the neatness of the feature)
  • pattern - settings to borrow from if a field is nil. read on for more on that.
you can also redefine the patterns used by npcs that have them predefined:

Code: Select all

modernReserveItems.patterns.default = {speedX=number, speedY=number, ect.})
worth noting, overwriting the default pattern without filling all fields will more then likely error. if you want to redefine how an aspect of the default table works, use something similar to this:

Code: Select all

modernReserveItems.patterns.default.doesntMove = true
modernReserveItems.patterns.default.data = {string = "text", var = 2, bool = true}
available patterns:
  • modernReserveItems.patterns.default - the fall back pattern. used to either catch any undefined npcs or fill in missing essential fields. it defaults to held npcs.
  • modernReserveItems.patterns.thrown - the thrown npc pattern. does as you'd expect.
  • modernReserveItems.patterns.stationaryPowerup - the pattern used by power ups that don't move. (fire flower, hammer suit, tanooki suit, ice flower.)
  • modernReserveItems.patterns.stationary - throws items above the player. used to get around some of the more annoying npc limitations. (racoon leaf's odd movement, the random smb3 powerup, smb3 fire flower #gdiredigit)
  • modernReserveItems.patterns.mushroom - used solely by mushrooms.
other options include:
  • modernReserveItems.enabled - bool;whether or not the library is allowed to run. good for making it an optional setting. true by default.
  • modernReserveItems.autoHold - bool;if the library is allowed to auto hold the run button for a short time after spawning isHeld npcs. true by default.
  • modernReserveItems.timeAutoHeld- number;how long AutoHold will hold npcs in enabled. 32 by default.
  • modernReserveItems.playSounds - bool;if the library should play sounds upon spawning npcs. true by default.
  • modernReserveItems.playerXMomentum/modernReserveItems.playerYMomentum - number;how much to times the player's speedX/speedY by before adding it to the spawned npc's speedX/speedY. i recommend decimal numbers, such as 0.5 or so. 0 by default.
  • modernReserveItems.allowThrownItems - bool;a flag to disable thrown items from being spawned. good for user edge cases. true by default.
  • modernReserveItems.allowHeldItems - bool;a flag to disable held items from being spawned. good for user edge cases. true by default.
  • modernReserveItems.allowHeldItemsInWarps- bool;a flag to disable held items from being spawned in warps/clearpipes. good for user edge cases. true by default.
  • modernReserveItems.allowContainedItems - bool;a flag to disable isContained items from being spawned. good for user edge cases. true by default.
  • modernReserveItems.allowAnyItems - bool;a flag to disable all items from being spawned. good for user edge cases. true by default.

feel free to suggest things, bug report, or what have you. have a nice day.
Image

Re: modernReserveItems.lua - SM3DL/SM3DW reserve mechanics

Posted: Tue Sep 29, 2020 12:03 pm
by FireSeraphim
This is exactly what I needed!

Re: modernReserveItems.lua - SM3DL/SM3DW reserve mechanics

Posted: Wed Sep 30, 2020 6:48 am
by Jumper
Nice! I'm surprised we didn't get this yet, as it's very useful in general.

There's something that I'd like to see added in SMBX 2.0, and it's Mystery Boxes and its variants, though I'm not going to rush anyone to fulfill this, especially on this post.

Regardless, thanks for making this; this will definitely be helpful for Episodes!

Re: modernReserveItems.lua - SM3DL/SM3DW reserve mechanics

Posted: Mon Jan 25, 2021 2:39 pm
by KBM-Quine
updated with reduced repeat code, changes, fixes, and added features. i must thank MrDoubleA for helping workshop it + the pause bug he found. you can read more about these in the original post, but here's a list of added things:
  • modernReserveItems.timeAutoHeld
  • modernReserveItems.allowHeldItemsInWarps
  • isThrown
  • containedID
  • doesntMove
the mushroom pattern has had doesntMove set to true by default. if you want the old mushroom pattern behavior, drop these lines where applicable:

Code: Select all

modernReserveItems.patterns.mushroom.speedX = 0.5
modernReserveItems.patterns.mushroom.doesntMove = false

Re: modernReserveItems.lua - SM3DL/SM3DW reserve mechanics

Posted: Wed Mar 10, 2021 10:52 pm
by KBM-Quine
small update:
default fields weren't being appended properly if an item had an existing pattern, should be fixed. download updated.
this should now allow you to give npcs spawned by modernReserverItems data fields via the default pattern. useful for manipulating npcs on the fly.