mobsInRange

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
thedrops
Noob
Noob
Posts: 6
Joined: 18 May 2012, 02:22
Noob?: No

mobsInRange

#1 Post by thedrops »

Edit:
Alrighty! So I managed to get it to work!

mobsInRange is my very first plugin. It adds a check to skill blocks in config.txt called mobsInRange.

Code: Select all

attackSkillSlot Storm Gust {
	lvl 10
	dist 7
	sp > 10
	onAction attack
	timeout 10
	notInTown 1
	maxAttempts 3
	mobsInRange 8,5 <<this guy right here
}
What it does is check to see how many enemies are in a radius around the current target.
8 represents the distance to the target's position, 5 is the number of mobs needed to pass.

The check gets the position of the current target, then looks at every other monster on the screen and checks the distance to the target's position. If the number of targets within distance of 8 is >= 5, then it casts the spell.

I used the checkSelfCondition plugin by kaliwanagan and the monsterDB plugin by Damokles to base the plugin off.

AAAAAAAANYWAYSSS here is the plugin as I currently have it. I'm sure it's full of redundancies and room for improvement. ;]
(Forgive my variable names)

Code: Select all

############################ 
# mobsInRange plugin for OpenKore by theDrops(2014) 
# 
# This software is open source, licensed under the GNU General Public Liscense
# Special thanks to kaliwanagan and Damokles for reference
# -------------------------------------------------- 
#
# This plugin hooks into checkMonsterCondition in Misc.pm
# It get's your current attack target, searches for monsters within a certain distance, then returns
# If the number of monsters within that distance are >= to the number specified, the skill block will cast
#
# Use:
# Add 'target_mobsInRange [distance],[# of enemies] to attackSkillSlot
# ie target_mobsInRange 8,6
# Will cast when there are 6+ monsters within 8 distance of the target
############################ 


package mobsInRange;

use strict;
use Time::HiRes qw(time usleep);
use IO::Socket;
use Text::ParseWords;
use Config;
eval "no utf8;";
use bytes;

use Globals;
use Modules;
use Settings;
use Log qw(message warning error debug);
use FileParsers;
use Interface;
use Network::Receive;
use Network::Send;
use Commands;
use Misc;
use Plugins;
use Utils;
use ChatQueue;

use AI;
use Actor;

Plugins::register('condition: mobsInRange', 'extends skill condition to check for mobs in range', \&onUnload); 
my $hooks = Plugins::addHooks( 
	['checkMonsterCondition', \&checkInRange, undef], 
);

message "Check Mob Range successfully loaded.\n", "success";

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

sub onReload {
    &onUnload;
}

sub checkInRange { 
    my (undef,$args) = @_;
	my @agMonsters;
	my %rangeArgs;
	my $currentTarget;
		
	return 0 if !$args->{monster} || $args->{monster}->{nameID} eq ''; 
	
	if ($config{$args->{prefix} . '_mobsInRange'}){
		($rangeArgs{'dist_'}, $rangeArgs{'mon_count'}) = split / *, */, $config{$args->{prefix} . '_mobsInRange'};

		$currentTarget = $args->{monster};
		my $monsterpos = calcPosition($args->{monster});
		my $monsterrr = $monstersList->getByID($args->{monster}->{ID});
		
		foreach my $monster (@{$monstersList->getItems()}) {
			my $ID2 = $monster->{ID};
			next if $ID2 eq $currentTarget;
			my $monstersLocation =calcPosition($monsters{$ID2});
			if (distance($monstersLocation,$monsterpos) <= $rangeArgs{dist_}) {
				my $boobs = distance($monstersLocation,$monsterpos);
				push @agMonsters, $ID2;
			}
		}
		
		my $agMonLength = $#agMonsters + 1;
		if($agMonLength < $rangeArgs{mon_count}){
			undef %rangeArgs;
			$args->{return} = 0;
		}
	}
	return 1; 
} 

return 1;