View Single Post
  #11  
Old 02-16-2012, 06:01 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Ahh, I misunderstood your reason for wanting to remove the item. If you are adding them via a script, then you have full control over if they get added or not. Why not just add the item to the corpse after it dies or at the time of death or attack or any number of possible spots instead of adding it all on spawn? That will reduce the work load on the server a bit when your zone is spawned, since it won't be doing it for all NPCs at once, just when needed.

I have a somewhat similar plugin I use that adds loot when combat is started. Basically I use it to scale loot drop rates to the size of the group that engaged the NPC. The idea is to help promote grouping by giving increased quest item drop rates and such based on the size of the group so you aren't penalized by drops as much when grouping. People should be more willing to open up group slots to others if they know it won't take them 6X as long to get the drops they need.

This plugin does have a trivial loot code option if you set it. I can give an example of usage if you need. It could probably work to do what you are wanting without actually scaling the drop rates. Though, it looks like the trivial check wasn't added to the non-group sections of the plugin (as I don't use that option yet anyway), so you would need to modify it slightly.

Code:
###Usage: plugin::ScaleDropToGroup(item_id, Chance[1-100], Scale[1-100]=100, Group_Only=0, Max_Chance=100, Trivial=0);
# Drops an item X amount of times depending on how many clients are in the group.
# Chance is the overall chance for the item to drop
# Scale is the rate that the drop chance decreases to for each additional member (Diminishing return)
# Group_Only is an optional setting.  If 0, solo players will have a chance for this to drop.  If 1, only groups will have a chance for the drop.
# The Group Only option is primarily for adding an item that already exists in the NPC's loot table.
# Max_Chance option allows the chance range to be increased above the default 100.
# Setting Max_Chance to 1000 will make the chance roll from 1 to 1000 instead of 1 to 100 which allows drop rates less than 1%.
# Trivial can enable the trivial loot checks to restrict scaling drops to only groups who can earn experience from the kill (default is disabled 0).
# Example 1: plugin::ScaleDropToGroup(1001, 100, 80);
# This example gives the item a 100% chance to be added, but each additional member reduces that chance to 80% of the previous chance
# Example 2: plugin::ScaleDropToGroup(1001, 5, 80, 1);
# This example gives the item a 5% chance to be added, but each additional member reduces that chance to 80% of the previous chance
# Example 2 will not add the item if an ungrouped client is fighting the NPC.
# Example 3: plugin::ScaleDropToGroup(1001, 1, 100, 0, 500, 1);
# This example will give the item a 0.1% drop chance for each member in the group or for solo players, but only scales to the group if they can get exp from the kill

