NWNX:EE  8193.37.14
Damage

Readme

This plugin allows to run a script just before a damage is applied to a creature, and allows to modify the amount and type of the damage.For this plugin to work you have to create a script and associate it to the "OnApplyDamage" event (see the example below) this should be done on the OnModuleLoad event of your module.Note that the immunities and damage reduction of the creature have been already taken into account when your script is called.

Example

On Module Load event example:

#include "nwnx_damage"
void main()
{
NWNX_Damage_SetDamageEventScript("_on_damage"); // This is the script that will be called
}
void main()
void NWNX_Damage_SetDamageEventScript(string sScript, object oOwner=OBJECT_INVALID)
Sets the script to run with a damage event.

"_on_damage" script example:

#include "nwnx_damage"
void main()
{
// Get all the data of the damage event
object oDamager = data.oDamager; // The damager
object oTarget = OBJECT_SELF; // The creature receiving the damage
// Let send the damage amounts and types to the Damager
SendMessageToPC(oDamager, "iBludgeoning: " + IntToString(data.iBludgeoning));
SendMessageToPC(oDamager, "iPierce: " + IntToString(data.iPierce));
SendMessageToPC(oDamager, "iSlash: " + IntToString(data.iSlash));
SendMessageToPC(oDamager, "iMagical: " + IntToString(data.iMagical));
SendMessageToPC(oDamager, "iAcid: " + IntToString(data.iAcid));
SendMessageToPC(oDamager, "iCold: " + IntToString(data.iCold));
SendMessageToPC(oDamager, "iDivine: " + IntToString(data.iDivine));
SendMessageToPC(oDamager, "iElectrical: " + IntToString(data.iElectrical));
SendMessageToPC(oDamager, "iFire: " + IntToString(data.iFire));
SendMessageToPC(oDamager, "iNegative: " + IntToString(data.iNegative));
SendMessageToPC(oDamager, "iPositive: " + IntToString(data.iPositive));
SendMessageToPC(oDamager, "iSonic: " + IntToString(data.iSonic));
SendMessageToPC(oDamager, "iBase: " + IntToString(data.iBase));
// Let say I want all creatures that have certain local int to be inmune to fire
// and I want to see on the log that the creature received 0 damage form fire
if(GetLocalInt(oTarget,"I_M_FIRE_ELEMENTAL"))
data.iFire = 0; //
// Let say I want all creatures that have certain local int to be inmune to cold
// this time I don't want to see anything on the log about ICE damage
if(GetLocalInt(oTarget,"I_M_ICE_ELEMENTAL"))
data.iCold = -1;
// So:
// - Set the numbers to -1 to hide them from the combat log
// - Set them to 0 to have them reported as 0
// - Set them to other positive numbers to change the damage values as you see fit.
// Send the modfied damages to nwnx
}
void NWNX_Damage_SetDamageEventData(struct NWNX_Damage_DamageEventData data)
Set Damage Event Data.
struct NWNX_Damage_DamageEventData NWNX_Damage_GetDamageEventData()
Get Damage Event Data.
Damage Event Data.
Definition: nwnx_damage.nss:11
object oDamager
The object that inflicted the damage.
Definition: nwnx_damage.nss:12

Hellball script example using DealDamage

#include "x2_i0_spells"
#include "nwnx_damage"
void main()
{
int nSpellDC = GetEpicSpellSaveDC(OBJECT_SELF);
effect eKnock = EffectKnockdown();
effect eExplode = EffectVisualEffect(464);
location lTarget = GetSpellTargetLocation();
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eExplode, lTarget);
// roll damage once
struct NWNX_Damage_DamageData damage, half;
damage.iAcid = d6(10);
damage.iElectrical = d6(10);
damage.iFire = d6(10);
damage.iSonic = d6(10);
half.iAcid = damage.iAcid / 2;
half.iElectrical = damage.iElectrical / 2;
half.iFire = damage.iFire / 2;
half.iSonic = damage.iSonic / 2;
// apply damage
object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, 20.0f, lTarget, TRUE, OBJECT_TYPE_CREATURE);
while (GetIsObjectValid(oTarget))
{
if (spellsIsTarget(oTarget, SPELL_TARGET_STANDARDHOSTILE, OBJECT_SELF))
{
SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, GetSpellId()));
float fDelay = GetDistanceBetweenLocations(lTarget, GetLocation(oTarget))/20 + 0.5f;
// no we don't care about evasion. there is no evasion to hellball
if (MySavingThrow(SAVING_THROW_REFLEX,oTarget,nSpellDC,SAVING_THROW_TYPE_SPELL,OBJECT_SELF,fDelay) > 0)
DelayCommand(fDelay, NWNX_Damage_DealDamage(half, oTarget));
else
{
DelayCommand(fDelay, NWNX_Damage_DealDamage(damage, oTarget));
DelayCommand(fDelay + 0.3f, ApplyEffectToObject(DURATION_TYPE_INSTANT, eKnock, oTarget));
}
}
oTarget = GetNextObjectInShape(SHAPE_SPHERE, 20.0f, lTarget, TRUE, OBJECT_TYPE_CREATURE);
}
}
void NWNX_Damage_DealDamage(struct NWNX_Damage_DamageData data, object oTarget, object oSource=OBJECT_SELF, int iRanged=FALSE)
Deal damage to a target.
Used for DealDamage.
Definition: nwnx_damage.nss:98
int iAcid
Acid damage.

