View Single Post
  #5  
Old 11-06-2011, 11:46 PM
lerxst2112
Demi-God
 
Join Date: Aug 2010
Posts: 1,742
Default

This is a way to do what you want. I added some error handling, so the npc will ignore anything said to it that isn't in the hash.

You had a few errors. A missing ; at the end of the hash statement, using () instead of {} to extract data from the hash, and some case issues.

As you go forward with this it might help to have the npc echo back the text you're sending it, by adding a quest::say($text); at the top. This would help you to see why it wouldn't have worked the way you were doing it. Specifically, hailing sends more than "Hail", which is what the split is for, and your saylink sends "Cookie" but the hash uses "cookie" as a key, which is what the lc() is for. It will also let someone say "No", "no", "nO", etc to the npc and still get the proper result.

Code:
sub EVENT_SAY
{
	my $cookie = quest::saylink("Cookie");
	my $cookieid = quest::varlink("19732");

	my %dadscookies = ("hail" => "Would you like a [$cookie]?",
			  "cookie" => "Yes, a Cookie! Here is what it looks like [$cookieid]",
			  "no" => "Okay, I will eat it!"
			  );
			  
	my @txt = split(",",lc($text));
	if(exists($dadscookies{$txt[0]}))
	{
		quest::say($dadscookies{$txt[0]});
	}
}

Last edited by lerxst2112; 11-06-2011 at 11:53 PM.. Reason: Added error handling.
Reply With Quote