Need help in editing playerRecorder.pl

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
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: Need help in editing playerRecorder.pl

#11 Post by EternalHarvest »

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

Code: Select all

use Utils;
...
if (existsInList($config{playerRecorder_notInMap}, $field->name)) {
	return;
}
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?
That's already possible by removing or disabling the plugin, isn't it?

Kaspy
Halfway to Eternity
Halfway to Eternity
Posts: 398
Joined: 08 Jun 2012, 15:42
Noob?: No
Location: Brazil

Re: Need help in editing playerRecorder.pl

#12 Post by Kaspy »

kaoru wrote:Is there a better option other then "return;" to turn the plugin off?
It is already possible to enable/disable plugins manually with the command plugin.
Now, the plugin itself getting on and off is not a very good measure because, as he would reactivate already being disabled!?

It's easier to do what I said, that if in a certain map, not only execute the command, based on a variable.
Image

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

Re: Need help in editing playerRecorder.pl

#13 Post by EternalHarvest »

KeplerBR wrote: It is already possible to enable/disable plugins manually with the command plugin.
Now, the plugin itself getting on and off is not a very good measure because, as he would reactivate already being disabled!?
Why plugin itself? When you need to turn it on or off, you just do that.
It's easier to do what I said, that if in a certain map, not only execute the command, based on a variable.
My commentary was not about "work on a certain map", but "turn the plugin on/off".

If you need an option, it's easier to use something like "return" there. If you need just a possibility to turn plugin on/off completely, it's already possible (sys.txt and plugin command) without even modifying the plugin.

kaoru
Human
Human
Posts: 34
Joined: 20 Jun 2008, 17:47
Noob?: No

Re: Need help in editing playerRecorder.pl

#14 Post by kaoru »

I didn't make myself clear when I asked for a better way to stop the plugin. Nevermind, it's not important now.

It's working. The code is also much less clunky then before. It's not 100%, because it triggers on not excluded players much more often then before, but still, my logs are much cleaner now. Thank you both for the huge help, I think it's a good job for a first edit.

Image

Code: Select all

########################################################
# This plugin is licensed under the GNU GPL            #
# Copyright 2005 by isieo                              #
# contact : - isieo <AT> *NOSPAM* G*MAIL <DOT> COM     #
#                                                      #
# Modified by sli (signedlongint@gmail.com)            #
# ---------------------------------------------------- #
# ---------------------------------------------------- #
# playerrecorder.pl                                    #
# Records Player's name together with AIDs, job and lvl#
# Usefull for players to find out other players' other #
# characters...                                        #
########################################################

package playerRecord;

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

Plugins::register("prec", "playerRecorder", \&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 $aYou = Actor::get($accountID);
	my $selfName = $char->name();
	my $map = $field->baseName;
	my $file = "$Settings::logs_folder/players_$selfName.txt";
		
	return if ($config{playerRecorder} == 0);		
	return if (existsInList($config{playerRecorder_notPlayers}, $targetName));
	return if (existsInList($config{playerRecorder_notInMap}, $map));
		
	if (existsInList($config{playerRecorder_inMap}, $map)) {
	message "Players Exists: $targetName ($targetId)\n";
	open FILE, ">>:utf8", $file;
	my $time=localtime time;
	print FILE "[$time]" . "[$map] " . "\t$targetName ($targetId)\n";		
	close FILE;	
	} else {
		return;
	}
}

1;

Raider
The Kore Devil
The Kore Devil
Posts: 672
Joined: 22 Feb 2013, 03:40
Noob?: No
Location: The Netherlands

Re: Need help in editing playerRecorder.pl

#15 Post by Raider »

Thanks, this is exactly what I was looking for. I wanted to exclude fields from recording players, ended up here by search :)
Added all cities to the @notInMap.

Code: Select all

