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:
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. |
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)); |
Alright, so instead of using:
Code:
Code:
Code:
Thanks for answering, Kingmen |
You also don't need the extra comma:
"no" => "Okay, I will eat it!", |
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 |
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 |
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.
|
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"); Usage Example: Code:
sub EVENT_SAY { |
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 |
All times are GMT -4. The time now is 10:40 AM. |
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.