Check Boss Health to Spawn Enemies

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!
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Check Boss Health to Spawn Enemies

Post by Emera Nova »

I'm trying to figure out what code I would need to use to check the health of a boss and spawn in or open up a door as it reaches certain lifepoint amounts.

Basically wanting to make it so each time the boss drops down 25% of its overall hp it will open a door releasing in a few smaller enemies.
Eburt
Posts: 69
Joined: Thu Feb 05, 2015 5:44 am

Re: Check Boss Health to Spawn Enemies

Post by Eburt »

MonsterComponent:getHealth()

Also, you might find the scripting reference to be a useful aid in endeavors like this: http://www.grimrock.net/modding/scripting-reference/
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Check Boss Health to Spawn Enemies

Post by Emera Nova »

So I'm attempting to build the script around the MonsterComponent:getHealth() command, and it keeps throwing up errors all over the script.
SpoilerShow
function CheckHealth()
if MonsterComponent:getHealth() = 750 then
dungeon_door_stone_1.door:open
else
dungeon_door_stone_1.door:close
end
As you can guess I literally have no Idea what I'm doing when it comes to creating my own scripts, that scripting reference thing ends up just confusing me more than helping. :s
User avatar
lot
Posts: 4
Joined: Mon Feb 23, 2015 6:22 pm

Re: Check Boss Health to Spawn Enemies

Post by lot »

Let's assume your monster's id is monster_1. Then script will look like following
SpoilerShow
function CheckHealth()
if monster_1.monster:getHealth() < 750 then
dungeon_door_stone_1.door:open()
else
dungeon_door_stone_1.door:close()
end
Analogically to "door" being a DoorComponent of dungeon_door_stone_1 object, "monster" is MonsterComponent of every monster object
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Check Boss Health to Spawn Enemies

Post by JKos »

Edit: ..lot beated me...
It's not that far away from working solution, this should do the trick.

Code: Select all

function CheckHealth()
if MonsterComponent:getHealth() <= 750 then
dungeon_door_stone_1.door:open()
else
dungeon_door_stone_1.door:close()
end
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Check Boss Health to Spawn Enemies

Post by Emera Nova »

:o Sweet I'll plug that in shortly, so if I wanted to make it so it did that a few more times the code would be
SpoilerShow
function CheckHealth()
if monster_1.monster:getHealth() < 750 then
dungeon_door_stone_1.door:open()
else
dungeon_door_stone_1.door:close()
end
if monster_1.monster:getHealth() <500 then
dungeon_door_stone_2.door:open()
else
dungeon_door_stone_2.door:close()
end
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Check Boss Health to Spawn Enemies

Post by Emera Nova »

So I plugged in

Code: Select all

function CheckHealth()
	if Golem.monster:getHealth() <= 750 then
	dungeon_secret_door_49.door:open()
	else
	dungeon_secret_door_49.door:close()
end
And where it says end, the editor throws up an error. 'end' expected (to close 'function' at line 1) near '<eof>'

What does that mean :o I kept the format the same as the suggested codes above and it seems to have broken.
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Check Boss Health to Spawn Enemies

Post by Zo Kath Ra »

Emera Nova wrote:So I plugged in

Code: Select all

function CheckHealth()
	if Golem.monster:getHealth() <= 750 then
	dungeon_secret_door_49.door:open()
	else
	dungeon_secret_door_49.door:close()
end
And where it says end, the editor throws up an error. 'end' expected (to close 'function' at line 1) near '<eof>'

What does that mean :o I kept the format the same as the suggested codes above and it seems to have broken.
you need two "end" statements
one for the "function" statement
and one for the "if" statement
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Check Boss Health to Spawn Enemies

Post by Emera Nova »

Welp, I didn't think this thru all the way xD, so it has to exactly hit 750 hp otherwise nothing happens.. What do I do if I want to have it open if it's health is below a certain lifepoint range and stay open after that point.
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Check Boss Health to Spawn Enemies

Post by Zo Kath Ra »

Emera Nova wrote:Welp, I didn't think this thru all the way xD, so it has to exactly hit 750 hp otherwise nothing happens.. What do I do if I want to have it open if it's health is below a certain lifepoint range and stay open after that point.
When/how do you check the boss's health?
Post Reply