Page 1 of 2
onProjectileHit hook for spell
Posted: Mon Apr 22, 2013 6:46 pm
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
Re: onProjectileHit hook for spell
Posted: Tue Apr 23, 2013 4:06 pm
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.
Re: onProjectileHit hook for spell
Posted: Tue Apr 23, 2013 5:04 pm
by Damonya
Wow I love your spell framework.
Thanks a lot. I'll test it right now.

Re: onProjectileHit hook for spell
Posted: Tue Apr 23, 2013 10:17 pm
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
Re: onProjectileHit hook for spell
Posted: Tue Apr 23, 2013 10:29 pm
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,
Re: onProjectileHit hook for spell
Posted: Tue Apr 23, 2013 10:57 pm
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 ^^
Re: onProjectileHit hook for spell
Posted: Wed Apr 24, 2013 1:12 am
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.
Re: onProjectileHit hook for spell
Posted: Thu Apr 25, 2013 10:02 am
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.
Re: onProjectileHit hook for spell
Posted: Thu Apr 25, 2013 5:36 pm
by Diarmuid
I need to install the AISwitcher and do some testing.
Re: onProjectileHit hook for spell
Posted: Thu Apr 25, 2013 8:03 pm
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.