Detecting multiple enemy deaths

Need help with any SMBX game-related issues? Ask your questions here.

Moderator: Userbase Moderators

Dinoman972
Shy Guy
Shy Guy
Posts: 6
Joined: Mon Mar 11, 2019 4:15 pm

Detecting multiple enemy deaths

Postby Dinoman972 » Mon Mar 11, 2019 4:59 pm

Hi, everyone! I got started in SMBX2 recently and I'm working on an episode, but I have a little problem. Basically, I want to make a boss fight where the player has to fight two enemies at once, which would end after both are defeated. This should be possible if both enemies are sharing a layer, but I have to use separate layers for each in order for their "hurt states" (you know, those short invicibility frames after you damage them that are seen in bosses such as Boom Boom and Birdo) to work. My question is: is there any other way to trigger an event when both enemies are defeated?

Thanks in advance.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Detecting multiple enemy deaths

Postby Emral » Mon Mar 11, 2019 5:44 pm

You can use a little lua workaround. Make a file called lunadll.lua inside your level folder (the folder with the name of the level, where you put custom graphics in), and paste the following inside:

Code: Select all

--Change the variables here so that the text in quotation marks matches the names of the "Death" events of the boss NPCs
local firstLayerDeathEvent = "REPLACE THIS"
local secondLayerDeathEvent = "REPLACE THIS TOO"

--Change the variable here so that the text in quotation marks matches the name of the event you would like to be executed when both NPCs died.
local bothDeadEvent = "REPLACE THIS AS WELL"

local firstEnemyDefeated = false
local secondEnemyDefeated = false

function onEvent(eventname)
	if eventname == firstLayerDeathEvent then
		firstEnemyDefeated = true
	elseif eventname == secondLayerDeathEvent then
		secondEnemyDefeated = true
	end
	
	if firstEnemyDefeated and secondEnemyDefeated then
		firstEnemyDefeated = false
		secondEnemyDefeated = false
		triggerEvent(bothDeadEvent)
	end
end
Make sure to replace the marked sections, too.

What this code does is keep track of which enemies have been defeated, and triggers an event as soon as both are defeated. OnEvent is a function that runs every time any SMBX event is called.

Dinoman972
Shy Guy
Shy Guy
Posts: 6
Joined: Mon Mar 11, 2019 4:15 pm

Re: Detecting multiple enemy deaths

Postby Dinoman972 » Tue Mar 12, 2019 11:42 am

Alright, I'll try. Thank you very much for the help!

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Detecting multiple enemy deaths

Postby Emral » Tue Mar 12, 2019 11:46 am

I just noticed the forum formatting has broken the newlines on the default theme. For safety, I have copied it to a hastebin link where it's formatted properly.
https://hastebin.com/xesasusoje.lua

Dinoman972
Shy Guy
Shy Guy
Posts: 6
Joined: Mon Mar 11, 2019 4:15 pm

Re: Detecting multiple enemy deaths

Postby Dinoman972 » Sat Mar 16, 2019 5:26 am

Alright, it works now! It kinda messed up the dialogue, for some reason, but I think I'll be able to fix that. Thanks, again!

Theopold1
Goomba
Goomba
Posts: 3
Joined: Fri Aug 14, 2020 7:39 am
Flair: Ameteur Programmer
Contact:

Re: Detecting multiple enemy deaths

Postby Theopold1 » Fri Aug 14, 2020 7:47 am

Dinoman972 wrote:
Mon Mar 11, 2019 4:59 pm
"...This should be possible if both enemies are sharing a layer..."
I want to know how to make a door spawn when all enemies are killed on one layer, myself! By the way, The enemies are Bot(Cyan), Charging Chuck, Wosu, and Hammer Bro, and I want to use characters such as Link, Bowser, Samus, and Mega.
Edit: There's nothing else on that layer, by the way.
Last edited by Theopold1 on Fri Aug 14, 2020 8:06 am, edited 1 time in total.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9890
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Detecting multiple enemy deaths

Postby Emral » Fri Aug 14, 2020 4:46 pm

Set each enemy's "no more objects on layer" event to an event that shows the door layer. An enemy carries out that event if it detects no more objects being on its layer.


Return to “Help and Support”

Who is online

Users browsing this forum: No registered users and 5 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari