Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Plugins & Mods

Quests::Plugins & Mods Completed plugins for public use as well as modifications.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 12-13-2012, 04:37 PM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default

valid point.

Code:
sub IsFlagged
{
    my %flag = @_;
    return 0 unless %qglobals;
    while (my ($key, $val) = each %flag) {
        if (ref $val eq 'HASH') {
            my $op = $key;
            unless ($op ~~ ['==', '>=', '>', '<=', '<', '!=']) {
                warn "invalid operator ($key) found in plugin::IsFlagged()";
                warn "skipped ".keys(%$val)." check(s)";
                next;
            }
            while (my ($key, $val) = each %{$val}) {
                return 0 unless defined $qglobals{$key}
                    and eval "$qglobals{$key} $op $val";
            }
        }
        else {
            return 0 unless defined $qglobals{$key}
                and $qglobals{$key} == $val;
        }
    }
    1;
}
now you can pass an operator as a key with an anonymous hash reference as a value (containing all the key/value pairs you want to check using that operator). if no operator is found (well, it's actually checking for a hash reference as a value), it defaults to ==.

example:
Code:
my $flagged = plugin::IsFlagged('>=' => {bic_quin => 4}, bic_fer => 11, bic_riw => 10);
would make sure $qglobals{bic_quin} was greater than or equal to 4, and that $qglobals{bic_fer} was equal to 11 and $qglobals{bic_riw} was equal to 10.

EDIT:
changed it to where it will only accept numeric comparison operators. that way an accidental assignment won't happen in eval.

Last edited by c0ncrete; 12-13-2012 at 05:16 PM.. Reason: improved example's legiblity and added sanity check.
Reply With Quote
 

Thread Tools
Display Modes

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 09:37 PM.


 

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