PDA

View Full Version : Clarification on Perl loop


Asylum
07-09-2015, 05:23 PM
sub EVENT_ITEM {
if (plugin::check_handin(\%itemcount,8161=>1)) {
quest::say("You have won! Take this as a reward. Defeat the Skeletal Lord within an hour for one of five random item rewards.");
quest::summonitem(7967); #2h reward
}
if (plugin::check_handin(\%itemcount,8162=>3)) {
quest::say("You have defeated the Skeletal Lord! Take this as a reward. Defeat the Skeletal Lord within half an hour for a powerful permanent version of the Soul-Caged Rapier.");
for (1..2) {
my $reward = quest::ChooseRandom(68752,68754,68756,68758,68768) ; #1h reward list
redo if (plugin::check_hasitem($client, $reward)); #check ownership of chosen lore reward
quest::summonitem($reward);
last;
}
}
if (plugin::check_handin(\%itemcount,8163=>3)) {
quest::say("You are quite efficient at defeating the Lord of Undeath. Take this as a reward.");
quest::summonitem(8164); #30m reward
}
else {
plugin::return_items(\%itemcount);
}
}


The code works fine in checking if the client turning in the 3 gems has the randomly selected reward and chooses another... until you have all 5 and attempt the turnin, which causes everything to pause. I guess I'm using the last; command incorrectly? or is it the for (1..2) ?

Asylum
07-09-2015, 05:26 PM
I understand the logic of it making an infinite loop if you have all 5 items, but how do I use the last; command to prevent this?

Asylum
07-09-2015, 05:37 PM
sub EVENT_ITEM {
if (plugin::check_handin(\%itemcount,8161=>1)) {
quest::say("You have won! Take this as a reward. Defeat the Skeletal Lord within an hour for one of five random item rewards.");
quest::summonitem(7967); #2h reward
}
if (plugin::check_handin(\%itemcount,8162=>3)) {
if (plugin::check_hasitem($client, 68752) && plugin::check_hasitem($client, 68752) && plugin::check_hasitem($client, 68752) && plugin::check_hasitem($client, 68752) && plugin::check_hasitem($client, 68752)) { #check ownership of all 5 rewards
quest::say("You possess all 5 possible rewards for the 1-hour event.");
}
else {
quest::say("You have defeated the Skeletal Lord! Take this as a reward. Defeat the Skeletal Lord within half an hour for a powerful permanent version of the Soul-Caged Rapier.");
for (1..2) {
my $reward = quest::ChooseRandom(68752,68754,68756,68758,68768) ; #1h reward list
redo if (plugin::check_hasitem($client, $reward)); #check ownership of chosen lore reward
quest::summonitem($reward);
last;
}
}
}
if (plugin::check_handin(\%itemcount,8163=>3)) {
quest::say("You are quite efficient at defeating the Lord of Undeath. Take this as a reward.");
quest::summonitem(8164); #30m reward
}
else {
plugin::return_items(\%itemcount);
}
}


This is the solution I've come up with, putting a pre-loop check for possession of all 5 possible rewards, but perhaps someone more experienced in Perl can construct something more efficient and/or concise.

Kingly_Krab
07-09-2015, 06:05 PM
Your check is the same item 5 times: if (plugin::check_hasitem($client, 68752) && plugin::check_hasitem($client, 68752) && plugin::check_hasitem($client, 68752) && plugin::check_hasitem($client, 68752) && plugin::check_hasitem($client, 68752))

EDIT: Check your inbox for my revised version.