onProjectileHit hook for spell

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
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 »

That's golden! :D :mrgreen: :!:

I'll update my exsp files...

EDIT: EXSP Full updated, I'll take care of EXSP Lite 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 »

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
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 »

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).
User avatar
Damonya
Posts: 134
Joined: Thu Feb 28, 2013 1:16 pm
Location: France
Contact:

Re: onProjectileHit hook for spell

Post 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
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 »

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.
Last edited by Diarmuid on Fri Apr 26, 2013 10:08 pm, edited 1 time in total.
User avatar
Damonya
Posts: 134
Joined: Thu Feb 28, 2013 1:16 pm
Location: France
Contact:

Re: onProjectileHit hook for spell

Post by Damonya »

No you should add dx dy, otherwise the monster hurt with his own spell. ;)
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 »

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.
Last edited by Diarmuid on Fri Apr 26, 2013 10:09 pm, edited 2 times in total.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: onProjectileHit hook for spell

Post 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 :)
Finished Dungeons - complete mods to play
User avatar
Damonya
Posts: 134
Joined: Thu Feb 28, 2013 1:16 pm
Location: France
Contact:

Re: onProjectileHit hook for spell

Post 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.
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 »

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
Orwak - MOD - Beta version 1.0
Post Reply