Config.txt add:
Code: Select all
retreatFile c:\retreat.txt 
retreatValid 1
retreatCommand #Any recognized command for openkore
retreatDesconect 0/1  #0 not DC  1 DC bot
retreatSound #Sound 
retreatSoundTime #Waiting for the sound to finishgef_fild03
Code: Select all
retreatFile c:\retreatGef_fild03.txt
retreatValid 1
retreatCommand relog 800
retreatDesconect 0
retreatSound "C:\Sons\GM.wav"Code: Select all
retreatFile c:\retreatGef_fild04.txt
retreatValid 1
retreatCommand relog 800
retreatDesconect 0
retreatSound "C:\Sons\GM.wav"Code: Select all
retreatFile c:\retreat.txtCode: Select all
# retreat by Setzer
#
#
# This source code is licensed under the
# GNU General Public License, Version 2.
# See http://www.gnu.org/licenses/gpl.html
package retreat;
use strict;
use Plugins;
use Commands;
use Globals;
use Utils;
use Misc;
use Log qw(message error warning);
use Network::Send;
Plugins::register("retreat", "warns bots to retreat after a GM action", \&unload);
my $pluginHooks  = Plugins::addHooks(
	['start3',                 \&on_Start,      undef],
	['packet_pre/map_change',  \&on_Teleport,   undef],
	['packet_pre/map_changed', \&on_Teleport,   undef],
	['packet_pre/errors',      \&on_Error,      undef],
	['packet_pre/self_chat',   \&on_SelfChat,   undef],
	['mainLoop_pre',           \&on_MainLoop,   undef]
);
my $pluginCHooks = Commands::register(
	['retreat', "retreat plugin", \&on_Command]
);
my %pluginConfig = (
	retreatPrefix => "[retreat]",
	retreatFile   => "",
);
sub on_Start {
	if( !defined($config{retreatFile}) ){
		unload();
	} else {
		$pluginConfig{retreatFile} = $config{retreatFile};
		message($pluginConfig{retreatPrefix}."retreat plugin started\n");
		message($pluginConfig{retreatPrefix}."retreat file is ".$pluginConfig{retreatFile}."\n");
	}
}
sub on_Teleport {
	my (undef, $callerArgs) = @_;
	my ($map) = $callerArgs->{map} =~ /([\s\S]*)\./;
	# same conditions as in Misc::checkAllowedMap
	return unless $AI == 2;
	return unless $config{allowedMaps};
	return if existsInList($config{allowedMaps}, $map);
	return if $config{allowedMaps_reaction} == 0;
	warning($pluginConfig{retreatPrefix}."teleported to not allowed map, sending retreat order\n");
	sendRetreatOrder("reason: teleported (".$chars[$config{slot}]{name}." teleported to ".$map.")");
}
sub on_Error {
	my (undef, $callerArgs) = @_;
	return if $callerArgs->{type} != 15;
	warning($pluginConfig{retreatPrefix}."disconnected by GM, sending retreat order\n");
	sendRetreatOrder("reason: kicked (".$chars[$config{slot}]{name}." disconnected by GM)");
}
sub on_SelfChat {
	my (undef, $callerArgs) = @_;
	if( ($callerArgs->{message} =~ /banish/) ||
        ($callerArgs->{message} =~ /banned/) ||
	    ($callerArgs->{message} =~ /punish/) ||
	    ($callerArgs->{message} =~ /banid/)  ||
	    ($callerArgs->{message} =~ /punid/)  ){
		warning($pluginConfig{retreatPrefix}."banned, sending retreat order\n");
		sendRetreatOrder("reason: banned (".$chars[$config{slot}]{name}." received message: ".$callerArgs->{message}.")");
	}
}
sub on_MainLoop {
	my (undef, $callerArgs) = @_;
	return if !(-e $pluginConfig{retreatFile});
	warning($pluginConfig{retreatPrefix}."retreat order received\n");
	Commands::run("conf logConsole 1");
	if ($config{retreatValid} == 0){
	   Log::warning "[retreat] retreat executado, sem comandos...\n",'retreat';
	} else {
	   my $comando;
	   $comando = $config{retreatCommand};
	   Log::warning "[retreat] retreat executado, comando $comando\n",'retreat';
	   Commands::run("$comando");
	   Commands::run("ai clear");
	}
	
	Commands::run("conf logConsole 1");
	AI::ai_clientSuspend(0, 4);
	unlink($config{retreatFile});
}
sub on_Command {
	my (undef, $message) = @_;
		if( !defined($message) ){
			$message = "command";
		}
		warning($pluginConfig{retreatPrefix}."retreat command received, sending retreat order\n");
		sendRetreatOrder("reason: ".$message);
}
sub unload {
	Plugins::delHooks($pluginHooks);
	Commands::unregister($pluginCHooks);
	undef $pluginHooks;
	undef %pluginConfig;
}
sub sendRetreatOrder {
	my $order = shift;
	# Sending retreat alert
	playSound($config{retreatSound}) if defined($config{retreatSound});
	# Creating retreat file
	my $opened = 1;
	open(RO,">".$pluginConfig{retreatFile}) || ($opened = 0);
	if( $opened != 1 ){
		warning($pluginConfig{retreatPrefix}."retreat order NOT sent (failed to open ".$pluginConfig{retreatFile}.")\n");
	} else {
		print RO $order;
		message($pluginConfig{retreatPrefix}."retreat order sent\n");
		close(RO);
	}
	
	if ($config{retreatDesconect} == 0){
	   Log::warning "[retreat] -- sem desconexao...\n",'retreat';	
	} else {
	   Log::warning "[retreat] -- desconectando...\n",'retreat';	
	   $net->serverDisconnect;
	}
	# Waiting for the sound to finish
	sleep($config{retreatSoundTime}) if $config{retreatSoundTime};
}
sub playSound {
	#my $file = shift;
	WinUtils::playSound('$config{retreatSound}');
}
1;


