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 06-14-2019, 10:46 AM
chrsschb's Avatar
chrsschb
Dragon
 
Join Date: Nov 2008
Location: GA
Posts: 904
Default Is it possible to filter on a hash/array?

I'm trying to see if instead of building multiple hashes for different types of turnins, if I can build a single large hash and filter results based on data in that hash. I'm not super savvy with these so kinda learning as I go, any help is appreciated.

Code:
%combine_1 = (
  1 => { "item1" => 1234, "item2" => 1111, "type" => 1,  "reward" => 11111 }, # Ring
  2 => { "item1" => 1234, "item2" => 2222, "type" => 4,  "reward" => 22222 }, # Veil
  3 => { "item1" => 1234, "item2" => 3333, "type" => 3,  "reward" => 33333 }, # Earring
  4 => { "item1" => 1234, "item2" => 4444, "type" => 1,  "reward" => 44444 }, # Ring
  5 => { "item1" => 1234, "item2" => 5555, "type" => 2,  "reward" => 55555 }, # Necklace
  );
For instance in this example I have 5 combines, I want to present these to the player and filter based on the type field. So if they respond to the NPC with [$type1] cause they want to see rings the npc should only respond with type 1 combines.

Dialogue I have right now:
Code:
    foreach $id (sort keys %combine_1) {
      my $item1_link = quest::varlink($turnin_1{$id}{"item1"});
      my $item2_link = quest::varlink($turnin_1{$id}{"item2"});
      my $reward_link = quest::varlink($turnin_1{$id}{"reward"});
      my $scost = $scomm . '' . pp;
      $client->Message($whisper_color, "$item1_link + $item2_link + $scost = $reward_link");
    }
Turnin:
Code:
  foreach $id (sort keys %combine_1) {
    $item1 = $turnin_1{$item_id}{"item1"};
    $item2 = $turnin_1{$item_id}{"item2"};
    $reward = $turnin_1{$item_id}{"reward"};

    if (plugin::takeItemsCoin(0, 0, 0, $scomm, $item1 => 1, $item2 => 1)) {
      quest::summonitem($reward);
      quest::ding;
    }
  }
I'm sure I'm missing something simple with this.
__________________
Clumsy's World: Resurgence [2019-Present]
Clumsy's World 2.0 [2014-2016]
Clumsy's World [2006-2012]
Reply With Quote
  #2  
Old 06-16-2019, 04:39 PM
Almusious
Fire Beetle
 
Join Date: Sep 2012
Posts: 25
Default

I -believe- this is what you're looking for (i.e. how to access/use a key in a hash of a hash):

Code:
%combine_1 = (
  1 => { "item1" => 1234, "item2" => 1111, "type" => 1,  "reward" => 11111 }, # Ring
  2 => { "item1" => 1234, "item2" => 2222, "type" => 4,  "reward" => 22222 }, # Veil
  3 => { "item1" => 1234, "item2" => 3333, "type" => 3,  "reward" => 33333 }, # Earring
  4 => { "item1" => 1234, "item2" => 4444, "type" => 1,  "reward" => 44444 }, # Ring
  5 => { "item1" => 1234, "item2" => 5555, "type" => 2,  "reward" => 55555 }, # Necklace
  );
  
{
	foreach my $key (sort keys %combine_1)
	## could be shortened: foreach (sort keys $combine_1)
	{
		if ($combine_1{$key}->{type} == 1)
		## if above shortened: if ($combine_1{$_}->{type} == 1)
		{
			my $itemlink = quest::varlink($combine_1{$key}->{reward});
			## my $itemlink = quest::varlink($combine_1{$_}->{reward});
			$client->Message(15, $itemlink);
		}
	}
}
?
Reply With Quote
  #3  
Old 06-17-2019, 06:06 AM
NatedogEZ's Avatar
NatedogEZ
Developer
 
Join Date: Dec 2012
Posts: 515
Default

Is this what you are trying to do?

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

Filters out stuff from a big ol hash
Reply With Quote
  #4  
Old 06-17-2019, 09:57 AM
chrsschb's Avatar
chrsschb
Dragon
 
Join Date: Nov 2008
Location: GA
Posts: 904
Default

Quote:
Originally Posted by NatedogEZ View Post
Is this what you are trying to do?

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

Filters out stuff from a big ol hash
I actually looked at this before and just thought it was too complex for what I'm trying to do. I know it's doing the same thing, but I'm not even entirely sure how parts of that script work so adapting it might be tough for me. I literally only need a filter for dialogue.
__________________
Clumsy's World: Resurgence [2019-Present]
Clumsy's World 2.0 [2014-2016]
Clumsy's World [2006-2012]
Reply With Quote
  #5  
Old 06-17-2019, 11:32 AM
Almusious
Fire Beetle
 
Join Date: Sep 2012
Posts: 25
Default

Devoid of feedback on what I posted using your own hash, I'm afraid I cannot be of much more assistance.

