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

Deal damage to Monster

Post by Emera Nova »

So I took the script from the thread deal damage to party and edited to what I thought would work on a monster.

Code: Select all

function damagemummy()
	if findEntity("mummy_2") ~= nil then
	mummy_2.monster:damage(5, "shock")
	end
end
When I activated the code it ended up freezing the game, why did that happen and how do I fix this? As it is I have it hooked up on a timer that does damage to the mummy every 15 seconds, I want it to check to see if the monster is still there and if it is deal the damage if nothing it just ends.

I front part of my script is what I use when looking for an object on in the dungeon to destroy it. So I thought that part of the script would work for looking at the monster.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Deal damage to Monster

Post by minmay »

MonsterComponent has no method named "damage".
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.
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Deal damage to Monster

Post by Emera Nova »

:o So does that mean It's not possible to damage the monster like the party?
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: Deal damage to Monster

Post by GoldenShadowGS »

Code: Select all

function damagemummy()
	local m = findEntity("mummy_2")
	if m ~= nil then
		damageTile(m.level, m.x, m.y, 0, m.elevation, 1, "shock", 5)
	end
end
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Deal damage to Monster

Post by Emera Nova »

Thank you Golden that works lovely
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Deal damage to Monster

Post by minmay »

Emera Nova wrote::o So does that mean It's not possible to damage the monster like the party?
There is no direct equivalent to the Champion:damage() method, however you can imitate it pretty much perfectly with MonsterComponent:setHealth(), MonsterComponent:getResistance(), MonsterComponent:showDamageText(), and MonsterComponent:die().
GoldenShadowGS wrote:function damagemummy()
local m = findEntity("mummy_2")
if m ~= nil then
damageTile(m.level, m.x, m.y, 0, m.elevation, 1, "shock", 5)
end
end
This has several problems:
1. it will damage all monsters and HealthComponents in the square (you need to use a TileDamagerComponent with an onHitMonster, onHitObstacle, etc. hook that will check the monster id and only damage the right one)
2. it won't do the right amount of damage because damageTile and TileDamagerComponent use an attack power roll, randomizing the amount of damage, whereas Champion:damage() does the exact amount of damage you specify
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.
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Deal damage to Monster

Post by Azel »

Now is a good time to request a new forum: Mod Newbies

Or something similar. Having a place for clueless Moders (myself included) can be beneficial. So that people can fumble through conversations as they engage in the painful aspects of beginner learning, while all the super duper godly mod vet's can enjoy their freedom. Someone with a bigger voice than mine should get a new Forum for newbie moders asap :mrgreen:
Post Reply