View Single Post
  #1  
Old 10-15-2014, 05:28 PM
Asylum
Sarnak
 
Join Date: Jun 2013
Posts: 81
Default Nested coupled foreach loops

I have searched the forums, though not exhaustively, for help on this topic but this was the only thread close to what I want to accomplish:

http://www.eqemulator.org/forums/showthread.php?t=31777

I am trying to create nested foreach loops where the inner loop simultaneously reads two @lists containing 8 items each. Here's what I have so far, and can't figure out how to reference the $item (@itemlist). Any help would be appreciated. Thanks.

Code:
sub EVENT_SPAWN {
	$npc->TempName("");
	quest::settimer("armor", 30);
}

sub EVENT_TIMER {
	if ($timer eq "armor") {
		my @clientlist = $entity_list->GetClientList();
		my @slotlist = (2,7,9,10,12,17,18,19);
		my @itemlist = (0000,0000,0000,0000,0000,0000,0000,0000);
		foreach $ent (@clientlist) {
			foreach $slot (@slotlist) {
				if (plugin::check_hasitemequipped($ent, $slot, $item)) { #usage plugin::check_hasitemequipped($client, slotid, itemid)
					$ent->Message(315, "Your armor protects you from harm.");
				}
				else {
					my $eid = $ent->GetID(); #Get this client's Entity_ID
					$ent->CastSpell(7026,$eid); #casts Aura of Crimson Mists IV
					my $h_ent_name = $ent->GetCleanName();
					quest::ze(4, "$h_ent_name suffers in the throes of anguish.");
				}
			}
		}
	}
}
the plugin I created is as follows:

Code:
#checks to see if player has item equipped
#usage plugin::check_hasitemequipped($client, slotid, itemid); #just input numbers for slotid and itemid

#Item slotid #'s
#1 LEar
#2 Head - visible
#3 Face
#4 REar
#5 Neck
#6 Shoulder
#7 Arms - visible
#8 Back
#9 LWrist - visible
#10 RWrist - visible
#11 Range
#12 Hands - visible
#13 Primary Slot - visible
#14 Secondary Slot - visible
#15 LFinger
#16 RFinger
#17 Chest - visible
#18 Legs - visible
#19 Feet - visible
#20 Belt
#21 Ammo

sub check_hasitemequipped { #Check for item $itmchk in slot $slotid
    my $client = shift;
	my $slotid = shift;
    my $itmchk = shift;
    my $itemid = $client->GetItemIDAt($slotid);
    if($itemid1==$itmchk) {
        return 1;
    }
  return 0;
}

1;
Reply With Quote