Author Sticky: Post Working Scripts Here
Selar Posted: Saturday, 29 June 03:29AM
1. Mimic (Monster in a box)

2. Makes a placeable object attack back.

3. This script might not be the cleanest thing around, but it does work.

Put this in onHeartbeat

NWScript:
void Mimic_Attacks(int myAttack, int opposingAC, object target, float delay=0.0);

void main()

{

   // How mad the mimic is, it will stop attacking after

   // it calms down.

   int IAmAngry = GetLocalInt( OBJECT_SELF, "HowMad" );

   object oPC = GetLastUsedBy();

   object oNPC = OBJECT_SELF;

   //The mimic base attack.

   int MyAttack = 15;

   //mimic stops once calmed down or the PC is too far

   if ( GetDistanceToObject(oPC) < 5.0 && IAmAngry)  {

       // mkae sure I'm open

       if ( !GetIsOpen(OBJECT_SELF) )

           ActionPlayAnimation(ANIMATION_PLACEABLE_OPEN);

       // Find out who's been hurting me

       if ( GetLastDamager() != OBJECT_INVALID) oPC = GetLastDamager();

       Mimic_Attacks(15, GetAC(oPC), oPC);

       Mimic_Attacks(15, GetAC(oPC), oPC,3.0);

       //Get less mad

       SetLocalInt( OBJECT_SELF, "HowMad", --IAmAngry);

    }

}

void Mimic_Attacks(int myAttack, int opposingAC, object target, float delay)

{

   //myAttack = mimic's base attack

   //opposingAC = duh

   //target = duh

   //delay = how long before actually making the attack

   //check to hit, then run animations and damage.

   if ( (myAttack + d20()) >= opposingAC) {

       DelayCommand(delay, ApplyEffectToObject(DURATION_TYPE_INSTANT,

                       EffectDamage( d8(), DAMAGE_TYPE_NEGATIVE ),

                       target));

       ActionPlayAnimation(ANIMATION_PLACEABLE_CLOSE);

       ApplyEffectToObject(DURATION_TYPE_INSTANT,

               EffectVisualEffect( VFX_COM_HIT_NEGATIVE ),

               target );

       DelayCommand(1.0, ActionPlayAnimation(ANIMATION_PLACEABLE_OPEN));

   }

   else {

       DelayCommand(delay, ActionPlayAnimation(ANIMATION_PLACEABLE_CLOSE));

       DelayCommand(1.0, ActionPlayAnimation(ANIMATION_PLACEABLE_OPEN));

   }

}



In onUsed:

NWScript:
void main()

{

  //hits you if you try to use it

  ApplyEffectToObject(DURATION_TYPE_INSTANT,

                       EffectDamage( d6() ),

                       GetLastUsedBy());

  SetLocalInt( OBJECT_SELF, "HowMad", 1);

}



In onDamaged, onPhysicalAttack, and onSpellCastAt:

NWScript:
void main()

{

  //Stays mad while being attacked.

  SetLocalInt( OBJECT_SELF, "HowMad", 3);

}



I included an explosion death for kicks using some of the code that I found on this thread. I also added some XP for killing it.

Put this in onDeath, if you just want the xp, take out everything but the include and the RewardXP function.

NWScript:
#include "nw_i0_tool"

void main()

{

   location loc = GetLocation(OBJECT_SELF);

   ApplyEffectAtLocation(DURATION_TYPE_INSTANT,

                           EffectVisualEffect( VFX_FNF_FIREBALL ),

                           loc);

   object newTarget = GetFirstObjectInShape(SHAPE_SPHERE, 10.0, loc);

   while (newTarget != OBJECT_INVALID)

   {

       if ( GetIsPC(newTarget) )

           ApplyEffectToObject( DURATION_TYPE_INSTANT,

                                EffectDamage ( d6(2), DAMAGE_TYPE_FIRE ),

                                newTarget);

       newTarget = GetNextObjectInShape(SHAPE_SPHERE, 10.0, loc);

   }

   RewardPartyXP(1000, GetLastAttacker());

}



It works fine for me, but if there's any problems, I'll try to fix it. Also make sure that you give the item more hit points than normal or it'll be too easy to kill.

Edit

Author Sticky: Post Working Scripts Here
Selar Posted: Saturday, 29 June 07:57PM
Hmm, I would liked to have editted my post above, but it won't let me anymore so...

I cleaned up the onHeartbeat script for my mimic some. It now attacks when its supposed to and tells the player its attacking whether it hit or not.

NWScript:
void Mimic_Attacks(int myAttack, int opposingAC, object target);

void main()

{

   int IAmAngry = GetLocalInt( OBJECT_SELF, "HowMad" );

   object oPC = GetLastUsedBy();

   object oNPC = OBJECT_SELF;

   if ( GetDistanceToObject(oPC) < 5.0 && IAmAngry)  {

       if ( !GetIsOpen(OBJECT_SELF) )

           ActionPlayAnimation(ANIMATION_PLACEABLE_OPEN);

       if ( GetLastDamager() != OBJECT_INVALID) oPC = GetLastDamager();

       Mimic_Attacks(15, GetAC(oPC), oPC);

       DelayCommand(3.0, Mimic_Attacks(15, GetAC(oPC), oPC));

       SetLocalInt( OBJECT_SELF, "HowMad", --IAmAngry);

    }

}

void Mimic_Attacks(int myAttack, int opposingAC, object target)

{

   int attackRoll = d20();

   int myToHit = myAttack + attackRoll;

   string roll = IntToString( myAttack ) + " + " + IntToString( attackRoll )

                + " = " + IntToString( myToHit );

   if ( myToHit >= opposingAC) {

       string hit = "Mimic attacks you and hits: ";

       hit += roll + ".";

       SendMessageToPC(target, hit);

       int dmgAmount = d8();

       ApplyEffectToObject(DURATION_TYPE_INSTANT,

                  EffectDamage(dmgAmount, DAMAGE_TYPE_NEGATIVE),

                  target);

       ActionPlayAnimation(ANIMATION_PLACEABLE_CLOSE);

       ApplyEffectToObject(DURATION_TYPE_INSTANT,

               EffectVisualEffect( VFX_COM_HIT_NEGATIVE ),

               target );

       DelayCommand(1.0, ActionPlayAnimation(ANIMATION_PLACEABLE_OPEN));

   }

   else {

       string miss = "Mimic attacks you and misses: ";

       miss += roll + ".";

       SendMessageToPC( target, miss );

       ActionPlayAnimation(ANIMATION_PLACEABLE_CLOSE);

       DelayCommand(1.0, ActionPlayAnimation(ANIMATION_PLACEABLE_OPEN));

   }

}