Specific hook for all meleeAttacks

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Specific hook for all meleeAttacks

Post by cromcrom »

Hello there,

I feel a little lazy, could anybody tell me if there is an easy way to apply a function (checkDeterioration, for instance) to all meleeAttacksComponents, without doing it for each item ? And if yes, either the code, or a serious hint or link would be amazing, please :-)
A trip of a thousand leagues starts with a step.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Specific hook for all meleeAttacks

Post by minmay »

It's trivial, actually. PartyComponent.onAttack() provides the component used to make the attack; it's the third argument.

Code: Select all

onAttack = function(self, champion, action, slot)
  if action and action:getClass() == "MeleeAttackComponent" then
    -- do your stuff here
  end
end,
There is one caveat: PartyComponent.onAttack() is not called at all for bare-handed attacks.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Specific hook for all meleeAttacks

Post by cromcrom »

Amazing, my deterioration system will make much more sense now. Thank you so much :-)
A trip of a thousand leagues starts with a step.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Specific hook for all meleeAttacks

Post by cromcrom »

Actually, I checked, the deterioraton system for weapons was already played on the onAttack hook from the partycomponent. However, this checks the deterioraton every time a character attacks. I would like to have it checked only when a monster is hit, so that would be the onMonsterHit hook from the meleeAttackComponent. However, my issue is to set this deteriorationCheck function on all meleeAttackcomponnts for all melee weapons, without doing it hand by hand for each weapon.
Hopefully I can make myself clear ...
A trip of a thousand leagues starts with a step.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Specific hook for all meleeAttacks

Post by minmay »

Sorry, the only hook for that is MeleeAttackComponent.onHitMonster().
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Specific hook for all meleeAttacks

Post by cromcrom »

Yes I know. Is there a way to apply a function to all onHitMonster, without doing it individually for each and every weapon type ?
A trip of a thousand leagues starts with a step.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Specific hook for all meleeAttacks

Post by minmay »

no, but you can use this to possibly make it a little more convenient
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Specific hook for all meleeAttacks

Post by cromcrom »

Thanks for the info, and not being as lazy as me :-)
A trip of a thousand leagues starts with a step.
Post Reply