(Request)Is it possible to disable lua scripts when playing a certain character?

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

Shodax
Bot
Bot
Posts: 53
Joined: Sat Feb 05, 2022 2:24 pm
Pronouns: he

(Request)Is it possible to disable lua scripts when playing a certain character?

Postby Shodax » Wed Apr 13, 2022 3:23 pm

Hello. I am using the AnotherPowerup script.lua and trying to modify it so that other characters can use the custom powerups and create sprites, but in what I do I would like to know if there is a way to disable that script when, for example, the player chooses Wario


Code: Select all


local littleDialogue = require("littleDialogue")
local anotherPowerDownLibrary = require("anotherPowerDownLibrary")
<<<      Script that I would like to be deactivated when a chooses an unsupported character[/color]


local ap = require("anotherpowerupSMM2")
ap.registerItemTier(800, true)
ap.registerPowerup("ap_acorn")
ap.registerItemTier(801, true)
ap.registerPowerup("ap_penguinsuit")
local ap = require("anotherpowerup")
ap.registerItemTier(968, true)
ap.registerItemTier(969, true)
ap.registerPowerup("ap_thunderflower")      >>>

local warpTransition = require("warpTransition")
twirl = require("Twirl")

Is there a way to achieve this?

deice
Rocky Wrench
Rocky Wrench
Posts: 638
Joined: Fri Jul 23, 2021 7:35 am

Re: (Request)Is it possible to disable lua scripts when playing a certain character?

Postby deice » Wed Apr 13, 2022 6:08 pm

one thing i immediately notice is that you're overriding (what i assume to be) the library table that stores monochrome's modified anotherpowerup with the default anotherpowerup. on the post for said script, it says "Using an unmodified anotherpowerup.lua file will lead to incorrect and glitchy behavior." so it's best that you move these into two separate variables (not to mention this will likely render the previously registered powerups useless even if this miraculously doesn't overwrite everything inside onInitAPI()? though i haven't tested it myself)
back on topic, the approach here depends on the exact desired effect. if you don't want the libraries to load at all, declare them without assigning to them at the top of the file, and wrap everything else inside a conditional statement:

Code: Select all

local ap_smm2, ap
if(player.character ~= CHARACTER_WARIO) then
	ap = require("anotherpowerup")
	ap_smm2 = require("anotherpowerupSMM2")
	ap.registerItemTier(968, true)
	ap.registerItemTier(969, true)
	ap.registerPowerup("ap_thunderflower")
	ap_smm2.registerItemTier(800, true)
	ap_smm2.registerPowerup("ap_acorn")
	ap_smm2.registerItemTier(801, true)
	ap_smm2.registerPowerup("ap_penguinsuit")
end
the caveat here is that if you are accessing these libraries anywhere else in the code, you have to wrap it with a nil check, for example:

Code: Select all

if(ap) then
	-- access ap fields here
end
if you want don't want to have to do this every time (and it makes no difference to what you're actually trying to do), then you can load the libraries anyway and just move the registering inside the if:

Code: Select all

local ap = require("anotherpowerup")
local ap_smm2 = require("anotherpowerupSMM2")
if(player.character ~= CHARACTER_WARIO) then
	ap.registerItemTier(968, true)
	ap.registerItemTier(969, true)
	ap.registerPowerup("ap_thunderflower")
	ap_smm2.registerItemTier(800, true)
	ap_smm2.registerPowerup("ap_acorn")
	ap_smm2.registerItemTier(801, true)
	ap_smm2.registerPowerup("ap_penguinsuit")
end
hope this helps

Shodax
Bot
Bot
Posts: 53
Joined: Sat Feb 05, 2022 2:24 pm
Pronouns: he

Re: (Request)Is it possible to disable lua scripts when playing a certain character?

Postby Shodax » Sun Apr 17, 2022 5:59 pm

thank you very much served the perfection


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari