Damage Dealt Event

Post Reply
STP
New member
Posts: 3
Joined: Sat Feb 14, 2015 16:49

Damage Dealt Event

by STP » Post

I'm creating a mod in which I'd like to know when a player deals damage to a LuaEntitySAO. It's my understanding there is a new damage system in use that might facilitate this, plus I can see the output dumped to the log when damage is dealt (output through ACTION[ServerThread]) so I know the engine has this information.

Is there an event I can use to access this? I want my mod to be "monster-mod independent", so that it won't matter what type of monster mod the user has installed (I intent to make my mod public of course) - as long as the monster mod uses the LuaEntitySAO & engine damage system my mod should detect damage dealt.

Thanks!

STP
New member
Posts: 3
Joined: Sat Feb 14, 2015 16:49

Re: Damage Dealt Event

by STP » Post

Judging by the lack of replies it's looking like I may not be able to do what I wanted to.

So if I can't detect when damage is dealt, what about an event for when a mob is killed/defeated/destroyed? Is that possible?

Or failing that, when a mob has been hit at all?

User avatar
HeroOfTheWinds
Member
Posts: 470
Joined: Wed Apr 23, 2014 23:16
GitHub: HeroOfTheWinds
IRC: WindHero
Location: Hawaii

Re: Damage Dealt Event

by HeroOfTheWinds » Post

Code: Select all

on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir) — Called by the engine when somebody punches the object. Note that you probably want to handle most punches using the automatic armor group system (See #Entity Damage).
puncher — An ObjectRef or nil.
time_from_last_punch — Can be used to calculate damage. Can be nil.
tool_capabilities — Capability table of used tool. Can be nil.
dir — Unit vector in the direction of the punch. Points from the puncher to the entity, and is always defined.
Maybe that will help a bit... There is no currently programmed callback for when entities are damaged, but perhaps you could make a feature request on the Minetest GitHub page. Until then, I would use the above function to determine when a mob is hit. It will be hard, but it's the only way. You need to find some way of re-registering all of the mobs in the minetest.registered_entities[] table with the on_punch() function overwritten with your changes.

Good luck!
Nam ex spatio, omnes res venire possunt.
Why let the ground limit you when you can reach for the sky?
Back to college now, yay for sophomore year schedules. :P

STP
New member
Posts: 3
Joined: Sat Feb 14, 2015 16:49

Re: Damage Dealt Event

by STP » Post

HeroOfTheWinds wrote:

Code: Select all

on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir) — Called by the engine when somebody punches the object. Note that you probably want to handle most punches using the automatic armor group system (See #Entity Damage).
puncher — An ObjectRef or nil.
time_from_last_punch — Can be used to calculate damage. Can be nil.
tool_capabilities — Capability table of used tool. Can be nil.
dir — Unit vector in the direction of the punch. Points from the puncher to the entity, and is always defined.
Maybe that will help a bit... There is no currently programmed callback for when entities are damaged, but perhaps you could make a feature request on the Minetest GitHub page. Until then, I would use the above function to determine when a mob is hit. It will be hard, but it's the only way. You need to find some way of re-registering all of the mobs in the minetest.registered_entities[] table with the on_punch() function overwritten with your changes.

Good luck!

EDIT--

Thank you Hero! With your post I was able to find everything I needed. What I have isn't perfect yet, but this appears to be providing the data needed at least to determine initial damage dealt, and when a monster is defeated:

Code: Select all

minetest.after(2.5, function()

	local ents = minetest.registered_entities
	local monsters = {}

	for _,ent in pairs(ents) do 

		if ent.hp_max ~= nil and ent.hp_max > 0 and ent.damage ~= nil and ent.damage > 0 then
			table.insert(monsters,ent)
			print(dump("Adding " .. ent.name .. " to set of monsters."))
		end			
		
	end

	for _,monster in pairs(monsters) do		
		monster.on_punch = function(self, player)
			if player and player:is_player() then
				print(dump("Monster punched by: " .. player:get_player_name()))
				print(dump("Monsters current hitpoints: " .. self.object:get_hp() .. " and max hp was " .. monster.hp_max))
			end
		end
	end


end)
This punch event may override current mob mod punch event script (not certain) such as awarding drops, but I was thinking of handling that with my mod anyway.

I can now determine when a monster is defeated and calculate the total damage dealt to it, or calculate the damage dealt between when monster was at full health and 'now'. Only thing I can't figure out from this (so far) is if the monster was already partially damaged and now it has been damaged further (since I can't find out its HP before it was hit, which may not be its max_hp).

I may be able to determine the damage from the time_from_last_punch and tool_capabilities arguments, but haven't checked that yet.

User avatar
HeroOfTheWinds
Member
Posts: 470
Joined: Wed Apr 23, 2014 23:16
GitHub: HeroOfTheWinds
IRC: WindHero
Location: Hawaii

Re: Damage Dealt Event

by HeroOfTheWinds » Post

Glad to hear that I could be of help. Let us know if you need more help, and good luck with your mod!
Nam ex spatio, omnes res venire possunt.
Why let the ground limit you when you can reach for the sky?
Back to college now, yay for sophomore year schedules. :P

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests