Monday, April 13, 2009

Setting For Auto-Trade

Most people use Auto-Trade to buy some items they need or want in short time..

1. Make a notepad named autotrade.pl and copy paste this and then put it in plugins folder :

  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::parseDataFile_lc);
  my $cfID = Settings::addControlFile($file, loader => [\&FileParsers::parseDataFile_lc, \%trade_lut]);
  #Settings::load($cfID);
  undef $file;

  sub Unload {
  Plugins::delHook('AI_pre', $hook1);
  Plugins::delHook('parseMsg/pre', $hook2);
  Settings::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 = 20;
  # 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 {
  my $hookName = shift;
  my $args = shift;
  my $switch = $args->{switch};
  my $msg = $args->{msg};

  if ($switch eq "00E9?") {
  my $amount = unpack("L1?", substr($msg, 2,4));
  my $ID = unpack("S1?", substr($msg, 6,2));
  if ($ID > 0) {
  # they added an item, so reset the timeout
  $tradeDealAddItem = 1;
  }
  }
  if ($switch eq "01F4?") {
  #deal request, wait before accepting
  $itemAddTimeout = time;
  }
  if ($switch eq "00E5?" || $switch eq "01F4?") {
  #deal request, wait before accepting
  $itemAddTimeout = time;
  }
  if ($switch eq "00EC") {
  my $type = unpack("C1?", substr($msg, 2, 1));
  if ($type == 1) {
  #they finalize their item selections
  $itemAddTimeout = time;
  }
  }
  }

  sub call {
  AUTOTRADE: {
  if (AI::is("","tradeAuto", "deal") && $config{tradeAuto} && $char->{skills}{NV_BASIC}{lv} > 4) {
  if (AI::action ne "tradeAuto" && AI::action ne "deal" && $::currentChatRoom ne "") {
  message "Begin auto-trade mode.\n", "autoTrade";
  if ($config{dealAuto}) {
  $config{dealAuto} = 0;
  Misc::configModify("dealAuto", $config{dealAuto});
  }
  AI::queue("tradeAuto");
  }

  last AUTOTRADE if !AI::is("tradeAuto","deal");

  if (Utils::timeOut($itemAddTimeout,$dealAcceptTime) && $::incomingDeal{name} && !$::currentDeal{name}) {
  $messageSender->sendDealAccept();
  undef $dealFinalize;
  undef $dealTrade;
  $itemAddTimeout = time;
  message "Sent deal accept, begin trading\n", "autoTrade";
  }
  last AUTOTRADE if (!$::currentDeal{name});
  if (!Utils::timeOut($itemAddTimeout,$itemWaitTime) && $tradeDealAddItem) {
  $itemAddTimeout = time;
  undef $tradeDealAddItem;
  }
  if (($::currentDeal{other_finalize} && Utils::timeOut($itemAddTimeout,$zenyAddDelay)) || Utils::timeOut($itemAddTimeout,$itemWaitTime)) {
  if ($::currentDeal{other} eq ()) {
  message "Other person didn’t add any items, cancelling…\n", "autoTrade";
  $messageSender->sendCurrentDealCancel();
  $itemAddTimeout = time;
  } elsif (!$dealFinalize) {
  my $sumvalue;

  my @currentDealOther;
  foreach (keys %{$::currentDeal{other}}) {
  push @currentDealOther, $_;
  }
  my $max = @currentDealOther;
  for (my $i = 0;$i < $max;$i++) {   my $found = 0;   my $ID = $currentDealOther[$i];   my $name = lc main::itemName($::currentDeal{other}{$ID});   if (defined $trade_lut{$name}) {   message "Add ".$trade_lut{$name}."z x $::currentDeal{other}{$ID}{amount} to deal\n", "autoTrade";   $sumvalue += ($::currentDeal{other}{$ID}{amount} * $trade_lut{$name});   } else {   message "Other person added item which is not in buy list, cancelling…\n", "autoTrade";   $messageSender->sendCurrentDealCancel();
  last AUTOTRADE;
  }
  }
  message "Trading $sumvalue zeny and confirming\n", "autoTrade";
  $messageSender->sendDealAddItem(0, $sumvalue);
  sleep(0.5);
  $messageSender->sendDealFinalize();
  $dealFinalize = 1;
  $itemAddTimeout = time;
  }

  }
  if ($::currentDeal{you_finalize} && Utils::timeOut($itemAddTimeout,$itemWaitTime)) {
  message "Other person didn’t accept the final trade, cancelling…\n", "autoTrade";
  $messageSender->sendCurrentDealCancel();
  $itemAddTimeout = time;
  }
  if (!$dealTrade && $::currentDeal{you_finalize} && $::currentDeal{other_finalize}) {
  message "Accepting final trade\n", "autoTrade";
  $messageSender->sendDealTrade();
  $dealTrade = 1;
  }
  }
  }
  }

  return 1;

2.  open your config.txt and put tradeAuto to 1 and deal auto to 0, so it'll looked like :

dealAuto 0
tradeAuto 1
dealAuto_names
partyAuto 1
partyAutoShare 1
guildAutoDeny 1

3. create another notepad in your controls folder named autotrade.txt , for example :

# [item name] [price]

Crunch Toast 2500000

2. Open your control folder and Put These into your macros.txt :

automacro openchatroom {
map payon
run-once 1
delay 10
call openchat
}

macro openchat {
do chat create "B: Crunch Toast 2,5 million" 2 0 1111
}

Note : its work properly and very well.. i tried it already in OK 2.0.6 , oh yeah almost forgot. . make sure all your notepads save as all files...



2 comments:

  1. hi, this macros works for autotrade buying,
    how do i make it to autotrade selling mode?

    ReplyDelete
  2. how about i want to sell my equip.
    example. i have +10 composite bow [4] and i want to sell using openkore, what config i need..

    ReplyDelete