sub ScaleDropToGroup {
	my $npc = plugin::val('$npc');
	my $client = plugin::val('$client');
	my $userid = plugin::val('$userid');
	my $entity_list = plugin::val('$entity_list');
	my $item_id = $_[0];
	my $drop_chance = $_[1];	# Chance
	my $per_member_chance = $_[2];	# Scale
	my $group_only = $_[3];
	my $max_chance = $_[4];
	my $trivial = $_[5];

	# If the event was triggered by a pet, get the pet's owner as the client
	my $Attacker = $entity_list->GetMobByID($userid);
	my $Owner = 0;
	my $PetOwnerID = 0;
	my $SwarmOwnerID = 0;
	if ($Attacker && $Attacker->IsNPC())
	{
		$PetOwnerID = $Attacker->CastToNPC()->GetOwnerID();
		$SwarmOwnerID = $Attacker->CastToNPC()->GetSwarmOwner();
	}
	if ($PetOwnerID)
	{
		$Owner = $entity_list->GetClientByID($PetOwnerID);
	}
	if ($SwarmOwnerID)
	{
		$Owner = $entity_list->GetClientByID($SwarmOwnerID);
	}
	if ($Owner)
	{
		$client = $Owner;
	}

	if (!$max_chance) { $max_chance = 100; }
	if ($drop_chance > $max_chance) { $drop_chance = $max_chance; }
	if (!$per_member_chance) { $per_member_chance = 100; }

	my $Charge = 0;	
	my $Stack_Size = $npc->GetItemStat($item_id, "stacksize"); 
	my $Has_Charge = $npc->GetItemStat($item_id, "maxcharges"); 
	if ($Stack_Size >= 1) { $Charge = 1; }
	if ($Has_Charge >= 1) { $Charge = $Has_Charge; }

	#plugin::Debug("Starting Plugin");
	# Verify all of the required fields are set properly
	if ($drop_chance > 0 && $item_id)
	{
		if($client)	# Verify we got a client
		{
			my $ClientGroup = $client->GetGroup();	# Check if the client is in a group
			if ($ClientGroup)
			{
				#plugin::Debug("Got Group");
				my $GroupCount = $ClientGroup->GroupCount();	# Count the group members
				my $NPCLevel = $npc->GetLevel();
				my $HighLevel = $ClientGroup->GetHighestLevel();
				my $ExpMaxLevel = (($NPCLevel / 3) * 4);
				#plugin::Debug("Highest Level is $HighLevel - NPC Max Exp Level is $ExpMaxLevel");
				if (!$trivial || $HighLevel <= $ExpMaxLevel)
				{
					if ($GroupCount > 1)
					{
						# Create the variable that tracks the highest number of opponents this NPC has had since it spawned
						if (!$npc->EntityVariableExists($item_id))
						{	
							$npc->SetEntityVariable($item_id, 1);
						}
						my $DropTotal = $npc->GetEntityVariable($item_id);
						#plugin::Debug("Group Total $GroupCount, NPC Total $DropTotal");
						if ($GroupCount > $DropTotal)
						{
							# Save the highest number of opponents
							$npc->SetEntityVariable($item_id, $GroupCount);
							my $scale_rate = 100;
							#plugin::Debug("Scale Rate $scale_rate");
							# Run a loop to do the math and add loot
							my $StartCount = 1;
							if ($group_only)
							{
								$StartCount = 2;
							}
							for ($count = $StartCount; $count <= $GroupCount; $count++)
							{
								#plugin::Debug("Count $count");
								$scale_rate = $scale_rate * $per_member_chance / 100;
								if ($count > $DropTotal)
								{
									#plugin::Debug("Ready to roll to add the loot");
									my $ActualChance = $drop_chance * $scale_rate / $max_chance;
									my $RandomNum = plugin::RandomRange(1, $max_chance);
									#plugin::Debug("Actual Chance $ActualChance - Random Number $RandomNum");
									if ($ActualChance >= $RandomNum)
									{
										#plugin::Debug("Dropping $loottable with an actual chance of $ActualChance and group count of $GroupCount");
										$npc->AddItem($item_id, $Charge, 0);
										#plugin::Debug("Group Drop Added");
									}
								}
							}
						}
					}
				}
			}
			else	# No Group
			{
				if (!$group_only)
				{
					# Create the variable that tracks that this has been rolled for once already
					if (!$npc->EntityVariableExists($item_id))
					{	
						$npc->SetEntityVariable($item_id, 1);
						my $RandomNum = plugin::RandomRange(1, $max_chance);
						if ($drop_chance >= $RandomNum)
						{
							$npc->AddItem($item_id, $Charge, 0);
							#plugin::Debug("Solo Drop Added");
						}
					}
				}
			}
		}
		else	# No Client Attacking
		{
			if (!$group_only)
			{
				# Create the variable that tracks that this has been rolled for once already
				if (!$npc->EntityVariableExists($item_id))
				{	
					$npc->SetEntityVariable($item_id, 1);
					my $RandomNum = plugin::RandomRange(1, $max_chance);
					if ($drop_chance >= $RandomNum)
					{
						$npc->AddItem($item_id, $Charge, 0);
						#plugin::Debug("Solo Drop Added");
					}
				}
			}
		}
	}
}
For what you are doing, something as simple as the below plugin is probably a better example. This one just for adding loot with a random chance:

Code:
###Usage: plugin::AddLoot( item_id, chance[1-100]);
# This plugin will just add loot with a chance
# If add rare chance field, can extend range past 100;

sub AddLoot {

	my $ItemId = $_[0];
	my $Chance = $_[1];
	my $Rare_Chance = $_[2];
	my $npc = plugin::val('$npc');

	my $Charge = 0;	
	my $Stack_Size = $npc->GetItemStat($ItemId, "stacksize"); 
	my $Has_Charge = $npc->GetItemStat($ItemId, "maxcharges"); 
	if ($Stack_Size >= 1) { $Charge = 1; }
	if ($Has_Charge >= 1) { $Charge = $Has_Charge; }
	
	if (!defined($Chance))
	{
		quest::addloot($ItemId, $Charge, 0);
	}
	
	if ((defined($Chance)) && (!defined($Rare_Chance)))
	{
		my $Get_Rand = plugin::RandomRange(1, 100);
		#plugin::Debug("Attempt :: Loot Add! $ItemId $Chance >= $Get_Rand");

		if ($Chance >= $Get_Rand)
		{
			quest::addloot($ItemId, $Charge, 0);
			#plugin::Debug("Loot Add! $ItemId");
		}
	}

	if ((defined($Chance)) && (defined($Rare_Chance)))
	{
		my $Get_Rand2 = plugin::RandomRange(1, $Rare_Chance);
		if ($Chance >= $Get_Rand2)
		{
			quest::addloot($ItemId, $Charge, 0);
			#plugin::Debug("Loot Add! $ItemId");
		}
	}
}
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!

Last edited by trevius; 02-16-2012 at 06:06 AM..
Reply With Quote