Custom turn attacks and move attacks.

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
DaggorathMaster
Posts: 37
Joined: Thu Sep 08, 2022 7:29 pm

Custom turn attacks and move attacks.

Post by DaggorathMaster »

I am trying to do custom turn attacks and move attacks.

Points of failure? Turning, moving, and, well, attacking...

So, how can I make these actions:
- Move or turn the attacker?
- Land the attack in the right tile?

I copied some things in moveAttack from the turtle, hoping that having a MonsterMoveAttack component and/or the action name moveAttack would be the end of it. Nope.

With turn attacks, I also did not want the single action default way of handling it, which decides on its own terms which animation to use.

The presumably hardcoded default turn attack sucks when:
SpoilerShow
the party is not the only target in existence ever, and it may be out of melee range.
(Yes, allies and factions work.)
turnToAttackDirection doesn't do anything unless the turn attack is done the default way.
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Custom turn attacks and move attacks.

Post by minmay »

"Turn attacks" are just MonsterAttackComponents with the turnToAttackDirection field set. The turnAttackLeft, turnAttackRight, and turnAroundAttack animations, if they exist, will then be used for attacks in those directions, and the monster will turn as soon as the attack begins. If you haven't provided a turnAttackLeft animation, the monster won't be able to make turn attacks to the left, and so on. Unless you set it with setAnimations() below:
DaggorathMaster wrote:With turn attacks, I also did not want the single action default way of handling it, which decides on its own terms which animation to use.
MonsterAttackComponent:setAnimations() may be used at any time to change the animations it uses. It takes one argument, a table with animation names:

Code: Select all

function MonsterAttackComponent:setAnimations(anims)
        self.attackAnim = anims.front
        self.attackLeftAnim = anims.left
        self.attackRightAnim = anims.right
        self.attackBackAnim = anims.back
        self.attackFrontLeftAnim = anims.frontLeft
        self.attackFrontRightAnim = anims.frontRight
end
The left/right/back animations are also used for turn attacks in those directions. You could call this function in your onThink hook right before telling the monster to attack, for example.
DaggorathMaster wrote: the party is not the only target in existence ever, and it may be out of melee range.
Both MonsterAttackComponent and MonsterMoveAttackComponent, except when the attackType is "projectile", are designed for the purpose of attacking the party. So if you want to use their animation logic etc., but "attack" things that are not the party (or attack the party in a particularly odd location), you'll need to return false from the onAttack hook and do your own "attack" logic.

For that, refer to the source files in the umod pack: the function you'll want to use as a reference for this is MonsterAttackComponent:attackParty(). You'll also need to reimplement Champion:getProtectionForBodyPart(). Don't worry about the onMonsterHitChampion message, it's only used by the lindworm boss fight.

If you mean to have monsters "attack" other monsters, you'll also need to reimplement much of MonsterComponent:onAttackedByChampion() and MonsterComponent:findImpactPosition(). For the latter, it's helpful to know that you can get the location of a node on a monster ("capsule" in this case) by using MonsterComponent:shootProjectile() from that node and then inspecting the position of the returned object (just remember to destroy it afterwards).

MonsterMoveAttackComponent requires an animation event named "move_forward" (the monster's object will move to the new square when this event is encountered). If you use MonsterMoveAttackComponent with an animation that does not have such an event, it will not work.
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
DaggorathMaster
Posts: 37
Joined: Thu Sep 08, 2022 7:29 pm

Re: Custom turn attacks and move attacks.

Post by DaggorathMaster »

OK I had missed the "move_forward" animation event for those attacks.
Works a bit too well now! (Mr. McBossLord needs a nerf).

Helpful to know that the monster turns at the start of the turn attack.
Maybe I'll just redo the animations to end facing forward, snd setPosition() with the new facing at the start.

Monster versus monster works, but is basic in some ways.
The fake projectile trick can help upgrade that, and knowing what code to look at for inspiration or properly-credited borrowing will help too.
Post Reply