my @notInMap = ("alberta", "aldebaran", "amatsu", "ayothaya", "brasilis", "comodo", "dewata", "dicastes01", "eclage", "einbroch", "geffen", "gonryun", "hugel", "izlude", "jawaii", "lighthalzen", "louyang", "malangdo", "malaya", "manuk", "mora", "morocc", "moscovia", "niflheim", "payon", "prontera", "rachel", "splendide", "umbala", "veins", "xmas", "yuno");
      for (@notInMap) {
         if ($field->baseName eq $_) {
            return;
         }
      }

Kaspy
Halfway to Eternity
Halfway to Eternity
Posts: 398
Joined: 08 Jun 2012, 15:42
Noob?: No
Location: Brazil

Re: Need help in editing playerRecorder.pl

#16 Post by Kaspy »

Raider, there is already a variable that collects the names of cities, based on the file cities.txt
If it is used, would be better.
Image

Raider
The Kore Devil
The Kore Devil
Posts: 672
Joined: 22 Feb 2013, 03:40
Noob?: No
Location: The Netherlands

Re: Need help in editing playerRecorder.pl

#17 Post by Raider »

KeplerBR wrote:Raider, there is already a variable that collects the names of cities, based on the file cities.txt
If it is used, would be better.
Huh I didn't know, I'm just beginning to participate in the OpenKore community but willing to learn Perl.
Unfortunately I'm vert busy with my study now where we are now learning R and Java.
Could you please explain how I could use that variable based on cities.txt?

Kaspy
Halfway to Eternity
Halfway to Eternity
Posts: 398
Joined: 08 Jun 2012, 15:42
Noob?: No
Location: Brazil

Re: Need help in editing playerRecorder.pl

#18 Post by Kaspy »

I apologize in advance to my bad English...
The functions.pl loads all the files from the control and tables, among them cities.txt, as seen here:

Code: Select all

	Settings::addTableFile('cities.txt',
		loader => [\&parseROLUT, \%cities_lut]);
Based on this, it is possible to know that the variable %cities_lut contains data cities.txt.

Remember that this variable is global, so it is stored in Globals.pm. To use it, you must define, preferably in the header:

Code: Select all

use Globals qw(%cities_lut);
Image

Raider
The Kore Devil
The Kore Devil
Posts: 672
Joined: 22 Feb 2013, 03:40
Noob?: No
Location: The Netherlands

Re: Need help in editing playerRecorder.pl

#19 Post by Raider »

KeplerBR wrote:I apologize in advance to my bad English...
The functions.pl loads all the files from the control and tables, among them cities.txt, as seen here:

Code: Select all

	Settings::addTableFile('cities.txt',
		loader => [\&parseROLUT, \%cities_lut]);
Based on this, it is possible to know that the variable %cities_lut contains data cities.txt.

Remember that this variable is global, so it is stored in Globals.pm. To use it, you must define, preferably in the header:

Code: Select all

use Globals qw(%cities_lut);
I see, how to use the variable like the notInMap or ExistInList?

Kaspy
Halfway to Eternity
Halfway to Eternity
Posts: 398
Joined: 08 Jun 2012, 15:42
Noob?: No
Location: Brazil

Re: Need help in editing playerRecorder.pl

#20 Post by Kaspy »

Raider wrote:I see, how to use the variable like the notInMap or ExistInList?
Using as an example the existsInList...

Use the search function on several files in Notepad++. Search by existsInList.
Then you will find the function it performs - is not a variable, is a function.
Normally, this kind of functions OpenKore is preceded by comments describing and returned values ​​depending on the situation. If this function is:

Code: Select all

##
# boolean existsInList(list, val)
# list: a string containing a list of comma-seperated items.
# val: the value to check for.
#
# Check whether $val exists in $list. This function is case-insensitive.
#
# Example:
# my $list = "Apple,Orange Juice";
# existsInList($list, "apple");		# => 1
# existsInList($list, "Orange Juice");	# => 1
# existsInList($list, "juice");		# => 0
Remember that in Perl, positive values ​​is true, 0 is false.
Image

Post Reply