To be honest it kind of seems like an over complicated way to go about it. Typically I just compare the distance between myself and the nearest enemy to enable the Fight loop and that works almost flawlessly since you can specify compass range to fight from which means you arent off running about the place.Quote:
Hey guys!
I need your help / advice on a function of mine...
Is this viable to check the remaining amount of foes in a kill loop?Code:; ~ Description: Returns number of foes which meet certain conditions, given by the parameter ; ~ $HPPercentage = from 0(=0%) to 1(=100%), set the HP in % to return all valid enemies with less than your set % ; ~ $aKilledFoes = start this function if a certain amount of foes are killed (only works in HM) ; ~ $aRange = returns all valid enemies within this range Func GetRemainingFoes($HPPercentage = 1, $aKilledFoes = 0, $aRange = $RANGE_NEARBY) If GetFoesKilled() > $aKilledFoes Then Local $lAgentArray = GetAgentArray(0xDB) Local $lMe = GetAgentById(-2) Local $lFoeCount = 0 For $i = 1 To $lAgentArray[0] ;If $lAgentArray[$i] = 0 Then ContinueLoop ; no Agent If Not GetIsEnemy($lAgentArray[$i]) Then ContinueLoop ; not an enemy If Not GetIsAlive($lAgentArray[$i]) Then ContinueLoop ; not alive $Distance = GetDistance($lAgentArray[$i], -2) If $Distance > $aRange Then ContinueLoop ; not in range If GetTarget($lAgentArray[$i]) <> $lMe Then ContinueLoop ; not targeting me $HP = DllStructGetData($lAgentArray[$i], 'HP') If $HP > $HPPercentage Then ContinueLoop ; ignore the enemy if it has more than the set HP % $lFoeCount += 1 Next Return $lFoeCount EndIf EndFunc ;==>CheckRemainingFoes
Since my problem is that most functions don't work in loops (i think because they are called too much in a loop so they simply return 0).
I tried to use this function in a killing loop:
Code:Func GetEnemiesWithinRange($aRange = $RANGE_AREA) Local $lAgentArray = GetAgentArray(0xDB) Local $lSubArray[$lAgentArray[0] + 1] $lSubArray[0] = 0 Local $lMeXY = GetAgentXY(-2) For $i = 1 To $lAgentArray[0] If GetIsEnemy($lAgentArray[$i]) = 0 Or GetIsDead($lAgentArray[$i]) Then ContinueLoop Local $lTargetXY = GetAgentXY($lAgentArray[$i]) If ComputeDistance($lMeXY[0], $lMeXY[1], $lTargetXY[0], $lTargetXY[1]) > $aRange Then ContinueLoop $lSubArray[0] += 1 $lSubArray[$lSubArray[0]] = $lAgentArray[$i] Next ReDim $lSubArray[$lSubArray[0] + 1] Return $lSubArray EndFunc ;==>GetEnemiesWithinRange
Now I am not sure because I have never used the AgentArray like that, but I think GetMaxAgents into ComputeDistance would provide a better result. So maybe run the Kill loop to find an enemy within distance, get to the enemy, then run a check on all agents within 1450 range (I think thats compass? Maybe its 1250) and add it to the EnemiesToBeKilled or whatever you want to call it.
I have this function from a Kilroy bot that I use quite often now - all credits to whoever wrote it since I did not! It seems you could probably rework it for what you need by adding in the Counts/Range.
Code:
Func GetNearestPriority($lPriority) Local $lNearestAgent = 0, $lNearestDistance = 100000000 Local $lDistance, $lAgentToCompare Local $aAgent = GetAgentByID(-2) For $i = 1 To GetMaxAgents() $lAgentToCompare = GetAgentByID($i) If DllStructGetData($lAgentToCompare, 'HP') < 0.005 Or DllStructGetData($lAgentToCompare, 'Allegiance') <> 0x3 Or DllStructGetData($lAgentToCompare, 'Type') <> 0xDB Or GetAgentName($lAgentToCompare) <> $lPriority Then ContinueLoop $lDistance = (DllStructGetData($aAgent, 'X') - DllStructGetData($lAgentToCompare, 'X')) ^ 2 + (DllStructGetData($aAgent, 'Y') - DllStructGetData($lAgentToCompare, 'Y')) ^ 2 If $lDistance < $lNearestDistance Then $lNearestAgent = $lAgentToCompare $lNearestDistance = $lDistance EndIf Next Return $lNearestAgent EndFunc ;==>GetNearestPriority