Showing posts with label plugin. Show all posts
Showing posts with label plugin. Show all posts

Monday, November 10, 2014

Plugin Wait4Party

di config.txt master tambahkan: follow_wait 1

catatan: jika sudah menggunakan macro, jangan gunakan ini

package waitParty;


use Plugins;
use Globals;
use Log qw(message error warning debug);


our $findParty;
our $temp;


Plugins::register('waitParty', 'Wait and come back for party', \&unload, \&unload);


my $hooks = Plugins::addHooks(   ['actor_player_add', \&waitForOthers, undef],
            ['actor_player_remove', \&waitForOthers, undef],
            ['party_share', \&waitForOthers, undef],
            ['party_move', \&waitForOthers, undef],
            ['AI_pre', \&waitForOthers, undef],
            ['actor_action_sit', \&waitForOthers, undef],
            ['actor_action_stand', \&waitForOthers, undef]);


sub unload {
   Plugins::delHooks($hooks);
}


sub waitForOthers {
   return unless $config{'follow_wait'};
   return unless defined @partyUsersID;


   #return if bot isn't at lockmap
   return if (($config{'follow_wait_inLockOnly'} > 0) && ($field{name} ne $config{lockMap}));


   my $actor;
   foreach (@partyUsersID) {
      next if $_ eq $accountID;
      next if $_ eq "";
      $actor = $playersList->getByID($_);


      if(!$actor && $char->{'party'}{'users'}{$_}{'online'}) {
         my %party;
         $party{x} = $char->{party}{users}{$_}{pos}{x};
         $party{y} = $char->{party}{users}{$_}{pos}{y};
         ($party{map}) = $char->{party}{users}{$_}{map} =~ /([\s\S]*)\.gat/;


         if ($party{map} ne $field{name} || $party{x} == 0 || $party{y} == 0) {
            delete $party{x};
            delete $party{y};
         }


         return unless ($party{map} ne $field{name} || exists $party{x});


         if ((exists $ai_v{party} && AI::distance(\%party, $ai_v{party}) > 15)
            || $party{map} != $ai_v{party}{map}
            || (AI::timeOut($ai_v{party}{time}, 15) && AI::distance(\%party, $char->{pos_to}) > $config{followDistanceMax})) {


            $ai_v{party}{x} = $party{x};
            $ai_v{party}{y} = $party{y};
            $ai_v{party}{map} = $party{map};
            $ai_v{party}{time} = time;


            warning "Party is far way.
", "waitParty";


            if ($ai_v{party}{map} ne $field{name}) {
               message "Searching party: $ai_v{party}{map}
", , "follow";
            } elsif (AI::distance(\%party, $char->{pos_to}) > $config{followDistanceMax} ) {
               message "Searching party: $ai_v{party}{map} ($ai_v{party}{x},$ai_v{party}{y})
", "follow";
            } else {
               return;
            }
            AI::clear("move", "route", "mapRoute");
            AI::ai_route($ai_v{party}{map}, $ai_v{party}{x}, $ai_v{party}{y}, distFromGoal => $config{followDistanceMin});
            my $followIndex = AI::findAction("follow");
            if (defined $followIndex) {
               $ai_seq_args[$followIndex]{ai_follow_lost_end}{timeout} = $timeout{ai_follow_lost_end}{timeout};
            }
         }
         $findParty = 1;
         return;
      } elsif ($findParty && ($actor = $playersList->getByID($_))) {
         warning "Party Found.
", "waitParty";
         $findParty = 0;
      } elsif ($findParty) {
         warning "Party is offline.
", "waitParty";
         $findParty = 0;
         return;
      }
   }
}
1;

Plugin HideConsole

1. di config.txt tambahkan: HideConsole 1
2. jika mau melihat bot: matikan bot dari task manager, nyalakan lagi

# =======================
# hideConsole v1.0
# =======================
# by hakore (hakore@users.sourceforge.net)
# see documentation at: http://forums.openkore.com/viewtopic.php?p=103437


package hideConsole;
use Globals qw(%config $interface);
use Log qw(message error);


Plugins::register('hideConsole', 'hide your console', \&onUnload);
my $hooks = Plugins::addHooks(
['initialized', \&autoHideConsole, undef],
['Command_post', \&cmdhideConsole, undef]
);


sub onUnload {
Plugins::delHooks($hooks);
}


sub autoHideConsole {
if ($config{hideConsole} > 0) {
hideConsole();
}
}


sub cmdhideConsole {
my (undef, $args) = @_;
my ($cmd) = split(' ', $args->{input}, 2);
if ($cmd eq "hideconsole") {
message("Console hidden
");


hideConsole();
$args->{return} = 1;
}
}


sub hideConsole {
eval 'use Win32::Console;Win32::Console->new(STD_OUTPUT_HANDLE)->Free();';
}


return 1;

Plugin autotrade.pl

1. di config.txt tambahkan
tradeAuto 1
2. ubah di config.txt
dealAuto 0
3. 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;