View Single Post
  #2  
Old 12-13-2012, 03:13 PM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default another short one

this plugin will reduce the length of quest conditions where multiple qglobals are checked in a single statement.

Code:
# checks that quest globals are defined and set to values passed in parameters
# usage: my $flagged = plugin::IsFlagged(key=>val, ...);
sub IsFlagged
{
    my %flag = @_;
    return 0 unless %qglobals;
    while (my ($key, $val) = each %flag) {
        return 0 unless defined $qglobals{$key} and $qglobals{$key} == $val;
    }
    1;
}
this, for example:
Code:
if (defined $qglobals{bic}     && $qglobals{bic}     == 10
&&  defined $qglobals{bic_fer} && $qglobals{bic_fer} == 11
&&  defined $qglobals{bic_riw} && $qglobals{bic_riw} == 10
&&  defined $qglobals{bic_bar} && $qglobals{bic_bar} ==  6
&&  defined $qglobals{bic_qin} && $qglobals{bic_qin} ==  4) {
    # do whatever here
}
becomes this:
Code:
my $flagged = plugin::IsFlagged(bic=>10, bic_fer=>11, bic_riw=>10, bic_bar=>6, bic_qin=>4);
if ($flagged) {
    # do whatever here
}
or this:
Code:
if (plugin::IsFlagged(bic=>10, bic_fer=>11, bic_riw=>10, bic_bar=>6, bic_qin=>4)) {
    # do whatever here
}

Last edited by c0ncrete; 12-13-2012 at 03:15 PM.. Reason: removed die
Reply With Quote