從此以後不再死的不明不白!!!
自動記錄死亡前詳細訊息
讓你找到原因!!!

範例:



使用方法: (超簡單~只有兩個步驟!)

1.
在 config.txt 中加入下列設定 (位置隨便都可以,我是加在" LOG 紀錄檔 (其它)"區域)

logDeath 1
# 是否要開啟角色死亡記錄,在 logs/deathlog.txt
# Plugin 功能,若 openkore/plugins/ 裡沒有 Autopsy.pl 的話此功能無效
logDeathSize 50
# 角色死亡記錄的行數,記錄死亡前幾行的訊息
deathMessage 您已經死了


 


 


2.
將以下代碼存成 Autopsy.pl
置於 openkore 的 plugins 目錄裡面 (ex: c:\ok\plugins)


##########################################################################
# This software is open source, licensed under the GNU General Public
# License, version 2.
# Basically, this means that you're allowed to modify and distribute
# this software. However, if you distribute modified versions, you MUST
# also distribute the source code.
# See http://www.gnu.org/licenses/gpl.html for the full license.
##########################################################################


#Autopsy.pl
#Plugin by: PlayingSafe, Openkore
#Revision 3 by Rbin
#Openkore 2.0.0 (SVN) upper
#How to use
#At your config file put
#logDeath 1 <-- put 1 to enable logging
#logDeathSize # <--- put your desired number of lines to save
#deathMessage <-- put the "You have died" word on your local language if kore is set to local language
#example:
#logDeathSize 25 (this will save 25 lines of console messages)
#deathMessage You have died (Default language English)


package Autopsy;


use Utils;
use strict;
use Plugins;
use Globals;
use Settings;
use Log qw(message debug);


Plugins::register('Autopsy', 'Record console messages after bot died', \&unload);
my $cHook = Log::addHook(\&cHook, "DeathLog");


sub unload {
        Log::delHook('cHook', $cHook);
}


my @messages = ();


sub cHook {
        my $type = shift;
        my $domain = (shift or "console");
        my $level = (shift or 0);
        my $currentVerbosity = shift;
        my $message = shift;
        my $user_data = shift;
        my $logfile = shift;
        my $deathmsg = shift;
        my $location = shift;


if ($level <= $currentVerbosity && $config{'logDeath'} == 1) {


        my (undef, $microseconds) = Time::HiRes::gettimeofday;
        $microseconds = substr($microseconds, 0, 2);
        my $message2 = "[".getFormattedDate(int(time)).".$microseconds] ".$message;


        push(@messages, $message2);
        my $size = scalar @messages;
        if ($size == $config{'logDeathSize'} + 1) {
                        shift(@messages);
        }
        if ($config{logAppendUsername}) {
                $logfile = "$Settings::logs_folder/deathlog_$config{username}_$config{char}.txt";
        } else {
                $logfile = "$Settings::logs_folder/deathlog.txt";
        }
        $deathmsg = $config{'deathMessage'};
        if ($message =~ /$deathmsg/) {
                my $pos = calcPosition($char);
                $location = "\nYou died at " . $field->descName . " (" . $field->name . ") : $pos->{x}, $pos->{y}\n";
                                use encoding 'utf8';
                                open(DFILE, ">>:utf8", "$logfile"); {
                                print DFILE "\n*** Start of console death log ***\n\n";
                                print DFILE @messages;
                                print DFILE $location;
                                print DFILE "\n*** End of console death log ***\n\n";
                                close(DFILE);
                        }
                }
        }
}
return 1;


 


 


 


以上轉至htht大大的分享!!


 


 


 


----------------------------------------------------------------------------------------------


本帖最後由 sofax222 於 2013-4-9 21:30 編輯


之後的這個功能SOFAX222大大會實作到主程式中了,
而不以插件為之 !!

請注意: 以下修改涉及主程式修改,
稍有不慎恐會造成 Openkore 無法執行,若無把握請勿嘗試,
建議修改前先備份該相關檔案,以備不時之需


開啟 src/Log.pm 程式檔
修改(1)
先找到「use Modules 'register';」字串,
原紿程式碼:


use Modules 'register';
 
use Globals qw(%config $interface %consoleColors $field);
 
use Utils::DataStructures qw(binAdd existsInList);
 
use Utils qw(binAdd existsInList getFormattedDate);


修改後程式碼:


use Modules 'register';
 
use Globals qw(%config $interface %consoleColors $field %cities_lut %maps_lut $char);
 
use Field;
 
use Utils::DataStructures qw(binAdd existsInList);
 
use Utils qw(binAdd existsInList getFormattedDate calcPosition);


也就是
1. 在第 02 行最後面「);」之前插入「 %cities_lut %maps_lut $char」。
2. 新增插入第 03 行
3. 在第 05 行最後面「);」之前插入「 calcPosition」。



修改(2)
先找到「our $warningVerbosity」字串,
原紿程式碼:


our $warningVerbosity;
 
our $errorVerbosity;


修改後程式碼:


our $warningVerbosity;
 
our $errorVerbosity;
 
our @messages=();


也就是新增插入第 03 行



修改(3)
先找到「# Print to files」字串,
原紿程式碼:


                }
 
        }
 


        # Print to files


修改後程式碼:


                }
 


                if($config{logDeath} && $config{'deathMessage'} && $field) {
 
                        my (undef, $microseconds) = Time::HiRes::gettimeofday;
 
                        $microseconds = substr($microseconds, 0, 2);
 
                        my $message2 = "[".getFormattedDate(int(time)).".$microseconds] ".$message;
 
                        my $logfile;
 
                        push(@messages, $message2);
 
                        if ($#messages == $config{'logDeathSize'} + 1) {
 
                                shift(@messages);
 
                        }
 
                        if ($config{logAppendUsername}) {
 
                                $logfile = "$Settings::logs_folder/deathlog_$config{username}_$config{char}.txt";
 
                        } else {
 
                                $logfile = "$Settings::logs_folder/deathlog.txt";
 
                        }
 
                        my $deathmsg = $config{'deathMessage'};
 
                        if ($message =~ /$deathmsg/) {
 
                                my $pos = calcPosition($char);
 
                                my $location = "You died at $maps_lut{$field->baseName.'.rsw'} (".$field->baseName.") : $pos->{x}, $pos->{y}\n";
 
                                use encoding 'utf8';
 
                                open(DFILE, ">>:utf8", "$logfile");
 
                                print DFILE "*** Start of console death log ***\n";
 
                                print DFILE @messages;
 
                                print DFILE $location;
 
                                print DFILE "*** End of console death log ***\n\n";
 
                                close(DFILE);
 
                        }
 
                }
 
        }
 


        # Print to files


也就是新增插入第 02~29 行



然後在 config.txt 檔案中加入以下三個設定參數:
logDeath 1
# 是否開啟死亡記錄功能,1:開啟,0:關閉
logDeathSize 50
# 記錄死亡前幾行的 Console 訊息
deathMessage You have died at
# 死亡時 Console 所顯示的訊息片段

記錄會寫到 logs 資料夾中。


創作者介紹
創作者 aaa1314 的頭像
aaa1314

RO相關資料資訊♂外掛腳本討論&請勿發表其他廣告(請保持畫面清爽)感謝

aaa1314 發表在 痞客邦 留言(0) 人氣()