Items Transfer (scratch)

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
d3fc0n
Noob
Noob
Posts: 9
Joined: 04 Apr 2008, 13:34

Items Transfer (scratch)

#1 Post by d3fc0n »

tested on svn 2.0.6

work like ezza's items transfer macro.

but it's have 2 function in 1 plugin. each of function start by command

reciever use "itemx recieve"

sender use "itemx send"

requirement
- use same storageAuto_npc, storageAuto_npc_type, storageAuto_npc_steps config
- use dealAuto_names config for master name (sender)

itemsTransfer.txt file format

Code: Select all

//Name<TAB>Weight
Aloe	1
Clover	1
Four Leaf Clover	1
Large Jellopy	1
itemsTransfer.pl

Code: Select all

#########################################################################
# This software is open source, licensed under the GNU General Public
# License, version 2.
# Basically, this means that you're allowed to modify and distribute
# this software. However, if you distribute modified versions, you MUST
# also distribute the source code.
# See http://www.gnu.org/licenses/gpl.html for the full license.
#########################################################################
# Items Transfer
# d3fc0n 1/05/2008
#########################################################################

package itemsTransfer;

use strict;
use Plugins;
use AI;
use Globals qw($char $conState $messageSender $playersList %config %currentDeal %storage %timeout @storageID);
use Log qw(error message);
use Misc qw(deal dealAddItem getNPCInfo);
use Utils qw(distance timeOut);

Plugins::register('itemsTransfer', 'Items Transfer.', \&on_unload);

my $hooks = Plugins::addHooks(
		['AI_pre', \&AI_pre]
	);
my $cmd = Commands::register(
		['itemx', 'Items Transfer.', \&initial]
	);

sub on_unload {
	Plugins::delHook($hooks);
	Commands::unregister($cmd);
}

sub initial {
	my (undef, $switch) = @_;
	return if (!$switch);

	my %args;
	$args{npc} = {};
	getNPCInfo($config{'storageAuto_npc'}, $args{npc});

	if (defined($args{npc}{ok})) {
		$config{sellAuto} = 0;
		$config{storageAuto} = 0;
		parseTransferList("$Plugins::current_plugin_folder/itemsTransfer.txt", \%{$args{list}});
		$args{state} = 0;

		if ($switch eq 'send') {
			$config{dealAuto} = 0;
			$args{type} = 0;

		} elsif ($switch eq 'recieve') {
			$config{dealAuto} = 3;
			$args{type} = 1;

		} else {
			return;
		}

		AI::queue('itemsTransfer', \%args);
	}
}

