Skip to content

Instantly share code, notes, and snippets.

@cydh
Last active October 9, 2019 14:59
Show Gist options
  • Save cydh/df6d1c9bb4e34a754071d97c9f1b3ab7 to your computer and use it in GitHub Desktop.
Save cydh/df6d1c9bb4e34a754071d97c9f1b3ab7 to your computer and use it in GitHub Desktop.
special_item_obtain::src/Nerwork/Receive.pm a clean lines for https://github.com/OpenKore/openkore/pull/2932
use constant {
TYPE_BOXITEM => 0x0,
TYPE_MONSTER_ITEM => 0x1,
};
sub special_item_obtain {
my ($self, $args) = @_;
my $item_name = itemNameSimple($args->{nameID});
my $holder = bytesToString($args->{holder});
my ($source_item_id, $source_name, $msg);
stripLanguageCode(\$holder);
if ($args->{type} == TYPE_BOXITEM) {
@{$args}{qw(box_nameID)} = unpack 'c/v', $args->{etc};
my $box_item_name = itemNameSimple($args->{box_nameID});
$source_name = $box_item_name;
$source_item_id = $args->{box_nameID};
chatLog("GM", "$holder has got $item_name from $box_item_name\n") if ($config{logSystemChat});
$msg = TF("%s has got %s from %s.\n", $holder, $item_name, $box_item_name);
message $msg, 'schat';
} elsif ($args->{type} == TYPE_MONSTER_ITEM) {
@{$args}{qw(len monster_name)} = unpack 'c Z*', $args->{etc};
my $monster_name = bytesToString($args->{monster_name});
$source_name = $monster_name;
stripLanguageCode(\$monster_name);
chatLog("GM", "$holder has got $item_name from $monster_name\n") if ($config{logSystemChat});
$msg = TF("%s has got %s from %s.\n", $holder, $item_name, $monster_name);
message $msg, 'schat';
} else {
$msg = TF("%s has got %s (from Unknown type %d).\n", $holder, $item_name, $args->{type});
warning $msg, 'schat';
}
Plugins::callHook('packet_special_item_obtain', {
ObtainType => $args->{type},
ItemName => $item_name,
ItemID => $args->{nameID},
Holder => $holder,
SourceItemID => $source_item_id, # ItemID if type (0) TYPE_BOXITEM
SourceName => $source_name, # Monster if type (1) TYPE_MONSTER_ITEM
Msg => $msg,
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment