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;

No comments:

Post a Comment