I'm simply not clear on the "if this then do that" function you're looking for.

That said, I'm thinking (based on what I've seen) that you may find a hash composition of the below more aligned with your assumed goals:

Code:
%combines = (
	"Rings" => 
	[
        {
			rewarditem => 7171,
			itemrequired1 => 1111,
			itemrequired2 => 2222,
			itemrequired3 => 3333,
			itemrequired4 => 4444,
			moneyrequiredplatinum => 2,
			moneyrequiredgold => 0,
            moneyrequiredsilver => 0,
            moneyrequiredcopper => 0
        },
        {
			rewarditem => 7171,
			itemrequired1 => 1111,
			itemrequired2 => 2222,
			itemrequired3 => 3333,
			itemrequired4 => 4444,
			moneyrequiredplatinum => 2,
			moneyrequiredgold => 0,
            moneyrequiredsilver => 0,
            moneyrequiredcopper => 0
		},
	],
    "Veils" => 
	[
        {
			rewarditem => 7171,
			itemrequired1 => 1111,
			itemrequired2 => 2222,
			itemrequired3 => 3333,
			itemrequired4 => 4444,
			moneyrequiredplatinum => 2,
			moneyrequiredgold => 0,
            moneyrequiredsilver => 0,
            moneyrequiredcopper => 0
		},
	],
    "Shoulders" => 
	[
        {
			rewarditem => 7171,
			itemrequired1 => 1111,
			itemrequired2 => 2222,
			itemrequired3 => 3333,
			itemrequired4 => 4444,
			moneyrequiredplatinum => 2,
			moneyrequiredgold => 0,
            moneyrequiredsilver => 0,
            moneyrequiredcopper => 0
		},
	],
);
Reply With Quote
  #6  
Old 06-17-2019, 11:42 AM
chrsschb's Avatar
chrsschb
Dragon
 
Join Date: Nov 2008
Location: GA
Posts: 904
Default

Quote:
Originally Posted by Almusious View Post
Devoid of feedback on what I posted using your own hash, I'm afraid I cannot be of much more assistance.
I appreciate both responses, I simply have not yet had a chance to test anything. My response to Nate is based on research I had already done in the past. I'll let you know after I get a chance to test out your recommendations.

Just to clarify, in the dialogue, similar to what Nate posted, the user can choose what "type" of jewelry they are interested in and I want to pull those out of the hash so the dialogue response isn't a mile long.
__________________
Clumsy's World: Resurgence [2019-Present]
Clumsy's World 2.0 [2014-2016]
Clumsy's World [2006-2012]
Reply With Quote
  #7  
Old 06-17-2019, 12:06 PM
Almusious
Fire Beetle
 
Join Date: Sep 2012
Posts: 25
Default

Quote:
Originally Posted by chrsschb View Post
I appreciate both responses, I simply have not yet had a chance to test anything. My response to Nate is based on research I had already done in the past. I'll let you know after I get a chance to test out your recommendations.

Just to clarify, in the dialogue, similar to what Nate posted, the user can choose what "type" of jewelry they are interested in and I want to pull those out of the hash so the dialogue response isn't a mile long.
Fair enough. How many items (total) do you suspect will be in the hash?

With the example I posted using your existing hash, so long as you utilize conditionals, it will "pull" the types requested, then display a link for the reward item.

The modified hash I posted is how I would roll myself, perhaps even making the moneyrequired and itemrequired keys hold array values (for flexibility), though it would of course require more code you're currently not comfortable with (though I suspect you will be in time).

Code:
%combines = (
	"Rings" => 
	[
        {
			rewarditem => 7171,
			itemrequired1 => 1111,
			itemrequired2 => 2222,
			itemrequired3 => 3333,
			itemrequired4 => 4444,
			moneyrequiredplatinum => 2,
			moneyrequiredgold => 0,
            moneyrequiredsilver => 0,
            moneyrequiredcopper => 0
        },
        {
			rewarditem => 7171,
			itemrequired1 => 1111,
			itemrequired2 => 2222,
			itemrequired3 => 3333,
			itemrequired4 => 4444,
			moneyrequiredplatinum => 2,
			moneyrequiredgold => 0,
            moneyrequiredsilver => 0,
            moneyrequiredcopper => 0
		},
	],
    "Veils" => 
	[
        {
			rewarditem => 7171,
			itemrequired1 => 1111,
			itemrequired2 => 2222,
			itemrequired3 => 3333,
			itemrequired4 => 4444,
			moneyrequiredplatinum => 2,
			moneyrequiredgold => 0,
            moneyrequiredsilver => 0,
            moneyrequiredcopper => 0
		},
	],
    "Shoulders" => 
	[
        {
			rewarditem => 7171,
			itemrequired1 => 1111,
			itemrequired2 => 2222,
			itemrequired3 => 3333,
			itemrequired4 => 4444,
			moneyrequiredplatinum => 2,
			moneyrequiredgold => 0,
            moneyrequiredsilver => 0,
            moneyrequiredcopper => 0
		},
	],
);

