avoid skill

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
bakamro
Noob
Noob
Posts: 10
Joined: 19 Dec 2010, 16:46
Noob?: Yes

avoid skill

#1 Post by bakamro »

can any1 help me with this plugin ? i got it from another forum and it is too advanced for me. It says error on line 176 when i tried put to avoid hammer fall

Code: Select all

# avoidSkill by Joseph
# original code from MessyKoreXP
# licensed under GPL

package avoidSkill;

use strict;
#use warnings;

use Time::HiRes qw(time);

use Globals;
use Utils;
use Misc;
use Network::Send;
use Log qw(debug message warning error);
use Skill;
use encoding 'utf8';

Plugins::register('avoidSkill', 'React to skills.', \&onUnload);

my $hooks = Plugins::addHooks(
            ['is_casting', \&avoidSkill, undef],
            ['packet_skilluse', \&avoidSkill, undef]
);

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

sub avoidSkill {
   my (undef, $args) = @_;
   my $sourceID = $args->{sourceID};
   my $targetID = $args->{targetID};
   my $skillID = $args->{skillID};
   my $x = $args->{x};
   my $y = $args->{y};

   my $skill = new Skill(idn => $skillID);
   $skill = $skill->getName();

   my $source = Actor::get($sourceID);

   debug "checking if we should avoid $skill from $source\n";

   for (my $i = 0; exists $config{"avoidSkill_$i"}; $i++) {
      next if (!$config{"avoidSkill_$i"});

      if (existsInList($config{"avoidSkill_$i"}, $skill)) {
         # if source is specified, make sure type is correct
         next if ($config{"avoidSkill_$i"."_source"} && $config{"avoidSkill_$i"."_source"} ne $source->{actorType});

         debug "checking avoid radius on $skill\n";

         # check if we are inside the skill area of effect
         my $inRange;
         my ($left,$right,$top,$bottom);
         if ($x != 0 || $y != 0) {
            $left = $x - $config{"avoidSkill_$i"."_radius"};
            $right = $x + $config{"avoidSkill_$i"."_radius"};
            $top = $y - $config{"avoidSkill_$i"."_radius"};
            $bottom = $y + $config{"avoidSkill_$i"."_radius"};
            $inRange = 1 if ($left <= $char->{pos_to}{x} && $right >= $char->{pos_to}{x} && $top <= $char->{pos_to}{y} && $bottom >= $char->{pos_to}{y});

         } elsif ($targetID eq $accountID) {
            $inRange = 1;
         }

         if ($inRange) {
            if ($char->{sitting}) {
               main::stand();
            }

            if ($config{"avoidSkill_$i"."_method"} == 0) {
               my $found = 1;
               my $count = 0;
               my %move;
               do {
                  ($move{x}, $move{y}) = getRandPosition($config{"avoidSkill_${i}_step"});
                  $count++;
                  if ($count > 100) {
                     $found = 0;
                     last;
                  }
               } while ($left <= $move{x} && $right >= $move{x} && $top <= $move{y} && $bottom >= $move{y});

               if ($found) {
                  stopAttack();
                  sendMove(\$remote_socket, $move{x}, $move{y});
                  message "Avoid skill $skill, random move to $move{x}, $move{y}.\n";
               }

            } elsif ($config{"avoidSkill_$i"."_method"} == 1) {
               my $dx = $x - $char->{pos_to}{x};
               my $dy = $y - $char->{pos_to}{y};
               my %random;
               my %move;

               my $found = 1;
               my $count = 0;
               do {
                  $random{x} = int(rand($config{"avoidSkill_$i"."_step"})) + 1;
                  $random{y} = int(rand($config{"avoidSkill_$i"."_step"})) + 1;

                  if ($dx >= 0) {
                     $move{x} = $char->{pos_to}{x} - $random{x};
                  } else {
                     $move{x} = $char->{pos_to}{x} + $random{x};
                  }

                  if ($dy >= 0) {
                     $move{y} = $char->{pos_to}{y} - $random{y};
                  } else {
                     $move{y} = $char->{pos_to}{y} + $random{y};
                  }

                  $count++;
                  if ($count > 100) {
                     $found = 0;
                     last;
                  }
               } while (!($field->isWalkable($x, $y)));

               if ($found) {
                  stopAttack();
                  sendMove(\$remote_socket, $move{x}, $move{y});
                  message "Avoid skill $skill, move to $move{x}, $move{y}.\n";
               }

            } elsif ($config{"avoidSkill_$i"."_method"} == 2) {
               my %src;
               $src{x} = $source->{pos_to}{x};
               $src{y} = $source->{pos_to}{y};

               my $found = 0;
               my $count = 0;
               my ($ex_left, $ex_right, $ex_top, $ex_bottom);
               my ($in_left, $in_right, $in_top, $in_bottom);
               my %move;
               my %nearest;

               do {
                  $ex_left = $src{'x'} - $count;
                  $ex_right = $src{'x'} + $count;
                  $ex_top = $src{'y'} - $count;
                  $ex_bottom = $src{'y'} + $count;

                  $count++;

                  $in_left = $src{'x'} - $count;
                  $in_right = $src{'x'} + $count;
                  $in_top = $src{'y'} - $count;
                  $in_bottom = $src{'y'} + $count;

                  my $nearest_dist = 9999;
                  for ($move{'y'} = $in_top; $move{'y'} <= $in_bottom; $move{'y'}++) {
                     for ($move{'x'} = $in_left; $move{'x'} <= $in_right; $move{'x'}++) {
                        if (($move{'x'} < $ex_left || $move{'x'} > $ex_right) && ($move{'y'} < $ex_top || $move{'y'} > $ex_bottom)) {
                           next if (($left <= $move{'x'} && $right >= $move{'x'} && $top <= $move{'y'} && $bottom >= $move{'y'}) ||
                              !($field->isWalkable($move{x}, $move{y})));

                           my $dist = distance(\%move, \%src);

                           if ($dist < $nearest_dist) {
                              $nearest_dist = $dist;
                              $nearest{'x'} = $move{'x'};
                              $nearest{'y'} = $move{'y'};
                              $found = 1;
                           }
                        }
                     }
                  }
               } while (($count < 100) && (!$found));

               if ($found) {
                  stopAttack();
                  sendMove(\$remote_socket, $nearest{x}, $nearest{y});
                  message "Avoid skill $skill, move to nearest position $nearest{'x'}, $nearest{'y'}.\n";
               }

            } elsif ($config{"avoidSkill_$i"."_method"} == 3) {
               message "Avoid skill $skill, use random teleport.\n";
               main::useTeleport(1);

            } elsif ($config{"avoidSkill_$i"."_method"} == 4) {
               return unless ($source->{actorType} eq 'Monster');
               message "Avoid skill $skill, attack to $source->{name}\n";
               # may not care about portal distance, oh well
               stopAttack();
               main::attack($sourceID);

            } elsif ($config{"avoidSkill_$i"."_method"} == 5 && timeOut($AI::Timeouts::avoidSkill_skill, 3)) {
               return unless ($source->{actorType} eq 'Monster');
               message "Avoid skill $skill, use ".$config{"avoidSkill_$i"."_skill"}." to $source->{name}\n";

               $skill = new Skill(name => $config{"avoidSkill_$i"."_skill"});

               message "Use ".$skill->getHandle." on target\n";

               if (main::ai_getSkillUseType($skill->getHandle)) {
                  my $pos = ($config{"avoidSkill_${i}_isSelfSkill"}) ? $char->{pos_to} : $monsters{$sourceID}{pos_to};
                  main::ai_skillUse(
                     $skill->getHandle,
                     $config{"avoidSkill_$i"."_lvl"},
                     $config{"avoidSkill_$i"."_maxCastTime"},
                     $config{"avoidSkill_$i"."_minCastTime"},
                     $pos->{x},
                     $pos->{y});
               } else {
                  main::ai_skillUse(
                     $skill->getHandle,
                     $config{"avoidSkill_$i"."_lvl"},
                     $config{"avoidSkill_$i"."_maxCastTime"},
                     $config{"avoidSkill_$i"."_minCastTime"},
                     $config{"avoidSkill_${i}_isSelfSkill"} ? $accountID : $sourceID);
               }
               $AI::Timeouts::avoidSkill_skill = time;
            }

         }

         last;
      }
   }
}

