onProjectileHit hook for spell

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Damonya
Posts: 134
Joined: Thu Feb 28, 2013 1:16 pm
Location: France
Contact:

onProjectileHit hook for spell

Post by Damonya »

Hello,

What is the hook that detects a spell is cast on monsters?

onProjectileHit is for pojectile weapon. Does it running with a spell?

I want to launch a function on a monster, when this monster is hit by a spell. But there is no specific hook for that.

onDamage is not accurate enough, because I want detect what spell hit the monster. How shall we do it? :?:

Thanks for help or explanation. Maybe we can't, I don't know

PS: I searched a lot on the forum, but I have not found
Orwak - MOD - Beta version 1.0
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Re: onProjectileHit hook for spell

Post by Diarmuid »

Hi!

I wrote an spells framework (EXSP) which is exactly for this purpose: viewtopic.php?f=14&t=4459.

And test it in action here: viewtopic.php?f=14&t=4860

The hooks are not placed on the monster, but on the spell.

The genreal purpose hook is onHit(self, level, x, y, hitType, [subType], [entity], [entity2], [entity3], [entity4]). When the spell hits something, you get the position, the hitType (monster, party, wall, door...), subType (alcove, button, lever...), and the entities if present. Entities 1-4 are for monster groups, which you get as individual monsters to do what you please.

Some proxy hooks are however provided for convenience which provide filtered results, such as onMonsterHit(self, monster, [monster2], [monster3], [monster4])

So, example hook would read:

Code: Select all

exsp:addSpellHooks("fireball", 
{
	onMonsterHit = function(self, monster)
	
		if monster.name == "shrakk_torr" then
			print("I just hit a Shrakk Torr, says the Fireball!")
		end
		
	end
})
More complete documentation here: https://sites.google.com/site/exspwiki/home

I'll just clean up some inefficient/redundant code I found out while making the Lite version (you need the full to use the hooks) and post an update later today.
User avatar
Damonya
Posts: 134
Joined: Thu Feb 28, 2013 1:16 pm
Location: France
Contact:

Re: onProjectileHit hook for spell

Post by Damonya »

Wow I love your spell framework. :o
Thanks a lot. I'll test it right now. :)
Orwak - MOD - Beta version 1.0
User avatar
Damonya
Posts: 134
Joined: Thu Feb 28, 2013 1:16 pm
Location: France
Contact:

Re: onProjectileHit hook for spell

Post by Damonya »

Is it compatible with the AISwitcher from xanathar ?

Because with custom monster :
Aiswitcher uses defineAiSwitchMonster{ }
and your spell framework uses fw_defineObject { }

So both are incompatible I think? I have to make a choice
Orwak - MOD - Beta version 1.0
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Re: onProjectileHit hook for spell

Post by Diarmuid »

You have to ask Xanathar what his AISwithcher does, but probably it's using the framework too so you should be fine. The idea is that exsp is using the framework "monsters" shortcut to add an onDamage hook to all monsters, so the framework must know about custom monsters. But there can be a workaround in all cases, as you can add this manually to the monster definition:

Code: Select all

		onDamage = function(self, damage, damageType)
			local dh = exsp.damageHandler
			if dh.onDamageFilter[self.id] then
				if dh.onDamageFilter[self.id] ~= "freezeMonster" then
					local id = dh.onDamageFilter[self.id]
					local spell = exsp.sd[id]
					if spell.name ~= "ice_shards" then
						dh.monsterGroupCtr[spell.id] = dh.monsterGroupCtr[spell.id] + 1
						if dh.monsterGroupCtr[spell.id] == dh.monsterGroup[spell.id] then
							spell:onHitHook("monster", nil, dh.monsterGroupTable[spell.id], "monster")
						end
					end
				end
				return false
			elseif extend:entity(self):isInvulnerable() then
				return false
			end
		end,
User avatar
Damonya
Posts: 134
Joined: Thu Feb 28, 2013 1:16 pm
Location: France
Contact:

Re: onProjectileHit hook for spell

Post by Damonya »

Thank you. But I think the problem is more complicated than that. With initializing spell framework, aiswitcher no longer works. Cooperation between you, would make the game very fun. Really ^^
Orwak - MOD - Beta version 1.0
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Re: onProjectileHit hook for spell

Post by Diarmuid »

Ok, I just realized that exsp doesn't work at all anymore with the latest version of the framework. So I have to get in touch with jKos to see what happened. It has something to do with loading of modules and initialization. Maybe that's where all the bugs come from. I'll look into it tonight.
User avatar
Damonya
Posts: 134
Joined: Thu Feb 28, 2013 1:16 pm
Location: France
Contact:

Re: onProjectileHit hook for spell

Post by Damonya »

I just downloaded the latest version of log_framework and exsp, but still the same problem.

when I add at the end of ini.lua :
import "mod_assets/exsp/exsp_init.lua"

IAswitcher don't work. With or without add you ondamage hook (which must be in a string for IAswitcher)

Am I the only one? otherwise perhaps it is me, who makes the wrong things, not as it should.
Orwak - MOD - Beta version 1.0
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Re: onProjectileHit hook for spell

Post by Diarmuid »

I need to install the AISwitcher and do some testing.
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: onProjectileHit hook for spell

Post by JKos »

I'm pretty sure that it's because they both use party.onDrawGui-hook, and my framework doesn't support it... But no worries, now it does. I just uploaded a new version which supports multiple and dynamic onDraw...-hooks.

So the exsp should be modilifed like this:
exsp.lua

Code: Select all

...

function autoexec()
	defineDefaultMonsters()
	fw.setHook('party.exsp.onDrawGui',function(g)
			exsp.exspTimer()
		end
	)
end
...
and party-entity definition must be removed also of course.

and aiSwitcher must be modified to use dynamic onDrawGui-hook.
- 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
Post Reply