Page 1 of 3

Need help in editing playerRecorder.pl

Posted: 04 Dec 2012, 11:28
by kaoru
I'm looking for help to edit playerRecorder.pl. I have no idea how to write plugins, I can only edit a thing or two and very poorly.

Could you guys help me to (a) make an exlusion for a specific list of players so the plugin won't trigger if these specific players are spotted and (b) also make an exclusion for specific maps (to avoid towns, for example)?

Code: Select all

sub write_player {
	my (undef, $args) = @_;
	my $targetId = $args->{player}{nameID};
	my $targetName = $args->{player}{name};
	my $selfName = $char->name();
	my $file = "$Settings::logs_folder/players_$selfName.txt";
	message "Player Exists: $targetName ($targetId)\n";

	open FILE, ">>:utf8", $file;
	my $time=localtime time;
	print FILE "[$time] " . $field->baseName . "\t$targetId $targetName\n";
	close FILE;
}

1;
EDIT #1: I think I got how to exclude the autorized players (Player1, Player2) by looking at other macros, but I don't know which order should I give to make the bot ignore them (marked by ####### COMMAND TO IGNORE EXCLUDED PLAYERS #######)

Code: Select all

sub write_player {
	my (undef, $args) = @_;
	my $targetId = $args->{player}{nameID};
	my $targetName = $args->{player}{name};
	my $selfName = $char->name();
	my $file = "$Settings::logs_folder/players_$selfName.txt";
	if ($name =~ /^([Player1|Player2/i) {
####### COMMAND TO IGNORE EXCLUDED PLAYERS #######
	} else {
		message "Player Exists: $targetName ($targetId)\n";
	}
Still need help to exclude fields, tough.

Re: Need help in editing playerRecorder.pl

Posted: 04 Dec 2012, 17:08
by Kaspy
Kaoru, if you explain in detail what I need (my english is bad), can help you.
You need what, exactly? Do not list certain players or maps? Or is it both?

Re: Need help in editing playerRecorder.pl

Posted: 04 Dec 2012, 18:08
by EternalHarvest
Put something like this before line with "message":

Code: Select all

for ("Player1", "Player2") {
	if ($name eq $_) {
		return;
	}
}
That would stop execution of the subroutine.

For maps, the same, but use $field->name instead of $name.

Re: Need help in editing playerRecorder.pl

Posted: 04 Dec 2012, 18:27
by kaoru
Thank you very much, EH. I'll try it right away.

[PT-BR] Sem problemas, Kepler. Eu quero adicionar duas coisas:

1) Criar uma lista de exclusão para que o plugin somente logue os jogadores específicos que estiverem fora dessa lista criada. Eu frequentemente boteio em mapas inóspitos, e o meu log é spamado com mensagens dos meus próprios bots, então fica horrível para discerni-los dos jogadores comuns.

Perceba que no edit do primeiro post, eu criei uma exclusão simples para os jogadores, mas o EternalHarvest propôs uma solução aparentemente melhor.

2) Também fazer uma exclusão para mapas específicos, assim o plugin não loga personagens em mapas desnecessários, como caminhos de rota ou cidades.

Código original do plugin playerRecorder.pl:

Code: Select all

package playerRecord;

use strict;
use Plugins;
use Log qw(message);
use Globals;
use Settings;
use Actor;

Plugins::register("prec", "playerRecord", \&on_unload, \&on_reload);
my $hook = Plugins::addHook('charNameUpdate', \&write_player, undef);

sub on_unload {
	Plugins::delHook("charNameUpdate", $hook);
}
sub on_reload {
	message "playerRecord plugin reloading, ";
	Plugins::delHook("charNameUpdate", $hook);
}
sub write_player {
	my (undef, $args) = @_;
	my $targetId = $args->{player}{nameID};
	my $targetName = $args->{player}{name};
	my $selfName = $char->name();
	my $file = "$Settings::logs_folder/players_$selfName.txt";
	message "Player Exists: $targetName ($targetId)\n";

	open FILE, ">>:utf8", $file;
	my $time=localtime time;
	print FILE "[$time] " . $field->baseName . "\t$targetId $targetName\n";
	close FILE;
}

1;

Re: Need help in editing playerRecorder.pl

Posted: 04 Dec 2012, 19:13
by kaoru
EDIT: IGNORE THIS POST!

Just tried it, it's not working. :(

Code: Select all

sub write_player {
	my (undef, $args) = @_;
	my $targetId = $args->{player}{nameID};
	my $targetName = $args->{player}{name};
	my $selfName = $char->name();
	my $file = "$Settings::logs_folder/players_$selfName.txt";

	for ("player1", "player2") {
		if ($name eq $_) {
		return;
		}
	}
		
	for ("prontera", "geffen", "alberta") {
		if ($field->name eq $_) {
		return;
	}
	}

	message "Player Exists: $targetName ($targetId)\n";

	open FILE, ">>:utf8", $file;
	my $time=localtime time;
	print FILE "[$time] " . $field->baseName . "\t$targetId $targetName\n";
	close FILE;
}
Also tried both separated ($field->name and $name) to see if any of them worked, no success. Also tried changing $field->name for $field->baseName and $name for $targetName, didn't work!

EDIT: Also tried using regexp, nothing...

Code: Select all

# (...)
if ($name =~ /^(player1|player2)/i {
return;
} else {
message "Player Exists: $targetName ($targetId)\n";
# (...)
}

Re: Need help in editing playerRecorder.pl

Posted: 05 Dec 2012, 01:05
by Kaspy

Code: Select all

	my $permission = 1;
	my @mapNameList = ('prontera', 'geffen', 'alberta');
	for (@mapNameList) {
		if ($field->name eq $_) {
		$ativado = 0;
		}
	}

	if ($permission) {
		message "Activated \n";
	}
I believe we have a much better method, but I'm not remembering the command...
In @mapNameList you should put the name of the maps that will NOT list. If you want, you can read a text file.

Use this example for the names of the characters case of

Re: Need help in editing playerRecorder.pl

Posted: 05 Dec 2012, 05:31
by MiBo
I didn't check the code cuz ima at work - but dont forget, that string comparison in perl is case sensitive. If you want case insensitive, try out the lc function.

Maybe the given map names/player names start with an upper letter?

Best regards,
MiBo

Re: Need help in editing playerRecorder.pl

Posted: 05 Dec 2012, 23:03
by kaoru
Thanks for the support so far. We're getting close.

[ENG] IT WORKS, but partially. The player exclusion is broken. Nevermind my last post, sys.txt was targetting another playerRecorder.pl... Sorry, I'm very rusty. I'm using the following code, based on previous suggestions:

[PT-BR] TÁ FUNCIONANDO, mas ainda têm alguns erros. A exclusão de jogadores roda parcialmente e precisa de conserto. O código ficou assim, baseado nas sugestões prévias:

Code: Select all

package playerRecord;

use strict;
use Plugins;
use Log qw(message);
use Globals;
use Settings;
use Actor;

Plugins::register("prec", "playerRecord", \&on_unload, \&on_reload);
my $hook = Plugins::addHook('charNameUpdate', \&write_player, undef);

sub on_unload {
	Plugins::delHook("charNameUpdate", $hook);
}
sub on_reload {
	message "playerRecord plugin reloading, ";
	Plugins::delHook("charNameUpdate", $hook);
}
sub write_player {
	my (undef, $args) = @_;
	my $targetId = $args->{player}{nameID};
	my $targetName = $args->{player}{name};
	my $selfName = $char->name();
	my $file = "$Settings::logs_folder/players_$selfName.txt";
	
	my @notPlayers = ("~º kaoru º~", "kaoru®", "kaoru", "Ka Oru");
		for (@notPlayers) {
			if ($targetName eq $_) {
				return;
			}
		}
		
		my @notInMap = ("prontera", "geffen", "alberta");
		for (@notInMap) {
			if ($field->baseName eq $_) {
				return;
			}
		}
	
	message "Player Exists: $targetName ($targetId)\n";

	open FILE, ">>:utf8", $file;
	my $time=localtime time;
	print FILE "[$time] " . $field->baseName . "\t$targetId $targetName\n";
	close FILE;
}

1;
[ENG] The map exclusion (@notInMap) works perfectly. It has room for improvement, but I'll cover it in another post.

My issues:

1. The player exclusion (@notPlayers) is not working properly with players that have special characters in their names. While "kaoru" and "Ka Oru" are excluded, "~º kaoru º~" and "kaoru®" are still logged, despite being in the exclusion list.

2. Not a very important issue, but still needs to be looked after: after the changes, the plugin is uptading the non-excluded players much more often then before. As soon as the player goes out of sight and returns, he is logged again, while before it had a certain "delay" to log him again. Maybe a problem with charNameUpdate?

3. $time=localtime time returns me time in "DDD MMM dd HH:HH:HH YYYY" (Thu Dec 6 01:25:40 2012) format. How do I make it "dd mm HH:HH" (6 12 01:25, or anything similar)?

[PT-BR] A exclusão dos mapas (@notInMap) está funcionando perfeitamente. Tem espaço para melhoras, mas cobrirei isso depois.

Os problemas:

1. A exclusão dos jogadores (@notPlayers) não está funcionando adequadamente com personagens que têm caracteres especiais nos nomes. Enquanto "kaoru" e "Ka Oru" são excluídas, "~º kaoru º~" e "kaoru®" são registradas no log, apesar de estarem incluídas na exclusão.

2. Esse problema não incomoda muito, mas precisa de atenção: depois das mudanças, o plugin tá atualizando os jogadores não excluídos com muito mais frequência. Assim que o jogador sai da vista do bot e retorna, ele é logado novamente, diferente de antes, que tinha um certo delay. Talvez um problema com charNameUpdate?

3. $time=localtime time retorna tempo no formato "DDD MMM dd HH:HH:HH YYYY" (Thu Dec 6 01:25:40 2012). Como eu passo pro formato "dd mm HH:HH" (6 12 01:25)? Ou algo similar.

Re: Need help in editing playerRecorder.pl

Posted: 05 Dec 2012, 23:19
by Kaspy
Regarding the time, had once fix this BUG in another plugin. But now as I did not remember.
Try using use Time::HiRes

In relation to not exclude those nicks, if it really happened you said, I believe it is because of the special characters used. You formatted correctly plugin (UTF-8 without boom)?

Re: Need help in editing playerRecorder.pl

Posted: 06 Dec 2012, 04:12
by kaoru
I have no idea what the hell I did, but it's working now! Thank you for the help! The time thing didn't work, but whatever.

I may want to link @notInMap to a config key in config.txt, like playerRecorder_notInMap. Is there a simple way to do it?

Also, I made another config key to turn the plugin on/off: playerRecorder [boolean]
Is there a better option other then "return;" to turn the plugin off?

Code: Select all

if ($config{playerRecorder} == 0){
			return;
		} else {