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 11-06-2011, 09:14 PM
Kingmen30264
Hill Giant
 
Join Date: Sep 2006
Posts: 112
Default Quest Using Hashes (%)

It's been awhile since I bugged anyone here on the forums about anything... and I got a question about a few quest(s) that I am composing.

First I am going to start off by saying this, "I finally got myself a Perl Book, and I have been slowing learning about Perl and its' entities."

As stated above, I am slowly learning Perl (What with College, a kid, and a family hehe), and here is something that I have come up with.

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!",
                  )

print %dadscookies($text);

}
I have tried it several forms of this, but I just cannot seem to grasp how it should be laid out.

If someone could please help me with this, then that would be awesome.

What I am trying to do is this:

Eliminate the IF/elsif/elseif command, and from what I have read, this is VERY possible thanks to "Hashes".

Once again, as always, sorry for the noob question, but I am trying learn this without asking too many people for help.

Thanks to all that respond.

Kingmen.
Reply With Quote
  #2  
Old 11-06-2011, 09:37 PM
joligario's Avatar
joligario
Developer
 
Join Date: Mar 2003
Posts: 1,498
Default

Don't have my system up to test, but a few things.

Not sure if it will break the script, but you don't need the last comma.
Instead of print, you should use quest::say(%dadscookies($text));
Reply With Quote
  #3  
Old 11-06-2011, 10:02 PM
Kingmen30264
Hill Giant
 
Join Date: Sep 2006
Posts: 112
Default

Alright, so instead of using:

Code:
print %dadscookies($text);
I should do something like:

Code:
quest::say(%dadscookies($text));
Here is what my NEW code looks like, and it is still not working.

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!",
                  )

quest::say(%dadscookies($text));

}
Once I get ONE of these %hashes working, making my other quest(s) this way should be a breeze

Thanks for answering,
Kingmen
Reply With Quote
  #4  
Old 11-06-2011, 10:46 PM
joligario's Avatar
joligario
Developer
 
Join Date: Mar 2003
Posts: 1,498
Default

You also don't need the extra comma:

"no" => "Okay, I will eat it!",
Reply With Quote
  #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
  #6  
Old 11-07-2011, 12:40 AM
Kingmen30264
Hill Giant
 
Join Date: Sep 2006
Posts: 112
Default

Thank you very much for helping me with this. This is EXACTLY what I wanted.... But I had one question....

Is it possible to run this without the use of IF commands?

Thanks for all the help,
Kingmen
Reply With Quote
  #7  
Old 11-07-2011, 05:56 AM
lerxst2112
Demi-God
 
Join Date: Aug 2010
Posts: 1,742
Default

I am not sure what you are asking when you say you don't want to use if commands. The only if in that script is to handle the case where the user says something to the npc that it doesn't understand. If you don't care about that and you want the npc to say " whenever that happens then go ahead and remove the if although that makes no sense to me.
Reply With Quote
  #8  
Old 11-07-2011, 06:20 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

I am not exactly sure what you are wanting to do, but maybe a plugin can help simplify things a bit for you. I haven't tested this at all, but it may work for what you are wanting. Just add following plugin to one of your plugin files in your plugins folder.

Code:
#Usage: plugin::EventSay("ExpectedText", "Response");
# Example: plugin::EventSay("Hail", "It Worked!");

sub EventSay {
	my $text = plugin::val('$text');
	my $CheckText = $_[0];
	my $Response = $_[1];
	
	if ($text =~ /$CheckText/i)
	{
		quest::say("$Response");
	}

}
Then, you should be able to test it using this:

Usage Example:
Code:
sub EVENT_SAY {

	my $cookie = quest::saylink("Cookie");
	my $cookieid = quest::varlink("19732");

	plugin::EventSay("Hail", "Would you like a [$cookie]?");
	plugin::EventSay("cookie", "Yes, a Cookie! Here is what it looks like [$cookieid]");
	plugin::EventSay("no", "Okay, I will eat it!");

}
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #9  
Old 11-07-2011, 07:39 AM
Kingmen30264
Hill Giant
 
Join Date: Sep 2006
Posts: 112
Default

Ah, okay. I see what is going on now. I am still in the middle of reading my Perl Book, but I think once I finish it, I will understand this a tad better eheh..



Thanks for the posts everyone... sorry for the ignorance,
Kingmen
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 07:59 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 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3