Hey folks, maybe you can find something useful in the code below - this allows you to detect damage done by spells, melee and ranged weapons.
Below in the code there is a #SPECIAL EFFECTS tag, where script recognizes what weapon is used and applies 'special effects' in case we are using special weapons like for example Legendary bow of Firestorm !
https://youtu.be/yvwhrdyf6QY?t=1m40s
Code:
/***
G1 [Tested with LeGo 2.5.0]
***/
FUNC INT Calculate_Weapon_Damage (var int victimPtr, var int ddPtr, var int dmg)
{
var oSDamageDescriptor dmgDescriptor;
dmgDescriptor = _^ (ddPtr);
//Don't change anything if damage was not caused by NPC
if (dmgDescriptor.pNpcAttacker == 0)
|| (victimPtr == 0)
{
return dmg;
};
var oCNPC oth; oth = _^(dmgDescriptor.pNpcAttacker);
var oCNPC slf; slf = _^(victimPtr);
//Spell
if (dmgDescriptor.nSpellID > 0)
{
if (dmgDescriptor.nSpellID == SPL_ICECUBE)
{
// ...
};
};
var c_item weapon;
//If damage was done by Ranged weapons, nSpellID == -1
if (dmgDescriptor.nSpellID == -1)
{
/***
dmgDescriptor.pItemWeapon contains ammo !! therefore we have to check either Readied Weapon or Equipped Weapon
might be there is a better way though ...
***/
if (Npc_IsInFightMode(oth, FMODE_FAR)) {
weapon = Npc_GetReadiedWeapon (oth);
} else if (Npc_HasEquippedRangedWeapon (oth)) {
weapon = Npc_GetEquippedRangedWeapon (oth);
};
};
} else
//Melee weapons
if (dmgDescriptor.pItemWeapon != 0)
{
weapon = _^ (dmgDescriptor.pItemWeapon);
};
// ... whatever calculation you need ...
//#SPECIAL EFFECTS
//Check what weapon was used
var int weaponInst;
weaponInst = Hlp_GetInstanceID (weapon);
//Legendary Bow of Firestorm !
if (weaponInst == ItRw_Bow_FireStorm)
{
//Check NPC's mana - can Special effect be casted ?
if (oth.attribute [ATR_MANA] >= ItRw_Bow_FireStorm.count[4])
{
oth.attribute [ATR_MANA] = oth.attribute [ATR_MANA] - ItRw_Bow_FireStorm.count[4];
Wld_PlayEffect ("SPELLFX_FIRESTORM_SPREAD", slf, slf, 0, 0, 0, FALSE);
/***
NPC_MagicHurt_NPC - is an alternative to B_MagicHurtNpc
Difference is you can specify DAM_TYPE and damage is not applied on 'self' but to 'victim', where victim is passed to function as C_NPC a paramater
***/
//NPC_MagicHurt_NPC (attacker, victim, SPL_DAMAGE_FIRESTORM, DAM_FIRE);
MEM_PushInstParam (oth);
MEM_PushInstParam (slf);
MEM_PushIntParam (SPL_DAMAGE_FIRESTORM);
MEM_PushIntParam (DAM_FIRE);
MEM_Call (NPC_MagicHurt_NPC);
};
};
return dmg;
};
FUNC VOID _HOOK_DMG_ONDMG_EVENT ()
{
//Remember this is example for G1 !
EAX = Calculate_Weapon_Damage (EDI, MEM_ReadInt (ESP + 548), EAX);
};
//Hook it with
HookEngine (7567329, 6, "_HOOK_DMG_ONDMG_EVENT");