Clan [uBp]™ :: Neverwinter Nights DivisionClan [uBp]™ :: Neverwinter Nights Division :: NewsClan [uBp]™ :: Neverwinter Nights Division :: AboutClan [uBp]™ :: ForumsClan [uBp]™ :: Neverwinter Nights Division :: Contact
Account Login
User Name:
Password:

Join Us!

 
Menu
Links
Neverwinter Nights
 
 

Loot Splitter Script: int GetNumberOfPartyMembers(object oMember);
int SellInventory(object oContainer = OBJECT_SELF);
void GivePartyGold(object oMember, int nGold);

// main loop called OnClose event
void main()
{
object oLastOpener = GetLastOpenedBy();
if( GetIsObjectValid( oLastOpener ) )
return;

int nPartySize = GetNumberOfPartyMembers( oLastOpener );
if( nPartySize <= 0 )
return;

int nValue = SellInventory();
if( nValue <= 0 )
return;

// figure out share, with a minimum of 1 gp each
int nShare = nValue/nPartySize;
if( nShare < 1 )
nShare = 1;

GivePartyGold(oLastOpener, nShare);

object oPC = GetFirstPC();
while( GetIsObjectValid( oPC ) ) // Loop through all the Players
{
if(GetIsObjectValid( GetItemInSlot( INVENTORY_SLOT_CARMOUR, oPC ) ) )
{
ExecuteScript("ws_saveall_sub", oPC);
}

oPC = GetNextPC();
}

//SendMessageToAllDMs( "All characters saved at [uBp] loot splitter." );
ExportAllCharacters(); // optional line, stops people from complaining they've lost stuff after splitting

if( nPartySize >= 3 )
{
ActionSpeakString( "All " + IntToString( nPartySize ) + " party members have received " +
IntToString( nShare ) + " GP as their share of " +
IntToString( nValue ) + " GP in treasure." );
}
else if( nPartySize == 2 )
{
ActionSpeakString( "Both party members have received " +
IntToString( nShare ) + " GP as their share of " +
IntToString( nValue ) + " GP in treasure." );
}
else if( nPartySize == 1 )
{
ActionSpeakString("You're the only one in the party! You got " +
IntToString( nShare ) + " GP in treasure." );
}
}

// Sells all the items in a givent inventory and returns the value
//
// oContainer container to search
int SellInventory(object oContainer = OBJECT_SELF)
{
int nItems = 0;
int nValue = GetGold( oContainer );
int nCurValue;
float nPercent;
int bShowContainerWarning = TRUE;

object oItem = GetFirstItemInInventory( oContainer );
while( GetIsObjectValid( oItem ) )
{
if ( !GetIdentified( oItem ) )
{
SetIdentified( oItem, TRUE );
}

// don't sell off containers
if( GetHasInventory( oItem ) )
{
// recursively calling GetInventorySellValue(oItem) causes
// a crash on the last GetNextItemInInventory() for the oItem
// all of the items in containers are found in the loot seller
if( bShowContainerWarning )
{
ActionSpeakString( "I will not puchase containers from you." );
bShowContainerWarning = FALSE;
}
}
// sell off non plot items with a value over 0 gold
else if( !GetPlotFlag( oItem ) && GetGoldPieceValue( oItem ) > 0 )
{
nCurValue = FloatToInt( GetGoldPieceValue( oItem ) * 1.0);
nValue += nCurValue;
}
DestroyObject( oItem );

oItem = GetNextItemInInventory( oContainer );
nItems++;
}

if( GetGold( oContainer ) != 0 )
{
AssignCommand( oContainer, TakeGoldFromCreature( GetGold( oContainer ), oContainer, TRUE ) );
}

return nValue;
}
// gives gold to each party member // // oMember PC in target party // nGold amount of gold to give each member void GivePartyGold( object oMember, int nGold ) { object oPartyMember = GetFirstFactionMember( oMember, TRUE ); while ( GetIsObjectValid( oPartyMember ) ) { GiveGoldToCreature( oPartyMember, nGold ); oPartyMember = GetNextFactionMember( oMember, TRUE ); } } // Returns the number of PCs in oMember's party // // oMember PC in target party int GetNumberOfPartyMembers( object oMember ) { int nCount = 0; object oPartyMember = GetFirstFactionMember( oMember, TRUE ); while( GetIsObjectValid( oPartyMember ) ) { nCount += 1; oPartyMember = GetNextFactionMember( oMember, TRUE ); } return nCount; }

 
 

           Mad Allendry:

  
 
Project Offset
Wizards of the Coast (D&D Tabletop)
Dungeon & Dragons Online
 
       
       
       
       
   Copyright © 2006, 2007, 2008 Clan [uBp]™. All rights reserved.