Page 1 of 1

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

Posted: Thu Mar 03, 2022 5:39 pm
by Shodax
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

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

Posted: Thu Mar 03, 2022 9:20 pm
by Marioman2007
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

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

Posted: Sun Mar 06, 2022 1:24 pm
by Shodax
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

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

Posted: Mon Mar 07, 2022 2:49 am
by Marioman2007
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

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

Posted: Mon Mar 07, 2022 2:19 pm
by Shodax
Thanks a lot.

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