eqemu-docs/docs/server/scripting/perl-plugins.md

70 lines
2.1 KiB
Markdown
Raw Permalink Normal View History

2022-11-11 20:26:47 -05:00
# Perl Plugins
2022-11-11 20:30:25 -05:00
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.
2022-11-11 20:26:47 -05:00
2022-11-11 20:30:25 -05:00
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.
2022-11-11 20:26:47 -05:00
2022-11-11 20:55:23 -05:00
To reload plugins for your zone you can use `#reload quest`, to reload plugins globally you'll need to use `#reload world`.
2022-11-11 20:26:47 -05:00
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();
}
}
```
![image](https://user-images.githubusercontent.com/89047260/201449965-c38e95fd-e1e4-49dd-ab48-e4434af3a8d1.png)
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) {
2022-11-11 20:38:52 -05:00
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'!");
}
}
}
}
}
```
2022-11-11 20:38:52 -05:00
![image](https://user-images.githubusercontent.com/89047260/201450584-6ab81709-5e7e-4d46-bc9f-2f38fe13527d.png)