Page 1 of 2

Check Boss Health to Spawn Enemies

Posted: Fri Feb 27, 2015 5:57 am
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.

Re: Check Boss Health to Spawn Enemies

Posted: Fri Feb 27, 2015 6:06 am
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/

Re: Check Boss Health to Spawn Enemies

Posted: Fri Feb 27, 2015 7:26 pm
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

Re: Check Boss Health to Spawn Enemies

Posted: Fri Feb 27, 2015 7:52 pm
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

Re: Check Boss Health to Spawn Enemies

Posted: Fri Feb 27, 2015 7:53 pm
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

Re: Check Boss Health to Spawn Enemies

Posted: Fri Feb 27, 2015 8:35 pm
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

Re: Check Boss Health to Spawn Enemies

Posted: Fri Feb 27, 2015 11:22 pm
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.

Re: Check Boss Health to Spawn Enemies

Posted: Fri Feb 27, 2015 11:32 pm
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

Re: Check Boss Health to Spawn Enemies

Posted: Sat Feb 28, 2015 2:00 am
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.

Re: Check Boss Health to Spawn Enemies

Posted: Sat Feb 28, 2015 11:48 pm
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?