View Single Post
  #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