BossFightComponent destroys game object when deactivated

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

BossFightComponent destroys game object when deactivated

Post by minmay »

Is there any way to prevent a BossFightComponent from destroying itself and its parent game object after deactivating? I have boss fights that I'd like to be able to stop and restart, but I can't do that very easily if the component destroys itself and everything related to it.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: BossFightComponent destroys game object when deactivated

Post by GoldenShadowGS »

I don't really have the time at the moment to figure out a solution for your question. But off the top of my head you can probably dynamically spawn a new bossfight if the old one is destroyed when turned off.
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: BossFightComponent destroys game object when deactivated

Post by GoldenShadowGS »

It was pretty easy to figure out once I had time to investigate. Try this code:

Code: Select all

function start()
	if myboss == nil then
		spawn("boss_fight", self.go.id.level, 0, 0, 0, 0, "myboss")
		myboss.bossfight:addMonster(mimic_1.monster)
		myboss.bossfight:setMusic("boss_fight_generic")
		myboss.bossfight:setBossName("Mimic")
		myboss.bossfight:activate()
	end
end

function stop()
	if myboss ~= nil then
		myboss.bossfight:deactivate()
	end
end
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: BossFightComponent destroys game object when deactivated

Post by minmay »

Well yeah, of course you can respawn the entire object. Duh. That's what my system currently does. But I was hoping to actually take advantage of the component system and attach a BossFightComponent to an object that also has a floor trigger, a script, etc. to make the logic cleaner.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: BossFightComponent destroys game object when deactivated

Post by GoldenShadowGS »

I misunderstood. Anyway, that behavior is likely hardcoded to clean up the parent entity when the boss fight is deactivated.
Post Reply