Electric discharge script?


Does anybody have a script that generates a volume of random electrical discharge I might use? Thanks!


Electrical (lightning) trap-type script

// 'lightstrike'
    OnHeartbeat script for a placeable (or other object). It could be slotted
    in a creature's heartbeat, eg, as a rather powerful defense. It will also
    work as-is in the OnEnter of a trigger, etc.

    This will create a lightning bolt strike, typically at an IPoint. It fires
    with a probability of "strikepct" each heartbeat; if a creature is within
    "strikerange" distance in meters, the closest creature will be targeted
    instead. The SaveDC can be specified as "strikedc" and the d6 damage
    delivered as "striked6". These are integer variables set on the object that
    fires this script.

    If a living target creature is within range, he/she/it will get a save vs
    electricity including any Evasion feats. But no distinction is made for
    reputation; friendlies and neutrals as well as hostiles get hit. The object
    that runs the script never gets hurt.

// ________________
// ** CONSTANTS ***
// ----------------

// Set these variables as local_ints on the IPoint itself.
const string STRIKE_PCT     = "strikepct";      // probability of a lightning strike per heartbeat event (default 100%).
const string STRIKE_RANGE   = "strikerange";    // the range from the IPoint in meters for a creature to become a valid target (default 5 meters).
const string STRIKE_D6      = "striked6";       // quantity of d6 dice to roll for damage (default 3d6).
const string STRIKE_DC      = "strikedc";       // the SaveDC for a creature hit (default 10 + d6 value incl/ default).

// true enables misschance for the visual effect (but only if there's *not* a
// valid creature to target - if a creature is valid the strike hits directly).
// False strikes at the IPoint location. Note that true requires a rather large
// area to work as intended - that is, for the strike to still be visible.

// _________________
// ** PROTOTYPES ***
// -----------------

// Applies electrical damage and hit-vfx to a creature target.
void Strike(object oTarget);

// ___________
// ** MAIN ***
// -----------
// note: OBJECT_SELF is the IPoint.
void main()
    //SendMessageToPC(GetFirstPC(FALSE), "Run ( lightstrike ) " + GetName(OBJECT_SELF) + " ( " + GetTag(OBJECT_SELF) + " )");

    int iPct = GetLocalInt(OBJECT_SELF, STRIKE_PCT);
    if (!iPct) iPct = 100;

    if (Random(100) < iPct)
        object oTarget = OBJECT_INVALID;

        object oCreature = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, CREATURE_ALIVE_TRUE);
        if (GetIsObjectValid(oCreature))
            int iRange = GetLocalInt(OBJECT_SELF, STRIKE_RANGE);
            if (!iRange) iRange = 5;

            if (GetDistanceToObject(oCreature) <= IntToFloat(iRange))
                oTarget = oCreature;

        float fDelay = IntToFloat(Random(60)) / 10.f;

        int bMissChance = FALSE;

        if (GetIsObjectValid(oTarget))
            DelayCommand(fDelay, Strike(oTarget));
            oTarget = OBJECT_SELF;
            bMissChance = MISSCHANCE;

        effect eVis = EffectVisualEffect(VFX_SPELL_HIT_CALL_LIGHTNING, bMissChance);
        DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget));

// __________________
// ------------------

// Applies electrical damage and hit-vfx to a creature target.
void Strike(object oTarget)
    int iPower = GetLocalInt(OBJECT_SELF, STRIKE_D6);
    if (!iPower) iPower = 3;

    int iSaveDc = GetLocalInt(OBJECT_SELF, STRIKE_DC);
    if (!iSaveDc) iSaveDc = 10 + iPower;

    int iDamage = GetReflexAdjustedDamage(d6(iPower),
    if (iDamage)
        effect eHit = EffectVisualEffect(VFX_HIT_SPELL_LIGHTNING);
        effect eElectrical = EffectDamage(iDamage, DAMAGE_TYPE_ELECTRICAL, DAMAGE_POWER_ENERGY);
               eElectrical = EffectLinkEffects(eElectrical, eHit);

        ApplyEffectToObject(DURATION_TYPE_INSTANT, eElectrical, oTarget);



I suppose I could create a volume of ipoints and use that approach. Or maybe electrical rays between randomly selected ipoints in the group.


Or wire it up to hit all creatures in range?


Well it’s for a light show really; the discharge will be apparent before entering the volume. I can always zap the party members after they enter the AoE.


The funny thing is that the script above is a modified version of @rjshae’s script he posted on the old forums.



I knew that but I didn’t want to get pedantic. :wink:


lul, i completely forgot …