sub EVENT_SAY
{
	if ($text=~/Hail/i)
	{
		my @itemtypes_available = (sort keys %combines);
		my $itemtypes_string = "";
		my $n = 0;
		foreach (@itemtypes_available)
		{
			if ($n < $#itemtypes_available)
			{
				if ($n == ($#itemtypes_available - 1))
				{
					$itemtypes_string .= quest::saylink($_, 1, "[".$_."]");
				} else {
					$itemtypes_string .= quest::saylink($_, 1, "[".$_."]") . ", ";
				}
			} else {
				$itemtypes_string .= " and " . quest::saylink($_, 1, "[".$_."]");
			}
			$n++;
		}
		plugin::Whisper ("I have ".$itemtypes_string." to offer via quests!");
	}
}
Not the prettiest method of concatenation, but, save for using pop, last, etc. in a loop, I believe the above way of going about it is the easier way for most folks to look at it (to see what is going on).

I'm heading out of town, so I cannot see my assistance through, but, you've got Nate's ears/eyes, you'll get it all worked out I have no doubt.
Reply With Quote
  #8  
Old 06-17-2019, 12:16 PM
chrsschb's Avatar
chrsschb
Dragon
 
Join Date: Nov 2008
Location: GA
Posts: 904
Default

Quote:
Originally Posted by Almusious View Post
Fair enough. How many items (total) do you suspect will be in the hash?
At least a hundred. This method will grow, evolve and be used for other npcs with similar functionalities.
__________________
Clumsy's World: Resurgence [2019-Present]
Clumsy's World 2.0 [2014-2016]
Clumsy's World [2006-2012]
Reply With Quote
  #9  
Old 06-17-2019, 12:28 PM
Almusious
Fire Beetle
 
Join Date: Sep 2012
Posts: 25
Default

Quote:
Originally Posted by chrsschb View Post
At least a hundred. This method will grow, evolve and be used for other npcs with similar functionalities.
And will there be multiple/different methods of obtaining the same reward item? What I mean is for example:

1111 x 1,
2222 x 1,
3333 x 1,
4444 x 1,
2pp,0gp,0sp,0cp
Results in: 9999

But...

1111 x 1,
2222 x 1,
5555 x 1
20pp,0gp,0sp,0cp
Also results in: 9999

If not, then having arrays as the itemrequired and moneyrequired values wouldn't be necessary (which is where I imagined you going). Also with that, then you could just roll with a formatted array like in Nate's script. Im out, I look forward to revisiting this when I get back, have a good one.
Reply With Quote
  #10  
Old 06-17-2019, 12:31 PM
chrsschb's Avatar
chrsschb
Dragon
 
Join Date: Nov 2008
Location: GA
Posts: 904
Default

Nah, each recipe and reward is unique. Some may share components, but no two are the same.
__________________
Clumsy's World: Resurgence [2019-Present]
Clumsy's World 2.0 [2014-2016]
Clumsy's World [2006-2012]
Reply With Quote
  #11  
Old 06-17-2019, 10:34 PM
chrsschb's Avatar
chrsschb
Dragon
 
Join Date: Nov 2008
Location: GA
Posts: 904
Default

Quote:
Originally Posted by Almusious View Post
I -believe- this is what you're looking for (i.e. how to access/use a key in a hash of a hash):

Code:
%combine_1 = (
  1 => { "item1" => 1234, "item2" => 1111, "type" => 1,  "reward" => 11111 }, # Ring
  2 => { "item1" => 1234, "item2" => 2222, "type" => 4,  "reward" => 22222 }, # Veil
  3 => { "item1" => 1234, "item2" => 3333, "type" => 3,  "reward" => 33333 }, # Earring
  4 => { "item1" => 1234, "item2" => 4444, "type" => 1,  "reward" => 44444 }, # Ring
  5 => { "item1" => 1234, "item2" => 5555, "type" => 2,  "reward" => 55555 }, # Necklace
  );
  
{
	foreach my $key (sort keys %combine_1)
	## could be shortened: foreach (sort keys $combine_1)
	{
		if ($combine_1{$key}->{type} == 1)
		## if above shortened: if ($combine_1{$_}->{type} == 1)
		{
			my $itemlink = quest::varlink($combine_1{$key}->{reward});
			## my $itemlink = quest::varlink($combine_1{$_}->{reward});
			$client->Message(15, $itemlink);
		}
	}
}
?
^ this method is working great for what I'm trying to do. This should get my dialog responses down to 6-10 depending on the category, which is much better and I can filter further if needed.
__________________
Clumsy's World: Resurgence [2019-Present]
Clumsy's World 2.0 [2014-2016]
Clumsy's World [2006-2012]
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:41 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