sub AI_pre {
	return unless (($conState == 5) && (AI::action eq 'itemsTransfer'));

	my $args = AI::args;

	if (distance($args->{npc}{pos}, $char->{pos_to}) > 2) {
		$args->{state} = 1;
		message "route\n";
		ai_route(
				$args->{npc}{map},
				($args->{type} == 0) ? $args->{npc}{pos}{x} - 1 : $args->{npc}{pos}{x} + 1,
				$args->{npc}{pos}{y} - 1,
				attackOnRoute => 1
			);
		return;
	}

	if (!$storage{opened} && timeOut($timeout{ai_storageAuto_giveup})) {
		$timeout{ai_storageAuto_giveup}{time} = time;
		$timeout{ai_storageAuto}{time} = time;

		if ($config{'storageAuto_npc_type'} eq "" || $config{'storageAuto_npc_type'} eq "1") {
			$config{'storageAuto_npc_steps'} = "c r1 n";

		} elsif ($config{'storageAuto_npc_type'} eq "2") {
			$config{'storageAuto_npc_steps'} = "c c r1 n";

		} elsif ($config{'storageAuto_npc_type'} eq "3") {
			message T("Using storage steps defined in config.\n"), "info";

		} else {
			error T("Wrong storageAuto_npc_type.\n");
			AI::dequeue();
		}
		$args->{state} = 2;
		message "open store\n";
		ai_talkNPC(
				$args->{npc}{pos}{x},
				$args->{npc}{pos}{y},
				$config{'storageAuto_npc_steps'}
			);
		return;
	}

	if ($args->{type} == 0) {

		 if ($storage{opened} && ($args->{state} <= 2) && timeOut($timeout{ai_storageAuto})) {
			$timeout{ai_dealAutoCancel}{time} = time;
			$timeout{ai_storageAuto}{time} = time;
			message "get store\n";

			for (my $i = 0; $i < @storageID; $i++) {
				next if ($storageID[$i] eq "");
				my $item = $storage{$storageID[$i]};
				next if (!defined $args->{list}{$item->{name}});
				my $amount = int((($char->{'weight_max'} * 90 / 100) - $char->{'weight'}) / $args->{list}{$item->{name}});

				if ($amount > 0) {

					if ($amount > $item->{amount}) {
						$amount = $item->{amount};
					}
					$messageSender->sendStorageGet($item->{index}, $amount);
					return;

				} else {
					$args->{state} = 3;
					$args->{more} = 1;
					message "full inv\n";
					return;
				}
			}
			message "empty store\n";
			$args->{state} = 3;
			$args->{more} = 0;
			return;
		}

		if (!%currentDeal && ($args->{state} == 3) && timeOut($timeout{ai_dealAutoCancel})) {
			$timeout{ai_dealAutoCancel}{time} = time;
			$timeout{ai_dealAuto}{time} = time;

			foreach my $pl (@{$playersList->getItems()}) {

				if ($pl->{name} eq $config{dealAuto_names}) {
					deal($pl);
					message "deal start\n";
					return;
				}
			}
			return;
		}

		if (%currentDeal && ($args->{state} == 3) && timeOut($timeout{ai_dealAuto})) {
			$timeout{ai_dealAuto}{time} = time;
			$timeout{ai_storageAuto}{time} = time;
			message "deal add\n";

			if ($currentDeal{you_items} < 10) {

				for (my $i = 0; $i < @{$char->inventory->getItems()}; $i++) {
					my $item = $char->inventory->getItems()->[$i];
					next if (!defined $args->{list}{$item->{name}});
					next if $item->{equipped};
					next if ($item->{broken} && $item->{type} == 7);
					dealAddItem($item, $item->{amount});
					return;
				}

				if ($currentDeal{you_items} >= 1) {
					$args->{state} = 4;
					$messageSender->sendDealFinalize();
					message "deal final\n";
					return;

				} else {
					$args->{state} = 2;
					$messageSender->sendCurrentDealCancel();
					message "deal cancle\n";

					if ($args->{more} == 0) {
						AI::dequeue();
					}
					return;
				}

			} else {
				$args->{state} = 4;
				$messageSender->sendDealFinalize();
				message "deal final\n";
				return;
			}
		}

		if ($currentDeal{'you_finalize'} && $currentDeal{'other_finalize'} && ($args->{state} == 4) && timeOut($timeout{ai_dealAuto})) {
			$timeout{ai_dealAutoCancel}{time} = time;
			$timeout{ai_dealAuto}{time} = time;
			$args->{state} = 3;
			$messageSender->sendDealTrade();
			message "deal end\n";
			return;
		}
	}

	if (($args->{type} == 1) && $storage{opened} && timeOut($timeout{ai_storageAuto})) {
		$timeout{ai_storageAuto}{time} = time;

		if(@storageID >= 300 && $config{'dcOnStorageFull'}) {
			error T("Storage is full!\n");
			AI::dequeue();
		}

		foreach my $item (@{$char->inventory->getItems()}) {
			next if (!defined $args->{list}{$item->{name}});
			next if ($item->{equipped});
			next if ($item->{broken} && ($item->{type} == 7));
			$messageSender->sendStorageAdd($item->{index}, $item->{amount});
			return;
		}
		return;
	}
}

