Skip to content

Instantly share code, notes, and snippets.

@Akkadius
Created March 14, 2017 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akkadius/ffb7d4f66c7f9dd5eb812ec89671dc06 to your computer and use it in GitHub Desktop.
Save Akkadius/ffb7d4f66c7f9dd5eb812ec89671dc06 to your computer and use it in GitHub Desktop.
sub stop_return {
use Time::HiRes qw(time);
my $client = plugin::val('$client');
$client->SetEntityVariable("Stop_Return", time());
}
sub return_items {
my $hashref = plugin::var('$itemcount');
my $client = plugin::val('$client');
my $npc = plugin::val('$npc');
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
#::: };
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
if($debug == 1){
print $date, "\n";
$client->Message(15, "Time is " . localtime() . " time " . time());
}
if($client->GetEntityVariable("Stop_Return") > (time() - .5)){
if($debug == 1 || $status > 200){
$client->Message(15, "Recieved quest signal to stop item return");
$client->Message(15, "Recieved item time is " . $client->GetEntityVariable("Stop_Return") . " difference is " . ($client->GetEntityVariable("Stop_Return") - time()));
$client->Message(15, "Stop Return is " . $client->GetEntityVariable("Stop_Return") . " Current is " . ((time() - .5)) . " diff_cur is " . ($client->GetEntityVariable("Stop_Return") - (time() - .5)));
}
#quest::write("EZlog/EZ_Log_Item_Return.txt", localtime() . " ::" . $client->GetCleanName() . " :: [" . plugin::val('$zonesn') . "] :: NPCID " . $npc->GetNPCTypeID() . " : " . $npc->GetCleanName() . " : Items:: " . plugin::val('$item1') . "," . plugin::val('$item2'). "," . plugin::val('$item3') . "," . plugin::val('$item4') . " :: Time Window " . ($client->GetEntityVariable("Stop_Return") - (time() - .5)));
#quest::write("EZlog/EZ_Log_Item_Return.txt", " Window (Stop_Return) SR:: " . $client->GetEntityVariable("Stop_Return") . " CR:: " . time() . " DIFF:: " . (time() - $client->GetEntityVariable("Stop_Return")) . "");
return;
}
elsif($client->GetEntityVariable("Recieved_Item") > (time() - .5)){
if($debug == 1){
$client->Message(15, "Recieved item time is " . $client->GetEntityVariable("Recieved_Item") . " difference is " . ($client->GetEntityVariable("Recieved_Item") - time()));
$client->Message(15, "Client recieved item, do not hand anything back and return");
}
quest::write("EZlog/EZ_Log_Item_Return.txt", localtime() . " ::" . $client->GetCleanName() . " :: [" . plugin::val('$zonesn') . "] :: NPCID " . $npc->GetNPCTypeID() . " : " . $npc->GetCleanName() . " : Items:: " . plugin::val('$item1') . "," . plugin::val('$item2'). "," . plugin::val('$item3') . "," . plugin::val('$item4') . " :: Time Window " . ($client->GetEntityVariable("Recieved_Item") - (time() - .5)));
quest::write("EZlog/EZ_Log_Item_Return.txt", " Window (Recieved_Item) SR:: " . $client->GetEntityVariable("Recieved_Item") . " CR:: " . time() . " DIFF:: " . (time() - $client->GetEntityVariable("Recieved_Item")) . "");
return;
}
elsif($client->GetEntityVariable("DoubleProcessCheck") > (time() - .5)){
if($debug == 1){
$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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment