AntiMob plugin

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
kingkevz
Human
Human
Posts: 25
Joined: 04 Apr 2008, 22:55

AntiMob plugin

#1 Post by kingkevz »

Code: Select all

#-------------------------------------------------------------------------------
# AntiMob 
# *  for servers that have their teleport skill disabled (pRO Valkyrie/Valhala)
# coded by RJ (vmkjwan)
#
# This source code is licensed under the
# GNU General Public License, Version 2.
# See http://www.gnu.org/licenses/gpl.html
# -----------------------------------------------------------------------------
# Change Log:
# v0.1 (05/17/08) - Initial
# v0.2 (05/18/08) - Added computation based on HP:Aggro ratio
# v0.3 (06/04/08) - Added Life Insurance option
# -----------------------------------------------------------------------------
# How to use this plugin:
#
# in control\config.txt, put:
#
# antiMob (1|0)            
# antiMob_useInsu (1|0)   
#
#------------------------------------------------------------------------------

package antiMob;

use strict;
use Plugins;
use Globals;
use Utils;
use Misc;
use Settings;

Plugins::register("antiMob", "Relog when getting Mobbed", \&unload);

my $hooks = Plugins::addHooks(
   ['packet_attack', \&onAttack, undef]
);

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

# default relogTime
my $relogTime = 60;

sub onAttack {
   return unless ($config{'antiMob'});
   my ($self, $args) = @_;
   my $aggros = scalar AI::ai_getAggressives();

   if ($args->{'targetID'} eq $accountID) {
      return if($args->{'dmg'} == 0);
      my $hp = $char->hp_percent();

      # I havent really tweaked the HP:Aggro ratio.. But it did saved me a lot of times
      if( $hp < 50 && ((ceil($hp/10)-1) >= $aggros) ) {
         Log::message(sprintf("Too many aggressives. HP: %s Aggro: %s\n", $hp, $aggros));

         # Should we use insu?
         if($config{'antiMob_useInsu'}) {
            # Check if theres an active Life Insurance status
            if(!$char->{statuses}{'Life Insurance'}) {
               my $insu = Actor::Item::get('Life Insurance', undef, 1);
               # Check if you really have the Life Insurance item
               if(defined $insu) {
                  Log::message("Using Life Insurance..\n");
                  $insu->use();
                  return;
               # You dont have it.. Relog
               } else {
                  Log::message("We dont have any Life Insurance item left.\n");
               }

            } else {         
               Log::message("Good thing we still have Life Insurance status.\n");
               return;
            }
         }
         Log::message("Relogging..\n");
         relog($relogTime);
      }
   }

}

sub ceil {
   my $r = shift;
   my $frac = $r - int($r);
   if($frac<=0) {
      return int($r);
   } else {
      return 1+int($r);
   }
}

1;

This plugin will either use Insurance or Relog you for 60 seconds if ever get mobbed.

"Mob" on this plugin means, you have less than 50% HP and have (ceil(HP/10)-1) monsters attacking you. (e.g. 40% HP and 3 aggressives will trigger the plugin)