Check cast area

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

Check cast area

#1 Post by thedrops »

(Posting in the right area now)

So this is my first plugin. Basically what I'm trying to achieve is a check to see how many enemies are around the current attack target.
The check is called mobsInRange and is added like this:

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
}
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 based it off the checkSelfCondition plugin but I'm still new to this so I don't know if I went about it the correct way.

The check /works/ for the most part, but the issue is that sometimes when there is less than 5 it won't cast, but othertimes it will. It's basically random whether or not the condition works the way I want it to.

AAAAAAAANYWAYSSS here is the plugin as I currently have it. Would greatly appreciate any help. ;]
(Forgive my variable names)

Code: Select all

package checkSelfCondition;

#
# This plugin is licensed under the GNU GPL
# Copyright 2005 by kaliwanagan
# -------------------------------------------------- 
#
# This plugin hooks into checkSelfCondition in Misc.pm
# Instead of doing a return, set $args->{return} to the supposed return value.

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('checkSelfCondition', 'enable custom conditions', \&onUnload);
my $hooks = Plugins::addHooks(
	['checkSelfCondition', \&mobsInRange, undef],
);

message "Well it loaded at least.\n", "success";

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

sub onReload {
    &onUnload;
}

sub mobsInRange {
	my ($hookName, $args) = @_;
	my $prefix = $args->{prefix};
	my @agMonsters;
	my $currentTarget;
		
	return if ($config{$prefix."_mobsInRange"} eq '');
	return 0 if (AI::action ne 'attack');
	
	my %bullshit;
	($bullshit{'dist_'}, $bullshit{'mon_count'}) = split / *, */, $config{$prefix."_mobsInRange"};
	#if (AI::action eq 'attack') {
		my $args2 = AI::args;
		$currentTarget = $monsters{$args2->{ID}};
		my $monsterpos = main::calcPosition($monsters{$args2->{ID}});
		
		foreach my $monster (@{$monstersList->getItems()}) {
			my $ID2 = $monster->{ID};
			next if $ID2 eq $currentTarget;
			my $monstersLocation = main::calcPosition($monsters{$ID2});
			if (distance($monstersLocation,$monsterpos) <= $bullshit{dist_}) {
				#my $pancakes = distance($monstersLocation,$monsterpos);
				push @agMonsters, $ID2;
			}
		}
		
		my $agMonLength = $#agMonsters + 1;		
		undef %bullshit;
		if($agMonLength >= $bullshit{mon_count}){
			$args->{return} = 1;
			#return 1;
		} else {
			$args->{return} = 0;
			#return 0;
		}
	#}
}

return 1;