Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Q&A

Quests::Q&A This is the quest support section

Reply
 
Thread Tools Display Modes
  #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
  #2  
Old 10-15-2014, 05:39 PM
Asylum
Sarnak
 
Join Date: Jun 2013
Posts: 81
Default

Update: perhaps?

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, $itemlist[$a])) { #usage plugin::check_hasitemequipped($client, slotid, itemid)
					$a++;
					$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.");
				}
			}
		}
	}
}

Last edited by Asylum; 10-15-2014 at 06:13 PM.. Reason: Updated after more research
Reply With Quote
  #3  
Old 10-15-2014, 06:43 PM
Kingly_Krab
Administrator
 
Join Date: May 2013
Location: United States
Posts: 1,589
Default

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

sub EVENT_TIMER {
    if ($timer eq "armor") {
        my @clientlist = $entity_list->GetClientList();
        my @itemlist = (0000,0000,0000,0000,0000,0000,0000,0000);
        foreach $c (@clientlist) {
            if (plugin::check_hasitemequipped($c, @itemlist)) {
                $c->Message(315, "Your armor protects you from harm.");
            }
            else {
                $c->CastSpell(7026, $c->GetID());
                quest::ze(4, $c->GetCleanName() . " suffers in the throes of anguish.");
            }
        }
    }
}
Try this for the plugin:
Code:
sub check_hasitemequipped {
    my $client = shift;
    my @itemlist = shift;
    foreach $item (@itemlist) {
        for ($i = 0; $i <= 22; $i++) {
            if ($i == 22) {
                $i == 9999;
            }
            if ($client->GetItemIDAt($i) == $item) {
                return 1;
            }
        }
    }
    return 0;
}
EDIT: Slot information can be found here.
Reply With Quote
  #4  
Old 10-15-2014, 06:51 PM
Asylum
Sarnak
 
Join Date: Jun 2013
Posts: 81
Default

I see you've avoided the nested loops by shifting one iteration to the plugin; good idea. Now to tweak allowing bracers in either left or right slots (9 or 10).

I would want to limit the checked slots to visible slots (2,7,9,10,12,17,18,19), so the 1->22 $i++ iteration would need changing.

Thanks Kingly_Krab

p.s. This can also be utilized to accomplish the "remove weapon or armor" emotes and checks during MPG trials.
Reply With Quote
  #5  
Old 10-15-2014, 07:01 PM
Kingly_Krab
Administrator
 
Join Date: May 2013
Location: United States
Posts: 1,589
Default

Okay, I'd like to see how you're going to use this. Unless you're just using it for the MPG trials.
Reply With Quote
  #6  
Old 10-15-2014, 07:52 PM
Asylum
Sarnak
 
Join Date: Jun 2013
Posts: 81
Default

No, the MPG trials were an afterthought use. I plan on utilizing this check to implement a way to force usage of "resist gear" beyond the simple type resist checks. I.e., if you equip (not just own) 3 of 8 pieces of this gear, you only get hit with 5 of the 8 iterations of a DD, for example; whereas if you have the entire set on (lore to be added) the DD does not harm you.

I'll post the event when completed. Thanks again.
Reply With Quote
  #7  
Old 10-15-2014, 08:54 PM
Asylum
Sarnak
 
Join Date: Jun 2013
Posts: 81
Default

Results of testing:

Trying your suggested code for npc and plugin, the code merely checks for the proper item on the client's head (the lowest value slot in which an item can appear from the @itemlist). If that passes, returns a 1 and check ends. If that fails, returns a 0 and check ends. I.e., the for loop 1-22 is not executing past a true

Code:
if ($client->GetItemIDAt($i) == $item) {
    return 1;
}
as none of the other sent items in @itemlist are numerically correct to correspond with $i, returning a 0.

My quest continues...
Reply With Quote
  #8  
Old 10-15-2014, 09:39 PM
Uleat's Avatar
Uleat
Developer
 
Join Date: Apr 2012
Location: North Carolina
Posts: 2,815
Default

I'm probably missing something...

Code:
my @itemlist = (0000,0000,0000,0000,0000,0000,0000,0000);

Wouldn't any item found in any checked slot return 0?

Quote:
0000 (as @item) != {>0 .. <= ceiling} (as $client->GetItemIDAt($i))
__________________
Uleat of Bertoxxulous

Compilin' Dirty
Reply With Quote
  #9  
Old 10-15-2014, 09:44 PM
Asylum
Sarnak
 
Join Date: Jun 2013
Posts: 81
Default

Yes, the actual numbers for the items are not 0000, those were just placeholders when I began thinking of this script at work today. I have decided to axe the plugin and do it manually and it works perfectly, only I still have the explicit right versus left wrists to tackle. Finally, I need to get it working as a loop to have the ill effects count the number of correct/missing items of the 8.

This works as intended for checking all 8 visible armor items:

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

sub EVENT_TIMER {
	if ($timer eq "armor") {
		my @clientlist = $entity_list->GetClientList();
		foreach $ent (@clientlist) {
			if ($ent->GetItemIDAt(2) == 2298 && $ent->GetItemIDAt(7) == 2372 && $ent->GetItemIDAt(9) == 2376 && $ent->GetItemIDAt(10) == 31891 && $ent->GetItemIDAt(12) == 2377 && $ent->GetItemIDAt(17) == 2370 && $ent->GetItemIDAt(18) == 2378 && $ent->GetItemIDAt(19) == 2379) {
				$ent->Message(315, "Your armor protects you from harm.");
			}
			else {
				$ent->CastSpell(7026,$ent->GetID()); #casts Aura of Crimson Mists IV
				quest::ze(4, $ent->GetCleanName() . " suffers in the throes of anguish.");
			}
		}
	}
}
Hint: the item numbers are unique to my server, who knows what they are on other servers.
Reply With Quote
  #10  
Old 10-15-2014, 10:14 PM
Kingly_Krab
Administrator
 
Join Date: May 2013
Location: United States
Posts: 1,589
Default

If you HAVE you do your if statement that way, try this. (Spacing should not look like this, this is just for looks.)

Code:
if ($ent->GetItemIDAt(2) == 2298
&& $ent->GetItemIDAt(7) == 2372
&& (($ent->GetItemIDAt(9) == 2376 && $ent->GetItemIDAt(10) == 31891)
|| ($ent->GetItemIDAt(9) == 2376 && $ent->GetItemIDAt(10) == 2376)
|| ($ent->GetItemIDAt(9) == 31891 && $ent->GetItemIDAt(10) == 2376)
|| ($ent->GetItemIDAt(9) == 31891 && $ent->GetItemIDAt(10) == 31891))
&& $ent->GetItemIDAt(12) == 2377
&& $ent->GetItemIDAt(17) == 2370
&& $ent->GetItemIDAt(18) == 2378
&& $ent->GetItemIDAt(19) == 2379)
Reply With Quote
  #11  
Old 10-16-2014, 01:28 PM
Asylum
Sarnak
 
Join Date: Jun 2013
Posts: 81
Default

Next question: is there a function or call that accomplishes the following, or can one of you experts create one to look into an item's file and find the assigned weapon type by value? I imagine it would mirror the function of
quest::isdisctome(item_id) # Checks if 'item_id' is a discipline tome.

Code:
#usage quest::isweapon_type($itemid, type) where you choose the value for slash, blunt, et cetera

$itemid = $client->GetItemIDAt(13); #Gets itemid in primary
if (quest::isweapon_type($itemid, type)) { # Checks if $itemid is a type weapon
    effect;
}
else {
    other effect;
}
Reply With Quote
Reply


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 04:04 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 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3