Author Sticky: Post Working Scripts Here
crashdv Posted: Thursday, 04 July 10:13AM
1. Script Name - NPC Brawl

2. What it does:
The inspiration for this script came from this topic:

Switching factions
Click Here

The idea was to take a group of NPC's and based upon an action, have them take sides and start fighting amongst each other.

3. Notes:
This script will support any number of NPC's (and/or monsters) and any number of factions. In this script, I have three custom factions (A,B,C) and also include the Commoner faction. I had the custom factions hostile to each other, while neutral to everyone else. Out of 16 NPC's, some still remained part of the commoner faction and so became innocent bystanders.

I also included the option to have rally points. So when the script is executed, the NPC's will attempt to make it to the rally points before the actual faction change takes effect. This makes things a bit more interesting.

I chose to use a die roll so that the brawl could be different each time. However it wouldn't be difficult to modify this by hardcoding NPC tags and calling functions.

4. The Script itself

NWScript:
//::///////////////////////////////////////////////

//:: NPC Brawl Script

//:://////////////////////////////////////////////

/*

    The NPC Brawl Script will take a set of NPC's and randomly assign them to different factions,

    which depending on how the factions are setup may result in a total free-for-all.

    Requires the appropriate resources:

       NPC's (or creatures) that are created, where the tag prefix is the same and

       are numbered sequentially.  (Example NPC001, NPC002 ... NPC012, NPC013)

       Rally Points (Objects) which have been setup as a target for all members of a faction

       to rally at.

*/

//:://////////////////////////////////////////////

//:: Created By: crashdv (David Voss)

//:: Created On: 07/04/2002

//:: Last Modified: 07/04/2002

//:://////////////////////////////////////////////

void main()

{

   // NPC Tag Prefix

   string sNPCTagPrefix = "NPC";

   // Max Number of NPC's

   // The tags for the NPC's who will brawl, should share the same

   // tag prefix and also be numbered sequentially, starting at 001.

   int nMaxFaction = 16;

   // Flag for whether or not to use the rally points (0:No;1:Yes)

   int nUseRallyPoints = 1;

   // Flag for random use of taunt animation (0:No;1:Yes)

   int nUseTauntAnimation = 1;

   // Delay for changing faction (in seconds - make sure it is a float - includes the decimal)

   float fDelay = 5.0;

   object oNPC, oFaction_FlagA, oFaction_FlagB, oFaction_FlagC;

   int i, nRoll, nFaction;

   string sNPCTag;

   // Create Faction Flag Objects - if using Rally Points

   if (nUseRallyPoints == 1)

   {

      oFaction_FlagA = GetObjectByTag("Flag_FactionA",0);

      oFaction_FlagB = GetObjectByTag("Flag_FactionB",0);

      oFaction_FlagC = GetObjectByTag("Flag_FactionC",0);

   }

   for (i=1; i < nMaxFaction; i++)

   {

      // Build Tag

      if (i < 10) {sNPCTag = sNPCTagPrefix + "00" + IntToString(i);}

      else if (i < 100) {sNPCTag = sNPCTagPrefix + "0" + IntToString(i);}

      else {sNPCTag = sNPCTagPrefix + IntToString(i);}

      // New Object

      oNPC = GetObjectByTag(sNPCTag,0);

      // Get result of a new die roll

      nRoll = d4(1);

      // Roll for new Faction & Move to rally point

      // Note: When assigning factions, the 0-4 are the default factions (??).

      // New factions start at 5 and up.

      if (GetIsObjectValid(oNPC))

      {

         if (nRoll == 1)       // FACTION A   

         {

            nFaction = 5;

            if (nUseRallyPoints == 1)

            {

               // Have the NPC move to either the object or the location of the object (uncomment one)

               AssignCommand(oNPC,ActionMoveToObject(oFaction_FlagA,1,1.5));

               // AssignCommand(oNPC,ActionMoveToLocation(GetLocation(oFaction_FlagA),1));

            }

         }

         else if (nRoll == 2)  // FACTION B

         {

            nFaction = 6;

            if (nUseRallyPoints == 1)

            {

               // Have the NPC move to either the object or the location of the object (uncomment one)

               AssignCommand(oNPC,ActionMoveToObject(oFaction_FlagB,1,1.5));

               // AssignCommand(oNPC,ActionMoveToLocation(GetLocation(oFaction_FlagB),1));

            }

         }

         else if (nRoll == 3)  // FACTION C

         {

            nFaction = 7;

            if (nUseRallyPoints == 1)

            {

               // Have the NPC move to either the object or the location of the object (uncomment one)

               AssignCommand(oNPC,ActionMoveToObject(oFaction_FlagC,1,1.5));

               // AssignCommand(oNPC,ActionMoveToLocation(GetLocation(oFaction_FlagC),1));

            }

         }

         else if (nRoll == 4)  // COMMONER FACTION

         {

            nFaction = 1;

         }

         // Just make the NPC walk around a bit

         AssignCommand(oNPC,ActionRandomWalk());

         // Check for taunt...

         if (nUseTauntAnimation == 1 && nFaction != 1 && d2() == 2)

         {

            AssignCommand(oNPC,DelayCommand(fDelay,ActionPlayAnimation(ANIMATION_FIREFORGET_TAUNT,1.0,0.0)));

         }

         // Change Faction

         DelayCommand((fDelay+1.0),ChangeToStandardFaction(oNPC, nFaction));

      }

    }

}



[ Edited By crashdv: Thursday, 04 July 10:15AM (GMT) ]