(Request)disappear NPC and others appear after finishing a level

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)disappear NPC and others appear after finishing a level

Postby Shodax » Sun Feb 06, 2022 3:33 pm

Sorry I don't know much about lua. But I need one to know how to do something with saveData.
In one of my levels there is an invasion of enemies to the city but after defeating the boss they no longer appear, nor does the boss when the level is passed and the level is re-entered.
It occurred to me that the script would disappear the layer that belongs to the invaders and that it apprehends the layer where the villagers apprehend
When I finish the mission or how else can I achieve this?
first of all, Thanks

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

Re: (Request)disappear NPC and others appear after finishing a level

Postby deice » Sun Feb 06, 2022 6:57 pm

when the boss is killed, trigger an event. then try using the following code:

Code: Select all

local BOSS_EVENT = "boss_killed" --name of event triggered when the boss dies
local ENEMY_LAYER = "enemies" --name of the layer with enemies on it

function onEvent(eventName)
	if(eventName == BOSS_EVENT) then
		SaveData[Level.filename()] = SaveData[Level.filename()] or {}
		SaveData[Level.filename()].missionClear = true
	end
end

function onStart()
	if(SaveData[Level.filename()] and SaveData[Level.filename()].missionClear == true) then
		Layer.get(ENEMY_LAYER):hide(true)
	end
end
this should also be portable across levels should you ever need another level with the same mechanic.
(if it doesn't work, let me know cause i'm typing this off the top of my head haha~)

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

Re: (Request)disappear NPC and others appear after finishing a level

Postby Shodax » Mon Feb 07, 2022 1:17 pm

deice wrote:
Sun Feb 06, 2022 6:57 pm
when the boss is killed, trigger an event. then try using the following code:

Code: Select all

local BOSS_EVENT = "boss_killed" --name of event triggered when the boss dies
local ENEMY_LAYER = "enemies" --name of the layer with enemies on it

function onEvent(eventName)
	if(eventName == BOSS_EVENT) then
		SaveData[Level.filename()] = SaveData[Level.filename()] or {}
		SaveData[Level.filename()].missionClear = true
	end
end

function onStart()
	if(SaveData[Level.filename()] and SaveData[Level.filename()].missionClear == true) then
		Layer.get(ENEMY_LAYER):hide(true)
	end
end
this should also be portable across levels should you ever need another level with the same mechanic.
(if it doesn't work, let me know cause i'm typing this off the top of my head haha~)


Thank you.
I work wonders, I'll give you credit in my episode.
I made some modifications to show the villagers and remove other things. I leave it in case someone serves it, too

Code: Select all


local BOSS_EVENT = "final" --name of event triggered when the boss dies
local ENEMY_LAYER = "invasores" --name of the layer with enemies on it
local ALLY_LAYER = "toads"
local BLOCK_LAYER = "bloque1"
local PLANTA1_LAYER = "planta1"
local PLANTA2_LAYER = "planta2"
local PLANTA3_LAYER = "planta3"
local JEFE_LAYER = "bowser"

function onEvent(eventName)
	if(eventName == BOSS_EVENT) then
		SaveData[Level.filename()] = SaveData[Level.filename()] or {}
		SaveData[Level.filename()].missionClear = true
	end
end

function onStart()
	if(SaveData[Level.filename()] and SaveData[Level.filename()].missionClear == true) then
		Layer.get(ENEMY_LAYER):hide(true)
		Layer.get(BLOCK_LAYER):hide(true)
		Layer.get(PLANTA1_LAYER):hide(true)
		Layer.get(PLANTA2_LAYER):hide(true)
		Layer.get(PLANTA3_LAYER):hide(true)
		Layer.get(JEFE_LAYER):hide(true)
		Layer.get(ALLY_LAYER):show(true)
	end
end




Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 2 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari