EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Q&A (https://www.eqemulator.org/forums/forumdisplay.php?f=599)
-   -   A better way to write this?? (https://www.eqemulator.org/forums/showthread.php?t=39961)

chasem 08-27-2015 08:23 PM

A better way to write this??
 
I'm new to PERL and writing quests. Learned a ton just through everyones helpful posts here.

I'm wondering if there is a simpler way to write the following. It is for an NPC that will just be dealing with melee classes. It works, just guessing there is probably an easier way...

Code:

if($class eq 'Druid') { plugin::Whisper("Begone! I will not help a $class!"); return; } #No Druids return...
        if($class eq 'Magician') { plugin::Whisper("Begone! I will not help a $class!"); return; } #No Mages return...
        if($class eq 'Wizard') { plugin::Whisper("Begone! I will not help a $class!"); return; } #No Wizards return...
        if($class eq 'Necromancer') { plugin::Whisper("Begone! I will not help a $class!"); return; } #No Necros return...
        if($class eq 'Shaman') { plugin::Whisper("Begone! I will not help a $class!"); return; } #No Shaman return...
        if($class eq 'Cleric') { plugin::Whisper("Begone! I will not help a $class!"); return; } #No Cleric return...
        if($class eq 'Enchanter') { plugin::Whisper("Begone! I will not help a $class!"); return; } #No Enchanter return...

Thanks for any tips you can give.

Kingly_Krab 08-27-2015 08:31 PM

Try this:
Code:

if($class=~/Druid|Magician|Wizard|Necromancer|Shaman|Cleric|Enchanter/i) {
    plugin::Whisper("Begone! I will not help a $class!");
    return;
}


chasem 08-27-2015 08:38 PM

Awesome!! Thanks Kingly. Haven't come across the vertical bars used before.

Shendare 08-27-2015 08:48 PM

The world is upside-down when a regular expression is actually the simplest way to do something. Hahaha!

Kingly_Krab 08-27-2015 08:49 PM

The | is just an OR operator within REGEX.


All times are GMT -4. The time now is 01:43 PM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.