I need a bit of help perfecting this hasla farm code for an archer. I want it to attack any monster in 28 meter distance from it as soon as it appears. Currently it attacks around 50% of the monsters that appear and it also doesn't attack the monsters that my party members start attacking first. Can someone please tell me what to change to fix this? It's a modification of the plugin Here , all made by Karls.
Also this widget modification is needed for it to work correctly. The looting works perfectly, I just need it to attack monsters around me consistently.
Also this widget modification is needed for it to work correctly. The looting works perfectly, I just need it to attack monsters around me consistently.
Code:
using System;
using System.Windows.Forms;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using ArcheBuddy.Bot.Classes;
namespace Hasla
{
public class Hasla : Core
{
// EDIT THIS - the plugin's settings
const double _COMBAT_RANGE = 29; // how close bot should move to a mob before using skills
public static string GetPluginAuthor()
{
return "Karls";
}
public static string GetPluginVersion()
{
return "1.0";
}
public static string GetPluginDescription()
{
return "HaslaGrinder: Assisting you for Hasla Weapon Grind";
}
List<Creature> team;
public Creature GetBestNearestMob(Zone zone)
{
try
{
foreach (var obj in getCreatures())
{
if (obj.type == BotTypes.Npc && isAttackable(obj) && (obj.firstHitter == null || obj.firstHitter == me || team.Contains(obj.firstHitter))
&& isAlive(obj) && (zone.ObjInZone(obj) || me.dist(obj) < _COMBAT_RANGE)
&& (hpp(obj) == 100 || team.Contains(obj.aggroTarget)))
{
return obj;
}
}
}
catch { }
return null;
}
public void UseSkillAndWait(string skillName, bool selfTarget = false)
{
if (getSkill(skillName) == null)
return;
while (me.isCasting || me.isGlobalCooldown)
Thread.Sleep(50);
if (skillCooldown(skillName) > 0)
return;
if (!UseSkill(skillName, true, selfTarget))
{
if (me.target != null && GetLastError() == LastError.NoLineOfSight)
{
if (dist(me.target) <= 5)
ComeTo(me.target, 2);
else if (dist(me.target) <= 10)
ComeTo(me.target, 3);
else if (dist(me.target) < 20)
ComeTo(me.target, 8);
else
ComeTo(me.target, 8);
}
}
while (me.isCasting || me.isGlobalCooldown)
Thread.Sleep(50);
}
public void PlayDead()
{
while (me.isCasting || me.isGlobalCooldown)
Thread.Sleep(50);
UseSkill("Play Dead", false, true);
Thread.Sleep(2000);
while (getAggroMobs().Count == 0 && (mpp() < 95 || hpp() < 95))
Thread.Sleep(100);
MoveForward(false);
Thread.Sleep(250);
MoveForward(false);
Log("Regen done");
}
public void LootThread()
{
try
{
BlockClientDice(true);
while (true)
{
foreach (var item in me.getDiceItems())
{
bool doRoll = false;
// Always roll on purses and random drops
if (item.name.EndsWith("Coinpurse") || item.name.StartsWith("Unidentified") || item.id == 29207)
doRoll = true;
else if(item.id == 26056)
doRoll = GetGroupStatus("Conviction (Staff)");
else if (item.id == 26055)
doRoll = GetGroupStatus("Courage (Bow)");
else if (item.id == 35525)
doRoll = GetGroupStatus("Compassion (Heal)");
else if (item.id == 26057)
doRoll = GetGroupStatus("Fortitude (Shield)");
else if (item.id == 26053)
doRoll = GetGroupStatus("Honor (1H)");
else if (item.id == 26054)
doRoll = GetGroupStatus("Loyalty (2H)");
else if (item.id == 26058)
doRoll = GetGroupStatus("Sacrifice (Lute)");
item.Dice(doRoll);
if(doRoll)
Log("Rolling on : " + item.name);
else
Log("Passing on : " + item.name);
Thread.Sleep(5000);
}
Thread.Sleep(10000);
}
}
finally
{
BlockClientDice(false);
}
}
public void RefreshTeam()
{
team = new List<Creature>();
foreach (var t in getPartyMembers())
team.Add(t.obj);
}
public void PluginRun()
{
DelAllGroupStatus();
new Task(() => { LootThread(); }).Start();
RoundZone zone = new RoundZone(me.X, me.Y, 0);
SetGroupStatus("Farm mobs ON", false);
SetGroupStatus("Courage (Bow)", false);
SetGroupStatus("Compassion (Heal)", false);
SetGroupStatus("Conviction (Staff)", false);
SetGroupStatus("Fortitude (Shield)", false);
SetGroupStatus("Honor (1H)", false);
SetGroupStatus("Loyalty (2H)", false);
SetGroupStatus("Sacrifice (Lute)", false);
Log("Starting Hasla Assistant");
Creature bestMob = null;
RefreshTeam();
while (true)
{
if (GetGroupStatus("Farm mobs ON") && isAlive())
{
if (GetGroupStatus("Farm mobs ON"))
{
if (getAggroMobs().Count == 0)
{
// EDIT THIS - Change to your buffs or delete it
// rebuff
{
PlayDead();
}
}
if (((mpp() > 40 && hpp() > 75) || getAggroMobs().Count > 0))
{
bestMob = GetBestNearestMob(zone);
}
if (bestMob != null)
{
try
{
while (bestMob != null && isAlive(bestMob) && isExists(bestMob) && GetGroupStatus("Farm mobs ON") && isAlive())
{
if (bestMob.firstHitter != null && bestMob.firstHitter != me && !team.Contains(bestMob.firstHitter))
{
bestMob = null;
break;
}
if (bestMob.firstHitter == null && getAggroMobs().Count > 0 && bestMob != GetBestNearestMob(zone))
bestMob = GetBestNearestMob(zone);
if (me.target != bestMob)
SetTarget(bestMob);
if (angle(bestMob, me) > 45 && angle(bestMob, me) < 315)
TurnDirectly(bestMob);
// EDIT THIS - Put your in-combat healing/... here
var distToMob = me.dist(bestMob);
if (isAlive(bestMob))
{
if (distToMob > _COMBAT_RANGE)
{
ComeTo(me.target, _COMBAT_RANGE - 1);
}
else
{
// EDIT THIS - Change it to your skills with your trigger conditions
// instant skill to tag mobs
if (skillCooldown("Endless Arrows") == 0 && hpp(me.target) == 100)
UseSkillAndWait("Endless Arrows");
// fast spam to deal damage otherwise
else
{
UseSkillAndWait("Endless Arrows");
UseSkillAndWait("Endless Arrows");
UseSkillAndWait("Endless Arrows");
}
}
}
Thread.Sleep(5);
}
bestMob = null;
RefreshTeam();
}
catch { }
}
}
}
Thread.Sleep(10);
}
}
}
}