EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Q&A (https://www.eqemulator.org/forums/forumdisplay.php?f=599)
-   -   Random Quest (https://www.eqemulator.org/forums/showthread.php?t=42415)

zack221 04-22-2019 10:17 AM

Random Quest
 
Answered..

Sturm 04-22-2019 12:25 PM

You would have to define each possible turn-in combination.

zack221 04-22-2019 12:28 PM

ah right ok Thanks

Sturm 04-23-2019 09:37 AM

Not sure why you redacted your question, it might help someone in the future.

So he asked: How would you make a turn-in that could be 4 of any of the 10 items needed.

c0ncrete 04-23-2019 03:47 PM

Quote:

Originally Posted by Sturm (Post 262248)
You would have to define each possible turn-in combination.


What? No.

Code:

# list of 10 possible item ids
my @find = (
    0,
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9
);

# items found
my @found;

# items turned in (automatically exported in API)
# (item id => count)
my %itemcount = (
    1 => 1,
    3 => 1,
    7 => 2,
    a => 1
);

foreach my $item (keys %itemcount) {
    # validate item and make sure it is unique
    if ((grep /$item/, @find) && (!grep /$item/, @found)) {
        push @found, $item;
    }
    # only required if count will be less than 4 (max item ids that can be turned in)
    last if (@found == 4);
  }

print "found " . scalar @found . " of 4 required items ";

# minimum number of validated items
if (@found == 4) {
    print "(PASS)\n";
    # to accept only one of each validated item handed in - UNTESTED
    # plugin::check_handin(\%itemcount, map { $_ => 1 } @found);
} else {
    print "(FAIL)\n";
}

note: the above example assumes 4 unique item ids are required for success

Sturm 04-23-2019 04:23 PM

There ya go, if you're a wizard you can do it that way.

See, it pays to leave the original question.

There's always a different way to do things! haha

c0ncrete 04-23-2019 04:41 PM

Seeing the answer without knowing the question was bugging me. :D

There are always several ways to do something in Perl (using grep instead of the smart matching operator, for example).

Something similar to the example provided would be less error prone, especially if you ever intend to change the items that are required.


All times are GMT -4. The time now is 05:49 PM.

Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.