petFeeder plugin

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
fco2783
Plain Yogurt
Plain Yogurt
Posts: 95
Joined: 05 Apr 2008, 05:15
Noob?: Yes
Location: in place where you cant go
Contact:

petFeeder plugin

#1 Post by fco2783 »

http://bibian.ath.cx/openkore/viewtopic.php?t=4647

credit punkpudding

config options (add in config.txt):

petFeeder <flag> (new in v1.2)
flag: 1 = on, 0 = off
- enables/disables the plugin. disable the plugin if you have no pet & the plugin is causing problems for you.

petSmartFeed <flag>
flag: 1 = on, 0 = off
- when smart feed is on, the feed rate you specified (petFeedRate) will be ignored. when on, the bot will automatically select which hunger level to use based on the pet's intimacy. when pet is not loyal, the pet will be fed as soon as its hunger reaches neutral. when it's loyal, the pet will only be fed when it's hungry. perfect for quickly raising intimacy levels.

petFeedRate <rate>
- allows you to specify the hunger level to be used in feeding your pet. this option is only used when smart feed is off.

petMinHunger <rate>
- allows you to specify the hunger level to use in determining when to return the pet to egg status. if you (accidentally) set this too low (like 0), your pet will still be returned to egg as soon as its hunger gets close to "very hungry". (so even if you screw up, you won't lose your pet! Wink)

petPerformanceRate <rate> (new in v1.2)
- make your pet perform every <rate> seconds. if you don't set this option, the pet won't be automatically played. don't set the rate too low (lower than 5) - that'll make you look suspicious.
* playing with a pet is purely aesthetic. it won't affect you pet's intimacy. but it does look cool. Smile

petPerformanceRateSeed <rate> (new in v1.3)
- random value that is added to petPerformanceRate to make it look more realistic.
example: if the rate is 30 & the seed is 30, your pet will be automatically played after a random period between 30 and 60 (=30+30) seconds.

petPerformance_onAction <AI sequences> (new in v1.5)
- if this option is set, pet performance will only be used if at least one of the specified comma-separated list of AI sequences is curently active.

petPerformance_notOnAction <AI sequences> (new in v1.4)
- if this option is set, pet performance will only be used if none of the specified comma-separated list of AI sequences is curently active.


console commands:
note: you need to set "petFeeder 1" to enable console commands

pet s[tatus]
- display the pet's hunger & intimacy level.

pet f[eed]
- feed the pet.

pet p[erformance]
- make the pet perform.

pet r[eturn]- return the pet to egg.

pet u[nequip]
- unequip the pet's accessory.

other features:

1. shortened console commands
- you can now type "pet s" instead of "pet status", "pet f" instead of "pet feed", etc. but you can still use the old commands if you wish.

2. over-feeding prevention
- it won't allow you to feed your pet if its hunger status is full (even if you manually typed "pet f" in the console).

3. auto return to egg
- your pet will be automatically returned to egg status when its hunger gets close to "very hungry". this will prevent the pet from lowering its intimacy & running away. useful if you run out of pet food -if you're far from the store, or if your pet's food is rare (honey, shoot, etc).

some clarifications on pet food:

i've been asked about this a lot of times now so i thought i'd clarify it here: you don't need to specify what pet food this plugin has to use.

Usage
petFeeder 1
petFeedRate 50
petMinHunger 20
petPerformanceRate 30
petPerformanceRateSeed 30
petPerformance_notOnAction attack, skill_use

Code: Select all

# petFeeder v1.5
# -by punkpudding

package petFeeder;

use strict;
use Time::HiRes qw(time);
use Globals;
use Plugins;
use Log qw(debug message warning error);
use Utils;
use Commands;
use Network;
use Network::Send;

Plugins::register('petFeeder', 'petFeeder by punkpudding', \&onUnload, \&onReload);
my $hookCommandPost = Plugins::addHook('Command_post', \&onCommandPost);
my $hookAIpre = Plugins::addHook('AI_pre', \&onAIpre);
my $hookParseMsgPre = Plugins::addHook('parseMsg/pre', \&onParseMsgPre);

message "Pet feeding plugin loaded\n", "success";

my %pet;
my $hunger = 72;
my $performanceRate = $config{petPerformanceRate};


sub onUnload {
	Plugins::delHook('parseMsg/pre', $hookParseMsgPre);
	Plugins::delHook('AI_pre', $hookAIpre);
	Plugins::delHook('Command_post', $hookCommandPost);
	message "Pet feeding plugin unloaded\n", "success";
}

sub onReload {
	&onUnload;
}

sub onCommandPost {
	my (undef, $args) = @_;
	my ($cmd, $subcmd) = split(' ', $args->{input}, 2);
	if ($cmd eq "pet" && $config{petFeeder}) {
		if ($subcmd eq "s" || $subcmd eq "status") {
			message "Pet status: hungry=$pet{hungry} intimacy=$pet{friendly}\n";
		} elsif ($subcmd eq "f" || $subcmd eq "feed") {
			if ($pet{hungry} <= 72) {
				message "Feeding your pet. [current intimacy : $pet{friendly}]\n";
				sendPetFeed($::net);
				sendPetGetInfo($::net);
			} elsif ($pet{hungry} > 72) {
				message "Your pet's not yet hungry. Feeding him now will lower intimacy.\n";
			}
		} elsif ($subcmd eq "p" || $subcmd eq "performance") {
			message "Playing your pet.\n";
			sendPetPerformance($::net);
		} elsif ($subcmd eq "r" || $subcmd eq "return") {
			message "Returning pet to egg status.\n";
			sendPetReturnToEgg($::net);
		} elsif ($subcmd eq "u" || $subcmd eq "unequip") {
			message "Unequipping pet accessory.\n";
			sendPetUnequipItem($::net);
		} else {
			error "Syntax Error in function 'pet' (pet management)\n" .
				"Usage: pet < s[tatus] | f[eed] | p[erformance] | r[eturn] | u[nequip] >\n";
		}
		$args->{return} = 1;
	}
}

sub onAIpre {
	return unless ($main::conState == 5);
	if ($config{petFeeder}) {
		# request status
		if (timeOut($pet{lastStatusInfo}, 30)) {
			if (timeOut($pet{lastStatusRequest}, 10)) {
				$pet{lastStatusRequest} = time;
				sendPetGetInfo($::net);
				if ($pet{friendly} < 990) { $hunger = 72; }
				elsif ($pet{friendly} >=990) { $hunger = 30; }
			}
		}
		# pet performance
		if ((defined($config{petPerformanceRate}) && timeOut($pet{lastPerformance}, $performanceRate))
		  && ((!$config{petPerformance_onAction}) || ($config{petPerformance_onAction} && existsInList($config{petPerformance_notOnAction}, AI::action())))
		  && ((!$config{petPerformance_notOnAction}) || ($config{petPerformance_notOnAction} && !existsInList($config{petPerformance_notOnAction}, AI::action())))
		) {
			sendPetPerformance($::net);
			message "Auto-playing your pet\n";
			$performanceRate = $config{petPerformanceRate} if !defined($performanceRate);
			$performanceRate = $config{petPerformanceRate} + int(rand $config{petPerformanceRateSeed}) if $config{petPerformanceRateSeed};
			$pet{lastPerformance} = time;
		}
	}
}

sub onParseMsgPre {
	my (undef, $args) = @_;
	my $switch = $args->{switch};
	my $msg = $args->{msg};
	# process status
	if ($switch eq "01A2" && $config{petFeeder}) {
		$pet{name} = substr($msg, 2, 24) =~ /([\s\S]*?)\000/;
		$pet{nameflag} = unpack("C1", substr($msg, 26, 1));
		$pet{level} = unpack("S1", substr($msg, 27, 2));
		$pet{hungry} = unpack("S1", substr($msg, 29, 2));
		$pet{friendly} = unpack("S1", substr($msg, 31, 2));
		$pet{accessory} = unpack("S1", substr($msg, 33, 2));
		$pet{lastStatusInfo} = time;
		debug "Pet status: level=$pet{level} hungry=$pet{hungry} intimacy=$pet{friendly}\n";
		if ($config{petSmartFeed}) {
			if ($pet{hungry} < $hunger && timeOut($pet{lastFeed}, 5) && $pet{friendly} > 0) {
				$pet{lastFeed} = time;
				sendPetFeed($::net);
				sendPetGetInfo($::net);
				message "Auto-feeding your pet. [current intimacy : $pet{friendly}]\n";
			}
			if ($pet{hungry} <= $config{petMinHunger} || $pet{hungry} <= 15) {
				sendPetReturnToEgg($::net);
				message "Critical hunger level reached. Pet returned to egg status.\n";
			}	
		} else {
			if ($pet{hungry} < $config{petFeedRate} && timeOut($pet{lastFeed}, 5) && $pet{friendly} > 0) {
				$pet{lastFeed} = time;
				sendPetFeed($::net);
				sendPetGetInfo($::net);
				message "Auto-feeding your pet. [current intimacy : $pet{friendly}]\n";
			}
			if ($pet{hungry} <= $config{petMinHunger} || $pet{hungry} <= 15) {
				sendPetReturnToEgg($::net);
				message "Critical hunger level reached. Pet returned to egg status.\n";
			}	
		}
	}
}

return 1;
Last edited by fco2783 on 18 Apr 2008, 06:44, edited 1 time in total.

Cadeath
Plain Yogurt
Plain Yogurt
Posts: 59
Joined: 05 Apr 2008, 05:14

Re: petFeeder plugin

#2 Post by Cadeath »

Code: Select all

petFeeder 1
petFeedRate 50
petMinHunger 20
petPerformanceRate 30
petPerformanceRateSeed 30
petPerformance_notOnAction attack, skill_use
Please explain further.. Thanks

gaanan100
Noob
Noob
Posts: 1
Joined: 07 May 2008, 11:37
Noob?: Yes

Re: petFeeder plugin

#3 Post by gaanan100 »

Do we have to save the code thing? and where to save it?

Roxas
Noob
Noob
Posts: 13
Joined: 06 May 2008, 02:53
Noob?: No
Location: No man's land

Re: petFeeder plugin

#4 Post by Roxas »

The code shud be saved under plugins folder...imo, and the config settings shud be inserted in config.txt

The name of the plugin shud be petFeeder.pl I guess.
Image

Cadeath
Plain Yogurt
Plain Yogurt
Posts: 59
Joined: 05 Apr 2008, 05:14

Re: petFeeder plugin

#5 Post by Cadeath »

Code: Select all

petFeeder 1
petFeedRate 50
petMinHunger 20
petPerformanceRate 30
petPerformanceRateSeed 30
petPerformance_notOnAction attack, skill_use
Please explain further.. Thanks

fco2783
Plain Yogurt
Plain Yogurt
Posts: 95
Joined: 05 Apr 2008, 05:15
Noob?: Yes
Location: in place where you cant go
Contact:

Re: petFeeder plugin

#6 Post by fco2783 »

Cadeath wrote:

Code: Select all

petFeeder 1
petFeedRate 50
petMinHunger 20
petPerformanceRate 30
petPerformanceRateSeed 30
petPerformance_notOnAction attack, skill_use
Please explain further.. Thanks
you could read the manual above...

Cadeath
Plain Yogurt
Plain Yogurt
Posts: 59
Joined: 05 Apr 2008, 05:14

Re: petFeeder plugin

#7 Post by Cadeath »

fco2783 wrote:
Cadeath wrote:

Code: Select all

petFeeder 1
petFeedRate 50
petMinHunger 20
petPerformanceRate 30
petPerformanceRateSeed 30
petPerformance_notOnAction attack, skill_use
Please explain further.. Thanks
you could read the manual above...
thanks for editing!

ubernoob
Noob
Noob
Posts: 2
Joined: 31 Oct 2008, 00:32
Noob?: Yes

Re: petFeeder plugin

#8 Post by ubernoob »

I get this error... where did I go wrong?
** OpenKore what-will-become-2.0.7 (SVN Version) - Custom Ragnarok Online
client ***
*** http://www.openkore.com/ ***

Loading all plugins...
Loading plugin plugins/petfeeder.pl...
This plugin cannot be loaded because of a problem in the plugin. Please notify
the plugin's author about this problem, or remove the plugin so OpenKore can
start.

The error message is:
Plugin contains syntax errors:
syntax error at C:/Leara/Programs/KoreSVN/plugins/petfeeder.pl line 4, near
"package petFeeder"
BEGIN not safe after errors--compilation aborted at
C:/Leara/Programs/KoreSVN/plugins/petfeeder.pl line 6.

Press ENTER to exit this program.

fco2783
Plain Yogurt
Plain Yogurt
Posts: 95
Joined: 05 Apr 2008, 05:15
Noob?: Yes
Location: in place where you cant go
Contact:

Re: petFeeder plugin

#9 Post by fco2783 »

ubernoob wrote:I get this error... where did I go wrong?
** OpenKore what-will-become-2.0.7 (SVN Version) - Custom Ragnarok Online
client ***
*** http://www.openkore.com/ ***

Loading all plugins...
Loading plugin plugins/petfeeder.pl...
This plugin cannot be loaded because of a problem in the plugin. Please notify
the plugin's author about this problem, or remove the plugin so OpenKore can
start.

The error message is:
Plugin contains syntax errors:
syntax error at C:/Leara/Programs/KoreSVN/plugins/petfeeder.pl line 4, near
"package petFeeder"
BEGIN not safe after errors--compilation aborted at
C:/Leara/Programs/KoreSVN/plugins/petfeeder.pl line 6.

Press ENTER to exit this program.
your problem is that you using a higher SVN... this plugin could only work at openkore 2.0.0 below

kalansay
Human
Human
Posts: 39
Joined: 15 Apr 2008, 18:58
Noob?: Yes
Contact:

Re: petFeeder plugin

#10 Post by kalansay »

Code: Select all

sendPetPerformance($::net);
That's the problem. I don't know how to fix it to make it work for newer version.
I think everything with ($::net) and (::net) is the problem.
For your CPU Usage & Memory usage concerns...
http://forums.openkore.com/viewtopic.php?f=10&t=33261
Image

Post Reply