mirror of
https://github.com/EQEmu/eqemu-docs-v2.git
synced 2026-08-08 17:45:09 -04:00
69 lines
2.1 KiB
Markdown
69 lines
2.1 KiB
Markdown
# Perl Plugins
|
|
|
|
Inside the [plugins](https://github.com/ProjectEQ/projecteqquests/tree/master/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](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/mklink) 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:
|
|
```pl
|
|
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.
|
|
```pl
|
|
sub EVENT_SAY {
|
|
if ($text=~/Hail/i) {
|
|
plugin::ListCustomData();
|
|
}
|
|
}
|
|
```
|
|
|
|

|
|
|
|
Perhaps you want to use the data itself, well you can do this.
|
|
```pl
|
|
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'!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|

|