Files

file  nwnx_damage.nss
 

Classes

struct  NWNX_Damage_DamageEventData
 Damage Event Data. More...
 
struct  NWNX_Damage_AttackEventData
 Attack Event Data. More...
 
struct  NWNX_Damage_DamageData
 Used for DealDamage. More...
 

Functions

void NWNX_Damage_SetDamageEventScript (string sScript, object oOwner=OBJECT_INVALID)
 Sets the script to run with a damage event. More...
 
struct NWNX_Damage_DamageEventData NWNX_Damage_GetDamageEventData ()
 Get Damage Event Data. More...
 
void NWNX_Damage_SetDamageEventData (struct NWNX_Damage_DamageEventData data)
 Set Damage Event Data. More...
 
void NWNX_Damage_SetAttackEventScript (string sScript, object oOwner=OBJECT_INVALID)
 Sets the script to run with an attack event. More...
 
struct NWNX_Damage_AttackEventData NWNX_Damage_GetAttackEventData ()
 Get Attack Event Data. More...
 
void NWNX_Damage_SetAttackEventData (struct NWNX_Damage_AttackEventData data)
 Set Attack Event Data. More...
 
void NWNX_Damage_DealDamage (struct NWNX_Damage_DamageData data, object oTarget, object oSource=OBJECT_SELF, int iRanged=FALSE)
 Deal damage to a target. More...
 

Function Documentation

◆ NWNX_Damage_SetDamageEventScript()

void NWNX_Damage_SetDamageEventScript ( string  sScript,
object  oOwner = OBJECT_INVALID 
)

Sets the script to run with a damage event.

Parameters
sScriptThe script that will handle the damage event.
oOwnerAn object if only executing for a specific object or OBJECT_INVALID for global.

Definition at line 174 of file nwnx_damage.nss.

◆ NWNX_Damage_GetDamageEventData()

struct NWNX_Damage_DamageEventData NWNX_Damage_GetDamageEventData ( )

Get Damage Event Data.

Returns
A NWNX_Damage_DamageEventData struct.
Note
To use only in the Damage Event Script.

Definition at line 174 of file nwnx_damage.nss.

◆ NWNX_Damage_SetDamageEventData()

void NWNX_Damage_SetDamageEventData ( struct NWNX_Damage_DamageEventData  data)

Set Damage Event Data.

Parameters
dataA NWNX_Damage_DamageEventData struct.
Note
To use only in the Damage Event Script.

Definition at line 223 of file nwnx_damage.nss.

◆ NWNX_Damage_SetAttackEventScript()

void NWNX_Damage_SetAttackEventScript ( string  sScript,
object  oOwner = OBJECT_INVALID 
)

Sets the script to run with an attack event.

Parameters
sScriptThe script that will handle the attack event.
oOwnerAn object if only executing for a specific object or OBJECT_INVALID for global.

Definition at line 261 of file nwnx_damage.nss.

◆ NWNX_Damage_GetAttackEventData()

struct NWNX_Damage_AttackEventData NWNX_Damage_GetAttackEventData ( )

Get Attack Event Data.

Returns
A NWNX_Damage_AttackEventData struct.
Note
To use only in the Attack Event Script.

Definition at line 261 of file nwnx_damage.nss.

◆ NWNX_Damage_SetAttackEventData()

void NWNX_Damage_SetAttackEventData ( struct NWNX_Damage_AttackEventData  data)

Set Attack Event Data.

Parameters
dataA NWNX_Damage_AttackEventData struct.
Note
To use only in the Attack Event Script.
Setting iSneakAttack will only change the attack roll message and floating text feedback. Immunities and damage will have already been resolved by the time the attack event script is ran.

Definition at line 317 of file nwnx_damage.nss.

◆ NWNX_Damage_DealDamage()

void NWNX_Damage_DealDamage ( struct NWNX_Damage_DamageData  data,
object  oTarget,
object  oSource = OBJECT_SELF,
int  iRanged = FALSE 
)

Deal damage to a target.

Remarks
Permits multiple damage types and checks enhancement bonus for overcoming DR.
Parameters
dataA NWNX_Damage_DamageData struct.
oTargetThe target object on whom the damage is dealt.
oSourceThe source of the damage.
iRangedWhether the attack should be treated as ranged by the engine (for example when considering damage inflicted by Acid Sheath and other such effects)

Definition at line 356 of file nwnx_damage.nss.