setHealth on a spawned monster

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
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

setHealth on a spawned monster

Post by FeMaiden »

If I spawn a monster using a script, can I then use that same script to setHealth on the monster?

I don't really understand how to make a ghoul rise up from the ground when the party approaches.

when I place them on the map, even in guard mode, they just rise up as soon as the map is loaded.
the only way around it was to put them in spawners so that they don't "spawn" and rise up until the party steps on the trigger.

but the spawner does not allow you to change the monster health.

I recently learned how to spawn a monster out of a script, but can I set it's health from there as well?

like, what I wanted was an encounter where a buttload of ghouls rise up, but they are weaker than normal ghouls, with only 100 health each.
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: setHealth on a spawned monster

Post by Drakkan »

dealing with spawned monsters is little more complicated, I remember some thread around, however cannot find it now. Basically I think you need spawn the monster with script and add it some unique ID - then you can deal with it as regular if I am not mistaken.

If you do not want mess with that, than use just some easy workaround - for example place the real monster somewhere completely locked with teleport on it and just activate the teleport to move the monster where and when you need, which will have the same effect as spawning it.

As for undead, there is component "rise" on it, which is what you are looking for.
Regarding setting the health I am sure you are aware of basic monster components MonsterComponent:setHealth(health) and MonsterComponent:setMaxHealth(health)
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: setHealth on a spawned monster

Post by FeMaiden »

actually,the "put a monster on the map and then teleport it in technique" is something i've been using lately lol.
I've been using that for bosses.

as for the ghoul's "rise" ability. I don't want to turn it off.

I want to appear as if the ghoul to stays until it senses the player and then rises up. I have the same problem with the ambush spider.

If i put them off the map and teleport them in, they won't have the "ambush" or "rise" effect because they will have already done it the instant the map loaded.

I don't want the monster to just "appear out of thin air"


so you say it IS possible, I just need more scripting.
I figured as much.
I know how to spawn a monster with a script.
so then all I need to do is set an id for it and then i can manipulate it's stats and even add it to a boss fight?
User avatar
THOM
Posts: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: setHealth on a spawned monster

Post by THOM »

Do something like

Code: Select all

function(self)
  local warg = spawn("fjeld_warg",self.go.level,self.go.x,self.go.y,(party.facing+2)%4,self.go.elevation)
  warg.monster:setLevel(3)
  warg.monster:setMaxHealth(600)
  warg.monster:setHealth(600)
end 
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: setHealth on a spawned monster

Post by FeMaiden »

THOM wrote:Do something like

Code: Select all

function(self)
  local warg = spawn("fjeld_warg",self.go.level,self.go.x,self.go.y,(party.facing+2)%4,self.go.elevation)
  warg.monster:setLevel(3)
  warg.monster:setMaxHealth(600)
  warg.monster:setHealth(600)
end 

weird question.
I notice you setMaxHealth() first and then you setHealth()

I've been doing the health first and then max health.

is it better to set the max health first? or it doesn't matter?

it seems like it doesn't matter since I'm having the desired effect.
Post Reply