Author Sticky: Post Working Scripts Here
ligaman Posted: Sunday, 30 June 08:43PM
NWScript:
//Script: Proximity_Killer 

// (thanks to Albert Shih (Calidarien) for Alert() 

// function)

//Author: Frank Liga

//Version: v0.9, 2002-06-30

//Description: When a creature gets near the item with a 

// that is an enemy faction

//the creature will be killed.

//Usage: Attach to OnHeartbeat of the module/area

//Notes:

// 1. Create any number of obects with the same tag (i used a portal but you can use any object)

// 2. Create a Faction that is Friendly to PCS, Hostile to Hostiles,

//      and neutral to everyone else

// 3. Give the newly created Items this faction

// 4. Place this script in the module/area heartbeat event

// 5. Set the 3 variables (you can kill iDEBUG after you test it out)

// ITEM_KILL_TAG =  tag of the object

// VFX_EFFECT = the visual affect you want to kill the creatur

// PROXIMITY_DISTANCE how close the creature needs to be to set it off

//  v0.9: Pretty cool

//

string ITEM_KILL_TAG = "MyObject";

float PROXIMITY_DISTANCE = 30.;

int VFX_EFFECT = VFX_FNF_GAS_EXPLOSION_EVIL;

int iDEBUG = TRUE;

void Alert(string szMessage) {

  if(iDEBUG == TRUE) {

    object oPC = GetFirstPC();

    SendMessageToAllDMs(szMessage);

    while(GetIsObjectValid(oPC)) {

      SendMessageToPC(oPC, szMessage);

      oPC = GetNextPC();

    }

  }

}

//

// Checks how close a creature is and kills it

// if within proximity

void SeakAndDestroy(object oCenter, float fDist) {

  int nCounter = 0;

  float fCreatureDist = 0.0;

  object oCreature;

  int TestFlag=0;

  while(GetIsObjectValid(oCreature = 

    GetNearestObject(OBJECT_TYPE_CREATURE, oCenter, 

       ++nCounter))) 

    {

      fCreatureDist = 

         GetDistanceBetween(oCenter, oCreature);

      Alert("Creature " + GetTag(oCreature) 

         + " found at " + FloatToString(fCreatureDist));

      if((GetArea(oCenter) == GetArea(oCreature)) 

         && (fCreatureDist < fDist)

         && (GetIsEnemy(oCreature,oCenter)))

      {

        Alert("Killing " + GetTag(oCreature));

        effect eVis = EffectVisualEffect(VFX_EFFECT);

        ApplyEffectToObject(DURATION_TYPE_TEMPORARY,

          eVis, oCreature, 5.0);

      effect eDamage = EffectDamage(10000, 

        DAMAGE_TYPE_MAGICAL, 

        DAMAGE_POWER_PLUS_FIVE);

      

      DelayCommand(1.0, 

        ApplyEffectToObject(DURATION_TYPE_INSTANT,

          eDamage, oCreature));

    }

  }

}

void Nukem(string sTag, float fDist) {

  int nCounter = -1;

  object oItem;

  while(GetIsObjectValid(oItem = 

      GetObjectByTag(sTag, ++nCounter))) 

  {

    SeakAndDestroy(oItem, fDist);

  }

}

//

//Main function

void main() {

  Nukem(ITEM_KILL_TAG, PROXIMITY_DISTANCE);

}