Skip to content

Perl Plugins

Inside the plugins directory you can find example scripts on how to create reusable methods so that you don't have to copy and paste code in between files.

The plugins folder can be located in the quests folder and can be either dragged to the base folder directory or symbollically linked to be called from within the quests folder.

To reload plugins for your zone you can use #reload quest, to reload plugins globally you'll need to use #reload world.

An example plugin is this:

sub CustomData {
    my %custom_data = (
        0 => "A",
        1 => "B",
        2 => "C",
        3 => "D"
    );

    return %custom_data;
}

sub ListCustomData {
    my %custom_data = CustomData();

    foreach my $key (sort {$a <=> $b} keys %custom_data) {
        quest::message(315, "$key: $custom_data{$key}");
    }
}

You can call this custom_plugin.pl.

An example of an NPC using this would be as follows.

sub EVENT_SAY {
    if ($text=~/Hail/i) {
        plugin::ListCustomData();
    }
}

image

Perhaps you want to use the data itself, well you can do this.

sub EVENT_SAY {
    if ($text=~/Hail/i) {
        my $list_link = quest::saylink("list", 1);
        my $search_link = quest::saylink("search", 1);
        quest::whisper("Hail $name, would you like to $list_link or $search_link the custom data?");
    } elsif ($text=~/List/i) {
        plugin::ListCustomData();
    } elsif ($text=~/^Search$/i) {
        quest::whisper("Simply say \"search [value]\" to search the custom data.");
    } elsif ($text=~/^Search/i) {
        my $search_string = substr($text, 7);
        if (length($search_string) > 0) {
            my %custom_data = plugin::CustomData();
            foreach my $key (sort {$a <=> $b} keys %custom_data) {
                if (lc($search_string) eq lc($custom_data{$key})) {
                    quest::message(315, "Found '$search_string' under Key '$key'!");
                }
            }
        }
    }
}

image