sub parseTransferList {
	my ($file, $r_hash) = @_;

	undef %{$r_hash};
	my $reader = new Utils::TextReader($file);
	while (!$reader->eof()) {
		my $line = $reader->readLine();
		next if ($line =~ /^#/);
		$line =~ s/[\r\n\x{FEFF}]//g;
		next if (length($line) == 0 || $line =~ /^\/\//);

		my ($name, $weight) = split /\t+/, $line, 2;

		if (($name ne "") && ($weight ne "")) {
			$r_hash->{$name} = $weight;
		}
	}
	return 1;
}

return 1;
again, this is just scratch. if u can fix it's. please
sorry for my eng. i'm just another thailander.

oldjay
Noob
Noob
Posts: 2
Joined: 19 Jul 2008, 23:03
Noob?: Yes

Re: Items Transfer (scratch)

#2 Post by oldjay »

Hi d3fc0n,

Sorry my poor english...
I live in south of south america in a place called "Rio Grande do Sul/Brasil".
Well, that's my problem...
The recieve bot open the storage and my serve doesn't support this function.
The sender bot try to deal, but the recieve bot not respond...

Config for bot_sender:
storageAuto 0
storageAuto_npc amatsu 102 149
storageAuto_distance 3
storageAuto_npc_type 1
storageAuto_npc_steps c r1 n
storageAuto_password
storageAuto_keepOpen 0
storageAuto_useChatCommand
relogAfterStorage 0
minStorageZeny

Config for bot receive:
dealAuto 3
dealAuto_names bot_sender_name

storageAuto 0
storageAuto_npc amatsu 102 149
storageAuto_distance 3
storageAuto_npc_type 1
storageAuto_npc_steps c r1 n
storageAuto_password
storageAuto_keepOpen 0
storageAuto_useChatCommand
relogAfterStorage 0
minStorageZeny

What I have to do?
Best regards, and thanks for your atention.

ezza
Developers
Developers
Posts: 109
Joined: 04 Apr 2008, 09:50

Re: Items Transfer (scratch)

#3 Post by ezza »

@oldjay - Some servers wont allow you to use deal while in storage status. In addition to that problem.. as the author said, its just a scratch ... you need to fix it in order to use the plugin. 1 of the many main problem is Weight problem ... how each of the bot knows the other bot's weight? Not mentioning yet about the receiving bot Storage ID and Inventory ID. There are lots of things involve in this transfer routine when I created the Transfer macro (i just take the simple solotion but very neat). Thats my 2 cents.

oldjay
Noob
Noob
Posts: 2
Joined: 19 Jul 2008, 23:03
Noob?: Yes

Re: Items Transfer (scratch)

#4 Post by oldjay »

@ezza,

Thank's for your support.
When I wrote:
The recieve bot open the storage and my serve doesn't support this function.
The sender bot try to deal, but the recieve bot not respond...
I try to say that the recieve bot open directly the storage and the server doesn't allow deal process in storage status.
Like your macro transfer.
A. For the server that allow the deal process in storage status
B. For the server that wont allowed to use deal in storage status (My problem).

I'll try to use your macro, but my "lag server" is too high...=/
That's why I need to use plugins.
Now I want to learn how modify the plugin to enable for my server type.

Big hugh
Oldjay
Have a nice botday!!

mafuang
Noob
Noob
Posts: 2
Joined: 22 Jan 2010, 03:19
Noob?: Yes

Re: Items Transfer (scratch)

#5 Post by mafuang »

can this work on zeny too? if it can, can anyone help me?

paulodemoc
Noob
Noob
Posts: 7
Joined: 15 Jul 2011, 07:47
Noob?: Yes

Re: Items Transfer (scratch)

#6 Post by paulodemoc »

was anyone able to modify ezza's macro to servers that doesnt allow trade with opened storage?
I am a lil bit lost here :S

Post Reply