1. di config.txt tambahkan
tradeAuto 12. ubah di config.txt
dealAuto 03. buka notepad baru simpan, dengan nama autotrade.txt di folder control, isi:
# [item name] [price]
Gladius [3] 1000000
-----------------plugin-----------------------
package autoTrade;
#ported from messykorexp by Joseph
#original code by systeman
use strict;
use Plugins;
use Globals;
use Log qw(message warning error debug);
use AI;
use Misc;
use Network::Send;
use Utils;
Plugins::register('autoTrade', 'automated chat room dealing', \&Unload);
my $hook1 = Plugins::addHook('AI_pre', \&call);
my $hook2 = Plugins::addHook('parseMsg/pre', \&packet);
# load table file
our %trade_lut;
my $file = "autotrade.txt";
#my $cfID = Settings::addConfigFile($file, \%trade_lut, \&FileParsers:arseDataFile_lc);
my $cfID = Settings::addControlFile($file, loader => [\&FileParsers:arseDataFile_lc, \%trade_lut]);
#Settings::load($cfID);
undef $file;
sub Unload {
\tPlugins::delHook('AI_pre', $hook1);
\tPlugins::delHook('parseMsg/pre', $hook2);
\tSettings::removeFile($cfID);
}
my $dealTrade;
my $dealFinalize;
my $tradeDealAddItem;
my $itemAddTimeout;
# TIMEOUTS: you can change these if you want
# time to wait for them to add items before cancelling?
my $itemWaitTime = 12;
# time to wait before accepting deal request?
my $dealAcceptTime = 2;
# time to wait before adding zeny once they finalize their item choices?
my $zenyAddDelay = 3;
sub packet {
\tmy $hookName = shift;
\tmy $args = shift;
\tmy $switch = $args->{switch};
\tmy $msg = $args->{msg};
\tif ($switch eq "00E9") {
\t\tmy $amount = unpack("L1", substr($msg, 2,4));
\t\tmy $ID = unpack("S1", substr($msg, 6,2));
\t\tif ($ID > 0) {
\t\t\t# they added an item, so reset the timeout
\t\t\t$tradeDealAddItem = 1;
\t\t}
\t}
\tif ($switch eq "01F4") {
\t\t#deal request, wait before accepting
\t\t$itemAddTimeout = time;
\t}
\tif ($switch eq "00E5" || $switch eq "01F4") {
\t\t#deal request, wait before accepting
\t\t$itemAddTimeout = time;
\t}
\tif ($switch eq "00EC") {
\t\tmy $type = unpack("C1", substr($msg, 2, 1));
\t\tif ($type == 1) {
\t\t\t#they finalize their item selections
\t\t\t$itemAddTimeout = time;
\t\t}
\t}
}
sub call {
\tAUTOTRADE: {
\t\tif (AI::is("","tradeAuto", "deal") && $config{tradeAuto} && $char->{skills}{NV_BASIC}{lv} > 4) {
\t\t\tif (AI::action ne "tradeAuto" && AI::action ne "deal" && $::currentChatRoom ne "") {
\t\t\t\tmessage "Begin auto-trade mode.
", "autoTrade";
\t\t\t\tif ($config{dealAuto}) {
\t\t\t\t\t$config{dealAuto} = 0;
\t\t\t\t\tMisc::configModify("dealAuto", $config{dealAuto});
\t\t\t\t}
\t\t\t\tAI::queue("tradeAuto");
\t\t\t}
\t\t\tlast AUTOTRADE if !AI::is("tradeAuto","deal");
\t\t\tif (Utils::timeOut($itemAddTimeout,$dealAcceptTime) && $::incomingDeal{name} && !$::currentDeal{name}) {
\t\t\t\t$messageSender->sendDealAccept();
\t\t\t\tundef $dealFinalize;
\t\t\t\tundef $dealTrade;
\t\t\t\t$itemAddTimeout = time;
\t\t\t\tmessage "Sent deal accept, begin trading
", "autoTrade";
\t\t\t}
\t\t\tlast AUTOTRADE if (!$::currentDeal{name});
\t\t\tif (!Utils::timeOut($itemAddTimeout,$itemWaitTime) && $tradeDealAddItem) {
\t\t\t\t$itemAddTimeout = time;
\t\t\t\tundef $tradeDealAddItem;
\t\t\t}
\t\t\tif (($::currentDeal{other_finalize} && Utils::timeOut($itemAddTimeout,$zenyAddDelay)) || Utils::timeOut($itemAddTimeout,$itemWaitTime)) {
\t\t\t\tif ($::currentDeal{other} eq ()) {
\t\t\t\t\tmessage "Other person didn't add any items, cancelling...
", "autoTrade";
\t\t\t\t\t$messageSender->sendCurrentDealCancel();
\t\t\t\t\t$itemAddTimeout = time;
\t\t\t\t} elsif (!$dealFinalize) {
\t\t\t\t\tmy $sumvalue;
\t\t\t\t\tmy @currentDealOther;
\t\t\t\t\tforeach (keys %{$::currentDeal{other}}) {
\t\t\t\t\t\tpush @currentDealOther, $_;
\t\t\t\t\t}
\t\t\t\t\tmy $max = @currentDealOther;
\t\t\t\t\tfor (my $i = 0;$i < $max;$i++) {
\t\t\t\t\t\tmy $found = 0;
\t\t\t\t\t\tmy $ID = $currentDealOther[$i];
\t\t\t\t\t\tmy $name = lc main::itemName($::currentDeal{other}{$ID});
\t\t\t\t\t\tif (defined $trade_lut{$name}) {
\t\t\t\t\t\t\tmessage "Add ".$trade_lut{$name}."z x $::currentDeal{other}{$ID}{amount} to deal
", "autoTrade";
\t\t\t\t\t\t\t$sumvalue += ($::currentDeal{other}{$ID}{amount} * $trade_lut{$name});
\t\t\t\t\t\t} else {
\t\t\t\t\t\t\tmessage "Other person added item which is not in buy list, cancelling...
", "autoTrade";
\t\t\t\t\t\t\t$messageSender->sendCurrentDealCancel();
\t\t\t\t\t\t\tlast AUTOTRADE;
\t\t\t\t\t\t}
\t\t\t\t\t}
\t\t\t\t\tmessage "Trading $sumvalue zeny and confirming
", "autoTrade";
\t\t\t\t\t$messageSender->sendDealAddItem(0, $sumvalue);
\t\t\t\t\tsleep(0.5);
\t\t\t\t\t$messageSender->sendDealFinalize();
\t\t\t\t\t$dealFinalize = 1;
\t\t\t\t\t$itemAddTimeout = time;
\t\t\t\t}
\t\t\t}
\t\t\tif ($::currentDeal{you_finalize} && Utils::timeOut($itemAddTimeout,$itemWaitTime)) {
\t\t\t\tmessage "Other person didn't accept the final trade, cancelling...
", "autoTrade";
\t\t\t\t$messageSender->sendCurrentDealCancel();
\t\t\t\t$itemAddTimeout = time;
\t\t\t}
\t\t\tif (!$dealTrade && $::currentDeal{you_finalize} && $::currentDeal{other_finalize}) {
\t\t\t\tmessage "Accepting final trade
", "autoTrade";
\t\t\t\t$messageSender->sendDealTrade();
\t\t\t\t$dealTrade = 1;
\t\t\t}
\t\t}
\t}
}
return 1;
No comments:
Post a Comment