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 09-30-2018, 09:34 PM
superpally1
Sarnak
 
Join Date: Jul 2018
Location: Tennessee
Posts: 33
Default Trying to understand.

I can not figure out why this first script works as it should, and the second one does not.

Code:
sub EVENT_SAY {

    if ($text=~/armorset/i) {
	# head armor ids   147587 = leather, 147580 = plate, 147573 = chain, 147566 = cloth
        # chest armor ids  147588 = leather, 147581 = plate, 147574 = chain, 147567 = cloth
        # leg  armor ids   147591 = leather, 147584 = plate, 147577 = chain, 147570 = cloth
	
	my $headid = $client->GetItemIDAt(2);
        my $chestid = $client->GetItemIDAt(17);
        my $legid = $client->GetItemIDAt(18);
	
        if($headid == 147587 && $chestid == 147588 && $legid == 147591){ #leather
	    $client->Message(15,"3 pieces of armor equipped, $headid, $chestid, $legid.");
	}
	elsif($headid == 147587 && $legid == 147591){ #leather
            $client->Message(15,"2 pieces of armor equipped, $headid, $legid.");
	}
	if($headid == 147580 && $chestid == 147581 && $legid == 147584){ #plate
            $client->Message(15,"3 pieces of armor equipped, $headid, $chestid, $legid.");
	}
	elsif($headid == 147580 && $legid == 147584){ #plate
            $client->Message(15,"2 pieces of armor equipped, $headid, $legid.");
	}
	if($headid == 147573 && $chestid == 147574 && $legid == 147577){ #chain
            $client->Message(15,"3 pieces of armor equipped, $headid, $chestid, $legid.");
	}
	elsif($headid == 147573 && $legid == 147577){ #chain
            $client->Message(15,"2 pieces of armor equipped, $headid, $legid.");
	}
	if($headid == 147566 && $chestid == 147567 && $legid == 147570){ #cloth
            $client->Message(15,"3 pieces of armor equipped, $headid, $chestid, $legid.");
	}
	elsif($headid == 147566 && $legid == 147570){ #cloth
            $client->Message(15,"2 pieces of armor equipped, $headid, $legid.");
	}
    }
}


Code:
sub EVENT_SAY {
	if ($text=~/armorset/i) {
	# head armor ids   147587 = leather, 147580 = plate, 147573 = chain, 147566 = cloth
        # chest armor ids  147588 = leather, 147581 = plate, 147574 = chain, 147567 = cloth
        # leg  armor ids   147591 = leather, 147584 = plate, 147577 = chain, 147570 = cloth
	
	my $headid = $client->GetItemIDAt(2);
        my $chestid = $client->GetItemIDAt(17);
        my $legid = $client->GetItemIDAt(18);
	
        if ($headid == 147587||147580||147573||147566 && $chestid == 147588||147581||147574||147567 && $legid == 147591||147584||147577||147570){
            $client->Message(15,"3 pieces of armor equipped, $headid, $chestid, $legid.");
	}
	elsif ($headid == 147587||147580||147573||147566 && $legid == 147591||147584||147577||147570){
            $client->Message(15,"2 pieces of armor equipped, $headid, $legid.");
	}
    }
}
The second script will always output the 3 piece message regardless if you have all 3 pieces of gear on, 2 pieces, 1 piece, or no pieces.
If the item is not equipped the client->Message will just list -1 for the itemid for that slot.

The elsif statement is never reached.

Any help would be greatly appreciated.
Reply With Quote
  #2  
Old 10-01-2018, 12:07 AM
Almusious
Fire Beetle
 
Join Date: Sep 2012
Posts: 25
Default

