//////////////////////////////////////////////////////////////////////////////// // // Script: loot_splitter // // Use: Split loot between all party members, but identifies them first. // // Date: 03.18.2005 // // By: Robert Stehwien (rstehwien@hotmail.com) // // Updated: 07.30.09 // // By: Birdman076 // //////////////////////////////////////////////////////////////////////////////// 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) == FALSE ) 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); // ===== This is the code you need to add ===== 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(); } // while //SendMessageToAllDMs( "All characters saved at loot splitter." ); ExportAllCharacters(); 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 given 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) ) { // new code, 06/04/2005, to identify all items before selling! 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( "You cannot split containers!" ); 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; }