Thread: Check_handin
View Single Post
  #5  
Old 02-17-2013, 06:43 AM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default

i'd do something like this, but i'm extremely picky...

Code:
    elsif (                                 # consume knife only if
        $ulevel < 6                         # client is under level 6
        && !defined $qglobals{jep_knife}    # and has not turned it in yet
        && plugin::check_handin( \%itemcount, 1377 => 1 )
      )
    {
        # FYI: this will allow another turn-in after 30 minutes...
        quest::setglobal( "jep_knife", "1", "4", "M30" );
        quest::exp("20000");
        quest::ding();
    }

    # if the knife has already been turned in
    # and the client is attempting to turn it in again
    my $knife_back = 0;
    if ( defined $qglobals{jep_knife} && defined $itemcount{1377} ) {
        plugin::Whisper( "Oh, $name, you already brought my knife back. "
              . "Thank you though! You can have this one back." );
        my $knife_back = 1;
    }

    # determine how many items are left in %itemcount to return
    # NOTE: we're counting the knife if it has not been addressed above
    # because ( $ulevel > 5 && !defined $qglobals{jep_knife} ) is possible
    my $return_count = ( scalar keys %itemcount ) - $knife_back;

    # if we're returning at least one item that we have not addressed,
    # then we'll use some additional item return flavor text
    # NOTE: %itemcount will always have at least one key (0)
    if ( $return_count > 1 ) {

        # this is the text template we'll use in the call to sprintf
        my $return_template = "I don't want %s. Here, take %s back, $name.";

        # if we have more than 1 item going back that is not addressed,
        # use plural nouns... otherwise, use singular nouns
        my @return_noun =
          $return_count > 2
          ? ( "these", "them" )
          : ( "this", "it" );

        # put the template and the nouns together here
        plugin::Whisper( sprintf $return_template, @return_noun );
    }

    # give stuff back
    plugin::return_items( \%itemcount );
}
i commented everything so you can get an idea of what's going on.
__________________
I muck about @ The Forge.
say(rand 99>49?'try '.('0x'.join '',map{unpack 'H*',chr rand 256}1..2):'incoherent nonsense')while our $Noport=1;
Reply With Quote