sub getRandPosition {
   my $range = shift;
   my $x_pos = shift;
   my $y_pos = shift;
   my $x_rand;
   my $y_rand;
   my $x;
   my $y;

   if ($x_pos eq "" || $y_pos eq "") {
      $x_pos = $char->{'pos_to'}{'x'};
      $y_pos = $char->{'pos_to'}{'y'};
   }

   do {
      $x_rand = int(rand($range)) + 1;
      $y_rand = int(rand($range)) + 1;

      if (int(rand(2))) {
         $x = $x_pos + $x_rand;
      } else {
         $x = $x_pos - $x_rand;
      }

      if (int(rand(2))) {
         $y = $y_pos + $y_rand;
      } else {
         $y = $y_pos - $y_rand;
      }
   } while (!($field->isWalkable($x, $y)));

   my @ret = ($x, $y);
   return @ret;
}

Code: Select all

#avoidSkill skill to avoid here {
#   radius (if this is an area skill, put this radius of it here)
#   source (put Monster or Player here, case sensitive, leave blank for both)
#   method (choose one)
#      0 - Random position outside <avoidSkill_#_radius> by <avoidSkill_#_step>
#      1 - Move to opposite side by <avoidSkill_#_step>
#      2 - Move nearest enemy.
#      3 - Teleport
#      4 - Attack (monsters only)
#      5 - Use skill. (monsters only)
#
#   (options for methods 0-1)
#   step (how far you move, or something)
#
#   (options for method 5)
#   skill (skill to use against monster)
#   lvl (level to use)
#   isSelfSkill (flag)
#   maxCastTime (like normal skill slots)
#   minCastTime (like normal skill slots)
#}


avoidSkill Warp Portal {
   source Player
   radius 0
   method 0
   step 10
}
avoidSkill Hammer Fall {
   source Monster
   method 2
   radius 1
   step 10
}
#incase u want to avoid angelings safetywall#
avoidSkill Safety Wall {
   source Monster
   method 1
   radius 2
   step 10
}
avoidSkill Ice Wall {
   source Player
   method 3
}
avoidSkill Heaven's Drive {
   source Monster
   method 2
   radius 2
   step 10
}
avoidSkill Brandish Spear {
   source Monster
   method 3
}
avoidSkill Fire Bolt, Fire Wall, Water Ball {
   source Monster
   method 4
   radius 15
   step 10
}
avoidSkill Fire Bolt, Fire Wall, Water Ball {
   source Monster
   method 5
   radius 15
   step 10
        skill Provoke
   lvl 1
}