原創網址為http://forums.openkore.com/viewtopic.php?f=34&t=1490&p=6637
有興趣的人可以自己研究~以下均為自己研究後稍微修改而成
這個插件功用是當你斷線電腦會唱歌叫你起床.裡面還有許多警告功能例如:碰到BOSS斷線
1.以下是plugins插件把下面這些程式碼存成alertsound.pl放進plugins資料夾
# alertsound plugin by joseph
# Fixed to 1.9.x version by h4rry84
# http://openkore.sourceforge.net/forum/viewtopic.php?t=2032
#
#
# This software is open source, licensed under the GNU General Public
# License, version 2.
package alertsound;
use strict;
use Plugins;
use Globals;
use Utils;
use Log qw(message);
use Network::Send;
use Utils::Win32;
Plugins::register('alertsound', 'plays sounds on certain events', \&Unload);
my $packetHook = Plugins::addHook('parseMsg/pre', \&CheckPacket);
sub Unload {
Plugins::delHook('parseMsg/pre', $packetHook);
}
sub CheckPacket {
return if (!$config{'alertSound'});
my $hookName = shift;
my $args = shift;
my $switch = $args->{switch};
my $msg = $args->{msg};
if ($switch eq "008D") {
# Public chat message.
my $ID = substr($msg, 4, 4);
my $msg_size = length($msg);
my $chat = substr($msg, 8, $msg_size - 8);
$chat =~ s/\000//g;
my ($chatMsgUser, $chatMsg) = $chat =~ /([\s\S]*?) : ([\s\S]*)/;
$chatMsgUser =~ s/ $//;
if ($chatMsgUser =~ /^([a-z]?ro)?-?(Sub)?-?\[?GM\]?/i) {
alertSound("public GM chat");
} else {
alertSound("public chat");
}
} elsif ($switch eq "0097") {
# Private chat message.
my $msg_size = length($msg);
my $newmsg;
Network::Receive->decrypt(\$newmsg, substr($msg, 28, length($msg)-28));
$msg = substr($msg, 0, 28).$newmsg;
my ($privMsgUser) = substr($msg, 4, 24) =~ /([\s\S]*?)\000/;
my $privMsg = substr($msg, 28, $msg_size - 29);
if ($privMsgUser =~ /^([a-z]?ro)?-?(Sub)?-?\[?GM\]?/i) {
alertSound("private GM chat");
} else {
alertSound("private chat");
}
} elsif ($switch eq "009A") {
# System message/GM message (is this always global?)
alertSound("system message");
} elsif ($switch eq "00C0") {
# Emoticon
my $ID = substr($msg, 2, 4);
if ($players{$ID} && $ID ne $accountID) {
alertSound("emoticon");
}
} elsif ($switch eq "0091") {
# Map change
alertSound("map change");
} elsif ($switch eq "0092") {
# Map change - switching map servers
alertSound("map change");
} elsif ($switch eq "0095") {
# Identify GM Names
my $ID = substr($msg, 2, 4);
if ($players{$ID} && %{$players{$ID}}) {
my ($name) = substr($msg, 6, 24) =~ /([\s\S]*?)\000/;
if ($name =~ /^([a-z]?ro)?-?(Sub)?-?\[?GM\]?/i) {
alertSound("GM near");
}
}
} elsif ($switch eq "0195") {
#Identify GM Names
my $ID = substr($msg, 2, 4);
if ($players{$ID}) {
my ($name) = substr($msg, 6, 24) =~ /([\s\S]*?)\000/;
if ($name =~ /^([a-z]?ro)?-?(Sub)?-?\[?GM\]?/i) {
alertSound("GM near");
}
}
} elsif ($switch eq "0080") {
# someone disappeared here
my $ID = substr($msg, 2, 4);
if ($ID eq $accountID) {
# You are dead.
alertSound("death");
}
} elsif ($switch eq "0078") {
# Existance packet used to tell if monster exists
my $ID = substr($msg, 2, 4);
my $type = unpack("S*",substr($msg, 14, 2));
my $pet = unpack("C*",substr($msg, 16, 1));
if (!$jobs_lut{$type} && $type >= 1000 && !$pet) {
my $display = ($::monsters_lut{$type} ne "")
? $::monsters_lut{$type}
: "Unknown ".$type;
alertSound("monster $display");
}
} elsif ($switch eq "01D8") {
# Existance packet used to tell if monster exists
my $ID = substr($msg, 2, 4);
my $type = unpack("S*",substr($msg, 14, 2));
my $pet = unpack("C*",substr($msg, 16, 1));
if (!$jobs_lut{$type} && $type >= 1000 && !$pet) {
my $display = ($::monsters_lut{$type} ne "")
? $::monsters_lut{$type}
: "Unknown ".$type;
alertSound("monster $display");
}
}
if ($switch eq "006A") {
#123456
alertSound("disconnect");
}
}
##
# alertSound($event)
# $event: unique event name
#
# Plays a sound if alertSound is enabled,
# and if a sound is specified for the event.
#
# The config option "alertSound_#_eventList" should have a comma
# seperated list of all the desired events.
#
# Supported events:
# public chat, public GM chat, private chat, private GM chat, emoticon, system message
# map change, GM near, monster
sub alertSound {
return if (!$config{'alertSound'});
my $event = shift;
my $i = 0;
for (my $i = 0; exists $config{"alertSound_".$i."_eventList"}; $i++) {
next if (!$config{"alertSound_".$i."_eventList"});
if (Utils::existsInList($config{"alertSound_".$i."_eventList"}, $event))
{
message "Sound alert: $event\n", "alertSound";
Utils::Win32::playSound($config{"alertSound_".$i."_play"});
return;
}
}
}
return 1;
2.在config.txt檔內任一位置加入以下敘述ps.wav是播放的音樂一定要是wav才行
alertSound 1
alertSound {
eventList disconnect #這裡可以加入其他警告內容支援的大概有以下這些: monster 皮里恩, death, private GM chat, private chat, GM near, system message
play D:\RO\ps.wav
}
相關問題與答
1、斷線是打上:eventList disconnect 還是 eventList 連線中 還是 eventList disconnected
請問是要打上外掛會觸發的字嗎?
eventList 後面放的是alertsound.pl 裡面有的設定例如disconnect這個字詞是我自己新增在alertsound.pl 裡的
if ($switch eq "006A") {
alertSound("disconnect");
}
我是根據伺服器傳送的代碼來判斷而確定是否為斷線狀態~斷線的代碼為006A~代碼查詢可以從recvpackets.txt這個文件裡查詢
比較複雜的例如遇怪唱歌那就要寫一段去抓怪的名子的程式碼
因為斷線不用判斷額外的資料所以程式碼很簡單
這個相關字詞如果alertsound.pl裡沒有的那就不會起作用
p.s相關字詞大致上應該都夠用
其實觸發唱歌的方法有很多種~只是我覺得這外國人寫得很棒~
把很多常用的都附加近來才PO上來
需要的話也可以利用巨集讓他唱歌
[ 本帖最後由仙研 mike0302大大 於 2009-10-7 12:32 編輯 分享]
留言列表