Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Q&A

Quests::Q&A This is the quest support section

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 12-17-2015, 04:51 AM
ghanja's Avatar
ghanja
Dragon
 
Join Date: Aug 2012
Location: Hershey, PA
Posts: 499
Default

Just to add, for on-lookers. The above example assumes you are running this version of /plugins/check_handin.pl

Code:
# plugin::check_handin($item1 => #required_amount,...);
# autoreturns extra unused items on success
sub check_handin {
    my $hashref = shift;
    my %required = @_;
    foreach my $req (keys %required) {
        if ((!defined $hashref->{$req}) || ($hashref->{$req} != $required{$req})) {
            return(0);
        }
    }
     foreach my $req (keys %required) {
         if ($required{$req} < $hashref->{$req}) {
             $hashref->{$req} -= $required{$req};
         } else {
             delete $hashref->{$req};
         }
     }
     return 1;
}

sub return_items {    
        my $hashref = plugin::var('$itemcount');
        my $client = plugin::val('$client');
        my $name = plugin::val('$name');
        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') ],
        );
        
        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.");
                                        $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;

}

sub mq_process_items {
        my $hashref = shift;
        my $npc = plugin::val('$npc');
        my $trade = undef;
        
        if($npc->EntityVariableExists("_mq_trade")) {
                $trade = decode_eqemu_item_hash($npc->GetEntityVariable("_mq_trade")); 
        } else {
                $trade = {};
        }
        
        foreach my $k (keys(%{$hashref})) {
                next if($k == 0);
                
                if(defined $trade->{$k}) {
                        $trade->{$k} = $trade->{$k} + $hashref->{$k};
                } else {
                        $trade->{$k} = $hashref->{$k};
                }
        }
        
        my $str = encode_eqemu_item_hash($trade);
        $npc->SetEntityVariable("_mq_trade", $str);
}

sub check_mq_handin {
        my %required = @_;
        my $npc = plugin::val('$npc');
        my $trade = undef;
        
        if($npc->EntityVariableExists("_mq_trade")) {
                $trade = decode_eqemu_item_hash($npc->GetEntityVariable("_mq_trade"));
        } else {
                return 0;
        }
        
        foreach my $req (keys %required) {
                if((!defined $trade->{$req}) || ($trade->{$req} < $required{$req})) {
                                return 0;
                }
        }
        
        foreach my $req (keys %required) {
                if ($required{$req} < $trade->{$req}) {
                        $trade->{$req} -= $required{$req};
                } else {
                        delete $trade->{$req};
                }
        }
        
        $npc->SetEntityVariable("_mq_trade", encode_eqemu_item_hash($trade));
        return 1;
}

sub clear_mq_handin {
        my $npc = plugin::val('$npc');
        $npc->SetEntityVariable("_mq_trade", "");
}

sub encode_eqemu_item_hash {
        my $hashref = shift;
        my $str = "";
        my $i = 0;
        
        foreach my $k (keys(%{$hashref})) {
                if($i != 0) {
                        $str .= ",";
                } else {
                        $i = 1;
                }
                
                $str .= $k;
                $str .= "=";
                $str .= $hashref->{$k};
        }
        
        return $str;
}

sub decode_eqemu_item_hash {
        my $str = shift;
        my $hashref = { };
        
        my @vals = split(/,/, $str);
        my $val_len = @vals;
        for(my $i = 0; $i < $val_len; $i++) {
                my @subval = split(/=/, $vals[$i]);
                my $subval_len = @subval;
                if($subval_len == 2) {
                        my $key = $subval[0];
                        my $value = $subval[1];
                        
                        $hashref->{$key} = $value;
                }
        }
        
        return $hashref;
}
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 01:15 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3