Loading...   


sub return_items {    
	my $hashref = plugin::var('$itemcount');
	my $client = plugin::val('$client');
	my $name = plugin::val('$name');
	my $status = plugin::val('$status');
	my $items_returned = 0;

	my %ItemHash = (
		0 => [ plugin::val('$item1'), plugin::val('$item1_charges'), plugin::val('$item1_attuned') ],
		1 => [ plugin::val('$item2'), plugin::val('$item2_charges'), plugin::val('$item2_attuned') ],
		2 => [ plugin::val('$item3'), plugin::val('$item3_charges'), plugin::val('$item3_attuned') ],
		3 => [ plugin::val('$item4'), plugin::val('$item4_charges'), plugin::val('$item4_attuned') ],
	);
	
	#::: Example output from $_[0] or what is known as hash %itemcount
	#::: $VAR1 = \{
	#::: 	'99048' => 1,
	#::: 	'190100' => 2,
	#::: 	'112801' => 1
	#::: }; 
	
	if($status > 200){
		# use Data::Dumper;
		# print Dumper(\$_[0]);
		use Time::HiRes qw(time);
		use POSIX qw(strftime);

		my $t = time;
		my $date = strftime "%Y%m%d %H:%M:%S", localtime $t;
		$date .= sprintf ".%03d", ($t-int($t))*1000; # without rounding

		print $date, "\n";
		$client->Message(15, "Time is " . localtime() . " time " . time());
		if($client->GetEntityVariable("Recieved_Item") > (time() - .3)){
			$client->Message(15, "Client recieved item, do not hand anything back and return");
			return; 
		}
		elsif($client->GetEntityVariable("DoubleProcessCheck") > (time() - .3)){
			$client->Message(15, "This is a double process");
			$client->Message(15, "Windowed Time " . (time() - $client->GetEntityVariable("DoubleProcessCheck")));
			$client->Message(15, "Stored Time " . $client->GetEntityVariable("DoubleProcessCheck"));
			$client->Message(15, "Window Actual Time " . (time() - 1));
			$client->SetEntityVariable("DoubleProcessCheck", -10000); 
			return;
		}
		else{
			#$client->Message(15, "Setting window time");
			$client->SetEntityVariable("DoubleProcessCheck", time());
		}
	}

	foreach my $k (keys(%{$hashref}))
	{
		next if($k == 0);
		my $rcount = $hashref->{$k};
		my $r;
		for ($r = 0; $r < 4; $r++)
		{
			if ($rcount > 0 && $ItemHash{$r}[0] && $ItemHash{$r}[0] == $k)
			{
				if ($client)
				{
					$client->SummonItem($k, $ItemHash{$r}[1], $ItemHash{$r}[2]);
					quest::say("I have no need for this $name, you can have it back.");
					quest::doanim(64);
					$items_returned = 1;
				}
				else
				{
					# This shouldn't be needed, but just in case
					quest::summonitem($k, 0);
					$items_returned = 1;
				}
				$rcount--;
			}
		}
		delete $hashref->{$k};
	}
	# Return true if items were returned
	return $items_returned;

Raw Paste Data