"Spellthief" Skill Idea assistance

I’m literally just starting out and am trying to get into ASM, but so far have had little luck understanding concepts. My goal was to make a custom skill that gives a 1 durability tome when dodging an anima attack (basically the defender would receive a copy of the spell dodged), or if they already have one, it will increase the durability of the same tome in the defender’s inventory by 1 (attacked by fire, defender’s fire tome gains 1 durability).

I’m sure this is stupidly complex for someone starting out, but this skill idea is the main reason I was looking in ASM at all so far. If someone far smarter than me could explain how I could achieve this, I’d appreciate it greatly.

#include "gbafe.h"

extern int pr_SpellthiefId;

bool thumb_SkillTester(struct Unit * unit, u8 sid);

void Proc_Spellthief(struct BattleUnit * actor, struct BattleUnit * target, struct BattleHit * hit, struct BattleStats * stat)
{
    int i, weapon, wtype;

    if (!(stat->config & BATTLE_CONFIG_REAL))
        return;

    if (!thumb_SkillTester(&target->unit, pr_SpellthiefId))
        return;

    if (!(hit->attributes & BATTLE_HIT_ATTR_MISS))
        return;

    weapon = actor->weaponBefore;

    /* Skip unbreakable weapon */
    if (GetItemAttributes(weapon) & IA_UNBREAKABLE)
        return;

    wtype = GetItemType(weapon);
    switch (wtype) {
    case ITYPE_ANIMA:
    case ITYPE_LIGHT:
    case ITYPE_DARK:
        break;

    default:
        return;
    }

    /* If attacker use the same weapon as target */
    if (target == &gBattleTarget && ITEM_INDEX(weapon) == ITEM_INDEX(target->weaponBefore) && target->canCounter)
    {
        if (ITEM_USES(target->weapon) < GetItemMaxUses(weapon))
        {
            target->weapon = ITEM_INDEX(target->weapon) | ((ITEM_USES(target->weapon) + 1) << 8);
            return;
        }
    }

    for (i = 0; i < UNIT_ITEM_COUNT; i++)
    {
        if (target->unit.items[i] == 0)
        {
            target->unit.items[i] = ITEM_INDEX(weapon) | (1 << 8);
            return;
        }
        else if (ITEM_INDEX(target->unit.items[i]) == ITEM_INDEX(weapon))
        {
            if (ITEM_USES(target->unit.items[i]) < GetItemMaxUses(weapon))
            {
                target->unit.items[i] = ITEM_INDEX(target->unit.items[i]) | ((ITEM_USES(target->unit.items[i]) + 1) << 8);
                return;
            }
        }
    }
}

compiled:

ALIGN 4
PUSH
ORG CURRENTOFFSET+$1;Proc_Spellthief:
POP
WORD $4646B5F0 $464F46D6 $B5C0881B $6000D $7DB0014 $BCE0D406 $46B146BA $BCF046A8 $4700BC01 $284B37 $4B377819 $F876F000 $D0F02800 $79B6823 $274AD5ED $4B335BF6 $F0000030 $2308F86B $4004001C $D1E24203 $4B2F0030 $F862F000 $28023805 $4B2DD8DB $D027429D $4699231E $469833E1 $469A4B2A $464B44A9 $2F00881F $33D03A $407B4642 $D006421A $469C2302 $44E13401 $D1F02C05 $30E7C1 $F843F000 $42870A3F $64DAF2 $8BE0192C $33010A03 $4643021A $43134003 $E7B083E3 $27FF5BEB $421F4073 $2352D1D2 $2B0056EB $2348D0CE $5AEB4698 $46990A1B $4B110030 $F822F000 $DAC34581 $5AEA4643 $33010A13 $21B403A $46424313 $E79252AB $228021FF $63340C $524031 $430A18EB $E78880DA
POIN pr_SpellthiefId
POIN thumb_SkillTester
WORD $801756D $8017549 $203A56C $80175B1 $47504718

Add external definations:

ALIGN 4
/* Define the skill index by yourself */
pr_SpellthiefId:
	WORD 148

thumb_SkillTester:
	POIN SkillTester | 1

And insert the compiled label Proc_Spellthief to the proc skills:

// EngineHacks\Necessary\CalcLoops\BattleProcCalcLoop\BattleProcCalcLoop.event
ProcLoopParent:
// ...
POIN Proc_Spellthief
// ...
4 Likes

Wow! Thanks. I wasn’t expecting such a rapid response. I thought I’d be waiting for days before someone even saw the post. I really appreciate it.

2 Likes

I’m really sorry to bother you after you’ve made the code for me but when I put everything in, I couldn’t get assemblyarm.bat to run the .s file. Maybe I misunderstood which parts of code went where.

The code Mokha provided was in C, not ASM. If you’re on Windows you’ll need aMake.bat and a makefile, which will generate a lyn.event file (the compiled form of your c code). You can use Sacrifice.c as an example in the old skill system repo. However, in this case you don’t need to do that as Mokha has helpfully provided the compiled code already (the part with ALIGN, PUSH, POP etc). So you can just give that the name as your spellthief code, give it the extension .lyn.event and throw that in the same folder.

If you’re interested in learning more about C setup, Vesly has created a helpful guide here: C Setup for Dummies

But if you’re at that stage I would also recommend looking into the newer C Skill System if you want to make more skills.

1 Like