Robson » Code Viewer

//::///////////////////////////////////////////////
//:: Break Parties Script
//:: s_breakparties
//:: Copyright (c) 2004 Icey
//:://////////////////////////////////////////////
/*
 
   Large PC parties generate more lag than the
   same number of people in smaller parties.
 
   This script runs through everyone in the
   server and checks the size of their party. If
   it's larger than the maximum allowed, all
   members of the faction are sent a message and
   removed from the faction.
 
       ** THIS SCRIPT HAS NOT BEEN TESTED **
 
*/
//:://////////////////////////////////////////////
//:: Created By: Icey (iceyboard.no-ip.org)
//:: Created On: 3rd August, 2004
//:://////////////////////////////////////////////
 
//* FUNCTION DECLARATIONS *//
 
// returns the size of a faction when given a member
int GetFactionSize(object oMember);
 
// removes all members of the faction, just for PC factions
// oMember = Any member of the faction
void DestroyFaction(object oMember);
 
//* CONSTANTS *//
 
// the maximum amount of people allowed in a party
// this must be 1 or more
// setting to 1 will destroy all parties
const int IC_MAX_PARTY_SIZE = 7;
 
// the message sent to explain why a party was destroyed
const string IC_TALK_DESTROY_PARTY = "Large parties generate more lag so your party has been destroyed. Use smaller parties in future.";
// the message to send when the max party size is invalid
// the invalid amount is shown after this
const string IC_TALK_INVALID = "The maximum allowed party size is too small. It is: ";
 
//* FUNCTIONS *//
 
// returns the size of a faction when given a member
int GetFactionSize(object oMember)
{
   // this will store the amount of people in the party
   int nFactionSize = 0;
   // get the first member of the party, and only get pcs
   object oMember = GetFirstFactionMember(oMember, TRUE);
   // loop while we found another member of the party
   while (GetIsObjectValid(oMember))
   {
       // don't check dms
       if (!GetIsDM(oMember)
           && !GetIsDMPossessed(oMember))
           // increment the counter
           nFactionSize++;
       // get the next pc in the party
       oMember = GetNextFactionMember(oMember, TRUE);
   }
   // return the number of people in the party
   return nFactionSize;
}
 
// removes all members of the faction, just for PC factions
void DestroyFaction(object oMember)
{
   // get the first member of the party, and only get pcs
   object oMember = GetFirstFactionMember(oMember, TRUE);
   // loop while we found another member of the party
   while (GetIsObjectValid(oMember))
   {
       // don't remove dm's from parties
       if (!GetIsDM(oMember) &&
           !GetIsDMPossessed(oMember))
       {
           // tell them why they are being removed from the party
           SendMessageToPC(oMember, IC_TALK_DESTROY_PARTY);
           // make them leave the party
           RemoveFromParty(oMember);
       }
       // get the next pc in the party
       oMember = GetNextFactionMember(oMember, TRUE);
   }
}
 
// main function, see header for details of this script
void main()
{
   // check if the max party size is invalid
   if (IC_MAX_PARTY_SIZE < 1)
       // sent to all dm's so that this script can be run from a conversation/wand/console/etc
       SendMessageToAllDMs(IC_TALK_INVALID + "'" + IntToString(IC_MAX_PARTY_SIZE) + "'.");
   // if it's valid, run the code
   else
   {
       // get the first pc
       object oPC = GetFirstPC();
       // only loop while there are more pcs
       while (GetIsObjectValid(oPC))
       {
           // don't check if this is a dm
           if (!GetIsDM(oPC) &&
               !GetIsDMPossessed(oPC))
           {
               // check if the party is bigger than the allowed max size
               if (GetFactionSize(oPC) > IC_MAX_PARTY_SIZE)
                   // destroy the faction
                   DestroyFaction(oPC);
           }
           // find the next pc in the module
           oPC = GetNextPC();
       }
   }
}