Page 2 of 2

Re: onProjectileHit hook for spell

Posted: Thu Apr 25, 2013 9:09 pm
by Diarmuid
That's golden! :D :mrgreen: :!:

I'll update my exsp files...

EDIT: EXSP Full updated, I'll take care of EXSP Lite tonight.

Re: onProjectileHit hook for spell

Posted: Fri Apr 26, 2013 4:02 pm
by Damonya
Diarmuid wrote:That's golden! :D :mrgreen: :!:

I'll update my exsp files...

EDIT: EXSP Full updated, I'll take care of EXSP Lite tonight.
Thanks Diarmuid and JKos to have updated your frameworks. Now, AIswitcher runs with your spell framework. It's perfect. :)

I can now test the origin of my problem with this onspell hook on monsters.

PS : personally no problem either with grimwidget

Re: onProjectileHit hook for spell

Posted: Fri Apr 26, 2013 4:19 pm
by Diarmuid
Damonya wrote: PS : personally no problem either with grimwidget
Yes, but if you have the onDrawGui hook defined in gw in a cloneObject of the party, it might override the framework dynamic hooks, and exsp timer might just not work at all, without you noticing it. It doesn't crash, it just won't detect spells and trigger hooks. That's what happend for me at least.

To test if it's working, put a spawner and spell spinner in a room, send a fireball from the spawner with a pressure plate, and if it turns in the teleport field you should be fine. (Means the timer detected the spawned fireball).

Re: onProjectileHit hook for spell

Posted: Fri Apr 26, 2013 9:17 pm
by Damonya
It's great !! I love your framework

Here is a script that allows a monster to return your own spell.

Code: Select all

function autoexec()

exsp:addSpellHooks("name_of_the_spell",
{
   onMonsterHit = function(self, monster)

	if monster.name == "name_of_the_monster" then
		local level, x, y = self:getPosition() 
		local power, ordinal = self.power, self.ordinal 
      local facing = (self.facing + 2)%4
		local dx,dy = getForward((self.facing+2)%4)
		exsp:spellSpawn("name_of_the_spell", level, x+dx, y+dy, facing, {power = power, ordinal = ordinal}) 
      
	end
      
   end
})
end

Re: onProjectileHit hook for spell

Posted: Fri Apr 26, 2013 9:28 pm
by Diarmuid
Ha, that's really cool. Glad to see all the work I put into that being enjoyed by someone... :)

One detail (feature) : You don't need to spawn spells one tile ahead of monsters. You can pass spellSpawn the monster id instead of a position and it will launch it directly from the monster square, in the direction you specified. (So monsters can shoot backwards or sideways too).

So this should work:

Code: Select all

function autoexec()

exsp:addSpellHooks("name_of_the_spell",
{
   onMonsterHit = function(self, monster)

   if monster.name == "name_of_the_monster" then
      local power, ordinal = self.power, self.ordinal 
      local facing = (self.facing + 2)%4
      exsp:spellSpawn(self.name, monster.id, facing, {power = power, ordinal = ordinal}) 
   end
      
   end
})
end
What happens actually is that you'll see an animated fx particle for the first tile of the spell travel, and then exsp takes care of spawning the real spell on the next tile just at the right time so that the transition is (almost) seamless.

Re: onProjectileHit hook for spell

Posted: Fri Apr 26, 2013 9:48 pm
by Damonya
No you should add dx dy, otherwise the monster hurt with his own spell. ;)

Re: onProjectileHit hook for spell

Posted: Fri Apr 26, 2013 10:02 pm
by Diarmuid
Damonya wrote:No you should add dx dy, otherwise the monster hurt with his own spell. ;)
Really? I'll test it, one second, it shouldn't...

EDIT: Indeed, the code I put above works fine. I've even edited it slightly to add self.name instead of the actual string in the spellSpawn function.

Re: onProjectileHit hook for spell

Posted: Fri Apr 26, 2013 10:07 pm
by Komag
but that's the genius of that approach, it makes a "fake" spell on the monster, then the real one is auto-made one square away to not damage the monster :)

Re: onProjectileHit hook for spell

Posted: Sat Apr 27, 2013 12:33 pm
by Damonya
Diarmuid wrote:
Damonya wrote:No you should add dx dy, otherwise the monster hurt with his own spell. ;)
EDIT: Indeed, the code I put above works fine.
ok sorry, I tested again and in fact I was wrong. This is because I tested with poison_bolt and this is the normal behavior of this spell. damage of the spell projectile + poison damage = 2 times damage.

Re: onProjectileHit hook for spell

Posted: Sun Apr 28, 2013 3:19 pm
by Damonya
A variant with spells that crosses the monster without hurting, like a ghost. ;)

Code: Select all

function autoexec()


exsp:addSpellHooks("your_spell_name",
{
   onPass = function(self)
	if self:getCollisionAhead() == "your_monster_name" then
   	self:destroy()
	return false
	end
	end
})	
exsp:addSpellHooks("your_spell_name",
{	
	onMonsterHit = function(self, monster)

   if monster.name == "your_monster_name" then
      local power, ordinal = self.power, self.ordinal
      local facing = self.facing 
      exsp:spellSpawn("your_spell_name", monster.id, facing, {power = power, ordinal = ordinal})
   end
     
   end
})
end