Code:
sub EVENT_SAY {
	if ($text=~/armorset/i) {
		# head armor ids   147587 = leather, 147580 = plate, 147573 = chain, 147566 = cloth
		# chest armor ids  147588 = leather, 147581 = plate, 147574 = chain, 147567 = cloth
		# leg  armor ids   147591 = leather, 147584 = plate, 147577 = chain, 147570 = cloth
		my $headid = $client->GetItemIDAt(2);
		my $chestid = $client->GetItemIDAt(17);
		my $legid = $client->GetItemIDAt(18);
		if ($headid ~~ [147587,147580,147573,147566] and $chestid ~~ [147588,147581,147574,147567 and $legid ~~ [147591,147584,147577,147570])
		{
			$client->Message(15,"3 pieces of armor equipped, $headid, $chestid, $legid.");
		}
		elsif ($headid ~~ [147587,147580,147573,147566] and $legid ~~ [147591,147584,147577,147570])
		{
			$client->Message(15,"2 pieces of armor equipped, $headid, $legid.");
		}
	}
}
Use smart matching against an array, much easier to do and look at. Would also consider a hash if you go with any more items fwiw.
Reply With Quote
  #3  
Old 10-01-2018, 07:34 AM
Kingly_Krab
Administrator
 
Join Date: May 2013
Location: United States
Posts: 1,595
Default

“and” is not a valid bareword in Perl. Use && instead. Also, smart-matching is better if you predefine the arrays so it's much easier to understand what the random numbers are.
Reply With Quote
  #4  
Old 10-02-2018, 02:12 AM
Almusious
Fire Beetle
 
Join Date: Sep 2012
Posts: 25
Default

Indeed, "and" is instead a valid logical operator. You had me scratchin' my head trying to figure out what you meant, but I assume perl -c barfed on it because I placed the scalar values meant to be an array within brackets rather than parentheses. Serves me right for not bouncing it against Perl.

Code:
($headid ~~ (147587,147580,147573,147566) and ...
I left the comments in so the numbers didn't appear so random. Though, they may still appear random even if:

Code:
my @headpieces = (147587,147580,147573,147566);
if ($headid ~~ @headpieces) {
As aforementioned, I would consider doing a Hash of Hashes.

Maybe something along the lines of:

Code:
%HoH = (
	'leather'	=>	{
					'head'	=>	147587,
					'chest'	=>	147588,
					'legs'	=>	147591,
				},
	'plate'		=>	{
					'head'	=>	147580,
					'chest'	=>	147581,
					'legs'	=>	147584,
				},
	'chain'		=>	{
					'head'	=>	147573,
					'chest'	=>	147547,
					'legs'	=>	147577,
				},
	'cloth'		=>	{
					'head'	=>	147566,
					'chest'	=>	147567,
					'legs'	=>	147570,
				},
);
Though the nice thing about Perl and Eqemu in general, there are so many ways one can approach a problem to reach a solution. Sure, there are "better" ways, or perhaps even correct. For instance, placing the

Code:
my %elementshash = map { $_ => 1 } @headpieces;
if(exists($elementhash{$headid})) {
I am looking forward to see what you have cooking up superpally1. Assuming it's going to be a public server.
Reply With Quote
  #5  
Old 10-02-2018, 01:45 PM
superpally1
Sarnak
 
Join Date: Jul 2018
Location: Tennessee
Posts: 33
Default

Thank you very much for the help! I understand now. I will post what im making soon as i finish it later today. And my server is always public if you want to stop by. Omen I
Reply With Quote
  #6  
Old 10-03-2018, 08:35 PM
Almusious
Fire Beetle
 
Join Date: Sep 2012
Posts: 25
Default

I wrote this late at night, pretty sure it will work out, though my comments -may- be off a little, maybe someone can correct me on any wrong points. We're all here to learn.

Code:
%HoH = (
	'leather'	=>	{
					'head'	=>	147587,
					'chest'	=>	147588,
					'legs'	=>	147591,
				},
	'plate'		=>	{
					'head'	=>	147580,
					'chest'	=>	147581,
					'legs'	=>	147584,
				},
	'chain'		=>	{
					'head'	=>	147573,
					'chest'	=>	147547,
					'legs'	=>	147577,
				},
	'cloth'		=>	{
					'head'	=>	147566,
					'chest'	=>	147567,
					'legs'	=>	147570,
				},
);

sub EVENT_SAY 
{
	if ($text=~/hasharmorset/i)
	{
		# doing the following assuming the player is wearing a plate head (ID 147580)
		foreach $firstlevelkey (keys %HoH) 
		{ 	
		# iterate the parent keys of hash %HoH one by one and put the current key being read into $parentkey
		# we will assume 'plate' was read first
			$childhashref = $HoH{$firstlevelkey};	
			# make reference of first level hash based on current parent key (i.e. $parentkey)
			# $childhashref now equals $HoH{plate}
			foreach $secondlevelkey (keys %$childhashref) 
			{	
			# iterate the second level (child) keys of the dereferenced hash and put that key into $secondlevelkey
			# could also be written %{$childhashref} - lets assume it pulls out the key 'head' from $HoH{plate}
				if ($client->GetItemIDAt(2) == $HoH{$firstlevelkey}->{$secondlevelkey})
				{ 
				# $HoH{plate}->{head} is equal to its key value which is 147580 - a match, we know they have plate this iteration
				quest::say("You are wearing a ".$firstlevelkey." ".$secondlevelkey." found within my Hash of Hashes");
				}
			}
		}
	}
}
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 05:40 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