View Single Post
  #2  
Old 08-15-2018, 05:45 PM
Randymarsh9
Dragon
 
Join Date: Dec 2007
Posts: 658
Default

Welcome to the forums!

First of all, when posting code on here, try to wrap it in [code] blocks. That will make it much easier to read.

Now, onto your code itself. The sub EVENT_SAY is going to trigger once for each time you say something to the NPC. This means that your nested if statements are not going to work as you may be expecting.

For instance,
Code:
if ($text =~/Scale Level/i)
{
     $client->Message(4, "What Level?");
     if($text!~/Hail|Scale Level|ScaleLevel|WhatLevel|What Level/i)
     {
           plugin::ScaleLevel($text);
     }
}
Here, assuming the player chose to scale level, $text is going to be equal to "Scale Level." Once the $client->message line executes, it's immediately going to proceed to the next if statement. Since "Scale Level" will fail your regex check, the plugin::ScaleLevel will not run. The EVENT_SAY sub will then end.

You will need to restructure your code to account for the fact that you will never have different values for $text in the same execution of sub EVENT_SAY.

Also, for efficiency, you should use elsif's so that not every option is checked every time the NPC is spoken too. Right now, if someone hails your NPC, it will run the hail code, and then check every other prompt you have listed as well. It won't cause problems, but it does make the script slower.
Reply With Quote