83 lines
2.4 KiB
Plaintext
83 lines
2.4 KiB
Plaintext
int nRow=4; //how many squares are there in a row
|
|
int nCol=4; //how many squares are there in a column
|
|
int nPercent=45; //how many percent chance for a lightning
|
|
//bolt on each heartbeat
|
|
|
|
//ALRIGHT, don't change anything else!
|
|
|
|
int nMaxx=10*nRow;//maximum vector X value
|
|
int nMaxy=10*nCol;//maximum vector Y value
|
|
|
|
|
|
|
|
location GetRandomLocation(object oArea)
|
|
{
|
|
int nX=Random(nMaxx)+1;
|
|
int nY=Random(nMaxy)+1;
|
|
|
|
vector vPos=Vector(IntToFloat(nX), IntToFloat(nY), 0.0f);
|
|
|
|
location lRandom=Location(oArea, vPos, 90.0f);
|
|
|
|
return lRandom;
|
|
}
|
|
|
|
void DoLightningDamage(object oTarget)
|
|
{
|
|
//make a saving throw
|
|
int nSave=ReflexSave(oTarget, d20(2), SAVING_THROW_TYPE_ELECTRICITY, OBJECT_SELF);
|
|
|
|
//only creature can make saving throws - this might not be
|
|
//necessary, but just in case. If the object type isn't a
|
|
//creature, we'll set the 'saving throw' to failed
|
|
|
|
if (GetObjectType(oTarget) != OBJECT_TYPE_CREATURE)
|
|
nSave=0;
|
|
|
|
if (nSave==0) //saving throw failed, damage oTarget
|
|
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(d20(2), DAMAGE_TYPE_ELECTRICAL, DAMAGE_POWER_ENERGY), oTarget);
|
|
else if (GetIsPC(oTarget)) //saving throw succesful. If a
|
|
//PC was the target, let them know how close they got.
|
|
SendMessageToPC(oTarget, "You somehow managed to step aside from that lightning bolt.");
|
|
}
|
|
|
|
void HurtObject(object oTarget, location lTarget)
|
|
{
|
|
//what kind of object?
|
|
int nType=GetObjectType(oTarget);
|
|
|
|
//only creatures, placeables and doors can be hurt
|
|
if (nType==OBJECT_TYPE_CREATURE | OBJECT_TYPE_PLACEABLE | OBJECT_TYPE_DOOR)
|
|
{
|
|
//Lightning effect strikes the object
|
|
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_LIGHTNING_M), oTarget);
|
|
//possibly, damage is dealt
|
|
DoLightningDamage(oTarget);
|
|
}
|
|
//for other kinds of objects, lightning just strikes at
|
|
//location
|
|
else ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_LIGHTNING_M), lTarget);
|
|
}
|
|
|
|
|
|
void main()
|
|
{
|
|
//there's nPercent chance of this happening
|
|
if (d100()>nPercent) return;
|
|
|
|
//find a random location for the lightning bolt
|
|
location lTarget=GetRandomLocation(OBJECT_SELF);
|
|
|
|
//is there an object near that location?
|
|
object oTarget=GetFirstObjectInShape(SHAPE_SPHERE, 5.0f, lTarget, FALSE, OBJECT_TYPE_ALL);
|
|
|
|
//if there was an object, there's 5% chance of hitting that
|
|
//instead
|
|
if (GetIsObjectValid(oTarget) && d20()==1)
|
|
HurtObject(oTarget, lTarget);
|
|
|
|
//Lightning strikes the location...
|
|
else ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_LIGHTNING_M), lTarget);
|
|
|
|
}
|