Skip to content

Fix incorrect signature for AttackedBy() trigger#227

Draft
4Luke4 wants to merge 1 commit intoGibberlings3:masterfrom
4Luke4:astyles
Draft

Fix incorrect signature for AttackedBy() trigger#227
4Luke4 wants to merge 1 commit intoGibberlings3:masterfrom
4Luke4:astyles

Conversation

@4Luke4
Copy link
Copy Markdown
Contributor

@4Luke4 4Luke4 commented Mar 8, 2026

So, AttackedBy() implementation is not broken. However, the trigger is currently labeled with the wrong IDS type.

Unmodded TRIGGER.IDS states:

0x0002 AttackedBy(O:Object*,I:Style*AStyles)

But the engine shows the second argument is not an attack style at all.

Details

What the engine actually does (tested on IWD:EE v2.6.6.0):

  • CGameSprite::Swing at 0x1403B8010 builds trigger 0x0002 from:
    • m_selectedWeapon at +0x10f8
    • m_selectedWeaponAbility at +0x10fa
  • The matching path goes through CAITrigger::OfType at 0x140130730.
  • That matcher compares trigger type, source object, and the primary specific integer.
  • It does not do any ASTYLES lookup or style interpretation.

So the runtime meaning is:

  • primary integer = selected weapon slot
  • secondary ability integer is carried internally, but not exposed by the script signature in any meaningful way

Why vanilla scripts still work:

  • They usually write AttackedBy(..., DEFAULT).
  • DEFAULT evaluates to 0 in ASTYLES.IDS.
  • In the matcher, a requested specific value of 0 behaves like a wildcard (as you all probably know).
  • So AttackedBy([GOODCUTOFF],DEFAULT) really means "attacked by [GOODCUTOFF], any slot", not "attacked with style DEFAULT".

The engine-side slot evidence is also consistent:

  • Swing() can emit 9 (offhand weapon)
  • init/fallback code uses 10 (fist/unarmed)
  • combat equip code selects 11..14, 34, and 35..38 (ammo + magical weapon + ordinary weapon slots)

So the real combat domain is:

9, 10, 11..14, 34, 35..38

Summoning @Bubb13 for confirmation...

@Bubb13
Copy link
Copy Markdown

Bubb13 commented Mar 8, 2026

I only observe AttackedBy()'s integer parameter being filled with 0 at all call sites using CAITrigger::ATTACKEDBY:

CAITrigger::CAITrigger(&attackedByTrigger, 2, &this->m_typeAI, 0);

The last argument is the event trigger's int parameter. You can check what value the engine is filling with EEex's latest crash_handler branch commit; set EEex_Debug_LogEventTriggers = true in EEex_Debug.lua and view the terminal output.

e.g.:

Event trigger set:
    Receiving object ------ Aerie (*ERIE6)
    Trigger --------------- 0x0002 (AttackedBy)
    Trigger int parameter - 0
    Cause AI type:
        m_name ------------ "Keldorn"
        m_EnemyAlly ------- 2
        m_General --------- 1
        m_Race ------------ 1
        m_Class ----------- 6
        m_Instance -------- 0x8EF08EE
        m_SpecialCase[0] -- 0
        m_SpecialCase[1] -- 0
        m_SpecialCase[2] -- 0
        m_SpecialCase[3] -- 0
        m_SpecialCase[4] -- 0
        m_Specifics ------- 0
        m_Gender ---------- 1
        m_Alignment ------- 17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants