(Request)How can I make a script that enables and disables characters on the map?

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)How can I make a script that enables and disables characters on the map?

Postby Shodax » Thu Mar 03, 2022 5:39 pm

help
I've been searching and testing a script:

Code: Select all

local pm = require("playerManager")
 
pm.overworldCharacters = {1,2}


I add this script to map.lua and me and only allows the characters I want. But I have tried that when a certain level is finished or a boss is defeated, a new character can be selected, that it is activated with an event.
So I put this script on one level and it didn't work:

Code: Select all

local pich = {}

function pich.onEvent(eventName)
if eventName == "pich" then
SaveData[Level.filename()] = SaveData[Level.filename()] or {}
		SaveData[Level.filename()].missionClear = true
		pm.overworldCharacters = {1,2,3,4}
end
end

I think you have to put another kind of code in the map.lua that it is activated at the end of a certain level, but I do not know how to do it.


would greatly appreciate the help to make this script

Marioman2007
2025 Egg Hunter
2025 Egg Hunter
Posts: 546
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: (Request)How can I make a script that enables and disables characters on the map?

Postby Marioman2007 » Thu Mar 03, 2022 9:20 pm

I think this will help you

First, declare you SaveData boolean in the global luna.lua file:

Code: Select all

SaveData.myBool = SaveData.myBool or false
then set that boolean to true when you event is activated, in the local luna.lua file:

Code: Select all

function onEvent(eventName)
    if eventName == "pich" then
        SaveData.myBool = true
    end
end
and then set the overworld characters, in map.lua:

Code: Select all

local pm = require("playerManager")

if not SaveData.myBool then
    pm.overworldCharacters = {1,2} -- default characters
else
    pm.overworldCharacters = {1,2,3,4} -- default + unlocked characters
end

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

Re: (Request)How can I make a script that enables and disables characters on the map?

Postby Shodax » Sun Mar 06, 2022 1:24 pm

Marioman2007 wrote:
Thu Mar 03, 2022 9:20 pm
I think this will help you

First, declare you SaveData boolean in the global luna.lua file:

Code: Select all

SaveData.myBool = SaveData.myBool or false
then set that boolean to true when you event is activated, in the local luna.lua file:

Code: Select all

function onEvent(eventName)
    if eventName == "pich" then
        SaveData.myBool = true
    end
end
and then set the overworld characters, in map.lua:

Code: Select all

local pm = require("playerManager")

if not SaveData.myBool then
    pm.overworldCharacters = {1,2} -- default characters
else
    pm.overworldCharacters = {1,2,3,4} -- default + unlocked characters
end

It worked wonders.

thank you very much, I had not been able to get it for a long time.
How much money do I owe you? :lol: :lol: :lol: :lol:

Finally, is it correct if I later want to add another character that joins using this code?

global luna.lua

Code: Select all

SaveData.my2Bool = SaveData.my2Bool or false

local luna.lua

Code: Select all


function onEvent(eventName)
    if eventName == "newchar" then
        SaveData.my2Bool = true
    end
end

map.lua

Code: Select all


if SaveData.my2Bool then
    pm.overworldCharacters = {1,2,3,4,7} 
else
end

if that's not, which is correct?

thanks again

Marioman2007
2025 Egg Hunter
2025 Egg Hunter
Posts: 546
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: (Request)How can I make a script that enables and disables characters on the map?

Postby Marioman2007 » Mon Mar 07, 2022 2:49 am

You should something like this:

Code: Select all

if not SaveData.myBool and not SaveData.my2Bool then
    pm.overworldCharacters = {1,2} -- default characters
elseif SaveData.myBool and not SaveData.my2Bool then
    pm.overworldCharacters = {1,2,3,4} -- default + 1st unlocked characters
elseif SaveData.my2Bool then
    pm.overworldCharacters = {1,2,3,4,7} -- default + 2nd unlocked characters
end

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

Re: (Request)How can I make a script that enables and disables characters on the map?

Postby Shodax » Mon Mar 07, 2022 2:19 pm

Thanks a lot.

How much do I owe you for counseling? :D :D :D :D


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 4 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari