Retreat plugin - by Setzer

Other plugins for extending OpenKore's functionality. This forum is only for posting new plugins and commenting on existing plugins. For support, use the Support forum.

Moderator: Moderators

Message
Author
KoreGhost
Developers
Developers
Posts: 123
Joined: 28 Mar 2011, 12:48
Noob?: No
Location: Brazil
Contact:

Retreat plugin - by Setzer

#1 Post by KoreGhost »

Function: Retreat bots after action of GMs

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 finish
Example: 5 bots in gef_fild04 e 6 bots in gef_fild03

gef_fild03

Code: Select all

retreatFile c:\retreatGef_fild03.txt
retreatValid 1
retreatCommand relog 800
retreatDesconect 0
retreatSound "C:\Sons\GM.wav"
gef_fild04

Code: Select all

retreatFile c:\retreatGef_fild04.txt
retreatValid 1
retreatCommand relog 800
retreatDesconect 0
retreatSound "C:\Sons\GM.wav"
Important: prefers config all to relog in action of GMs, case its server uses bans for IPs. For this use

Code: Select all

retreatFile c:\retreat.txt
Copy code to notepad, save to retreat.pl in folders "plugins"

Code: 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;

sagoforfree
Noob
Noob
Posts: 1
Joined: 17 May 2011, 22:03
Noob?: No

Re: Retreat plugin - by Setzer

#2 Post by sagoforfree »

how does this plugin work. i need details on the notepad named retreat file... and it doesn't trigger any on my other bots.

need help. thnx!

EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: Retreat plugin - by Setzer

#3 Post by EternalHarvest »

Very comprehensive problem description.

"retreatFile" would be created/deleted automatically, it seems.

Unknown6996
Human
Human
Posts: 24
Joined: 07 Oct 2011, 11:21
Noob?: No

Re: Retreat plugin - by Setzer

#4 Post by Unknown6996 »

Eu estou tendo um problema.
Por exemplo :
Se eu abro o Plugin com o arquivo c:\retreatFile.txt existir,dá crash,aparecendo isto :

Code: Select all

OpenKore version what-will-become-2.1
Network state = 1
Network handler = Network::DirectConnection
SVN revision: 7860
Loaded plugins:
  plugins/macro.pl (macro)
  plugins/retreat.pl (retreat)

Error message:
Attempt to STORE non blessed reference (or not a reference)
Value:
$VAR1 = {};

Stack trace:
Attempt to STORE non blessed reference (or not a reference)
Value:
$VAR1 = {};
 at src/Utils/BlessedRefTie.pm line 10
	Tie::BlessedRef::STORE('Tie::BlessedRef=SCALAR(0x4ea65c4)', 'HASH(0x3a70684)') called at src/Commands.pm line 453
	Commands::cmdAI('ai', 'clear') called at src/Commands.pm line 285
	Commands::run('ai clear') called at D:/-Openkore/Openkore BR - Tortoise/plugins/retreat.pl line 94
	retreat::on_MainLoop('mainLoop_pre', undef, undef) called at src/Plugins.pm line 431
	Plugins::callHook('mainLoop_pre') called at src/functions.pl line 69
	main::mainLoop() called at src/Interface.pm line 75
	Interface::mainLoop('Interface::Console::Win32=HASH(0x3fcc5c4)') called at D:\-Openkore\Openkore BR - Tortoise\openkore.pl line 97
	main::__start() called at D:\-Openkore\Openkore BR - Tortoise\openkore.pl line 187
Mas se o arquivo não existir nesse diretório,ele vai de boa.

--------------
If i open my openkore,and the archive c:\retreatFile.txt exists,i get this error :

Code: Select all

OpenKore version what-will-become-2.1
Network state = 1
Network handler = Network::DirectConnection
SVN revision: 7860
Loaded plugins:
  plugins/macro.pl (macro)
  plugins/retreat.pl (retreat)

Error message:
Attempt to STORE non blessed reference (or not a reference)
Value:
$VAR1 = {};

Stack trace:
Attempt to STORE non blessed reference (or not a reference)
Value:
$VAR1 = {};
 at src/Utils/BlessedRefTie.pm line 10
	Tie::BlessedRef::STORE('Tie::BlessedRef=SCALAR(0x4ea65c4)', 'HASH(0x3a70684)') called at src/Commands.pm line 453
	Commands::cmdAI('ai', 'clear') called at src/Commands.pm line 285
	Commands::run('ai clear') called at D:/-Openkore/Openkore BR - Tortoise/plugins/retreat.pl line 94
	retreat::on_MainLoop('mainLoop_pre', undef, undef) called at src/Plugins.pm line 431
	Plugins::callHook('mainLoop_pre') called at src/functions.pl line 69
	main::mainLoop() called at src/Interface.pm line 75
	Interface::mainLoop('Interface::Console::Win32=HASH(0x3fcc5c4)') called at D:\-Openkore\Openkore BR - Tortoise\openkore.pl line 97
	main::__start() called at D:\-Openkore\Openkore BR - Tortoise\openkore.pl line 187
but if this file does not exist,i don't receive the crash's message !
Sorry for english ;D

Imagem do erro
Error image :
Image
Or url :
http://imageshack.us/photo/my-images/208/errorkm.jpg/

Post Reply