ID:1608191
 
(See the best response by Ter13.)
Code:
Aggro(mob/attacker, amount)
if(attacker in Threat)
Threat[attacker] += amount
checkThreat(Threat)
else
Threat[attacker] = amount
checkThreat(Threat)



checkThreat(list/L)
var/max
for(var/a in L)
if(max == null || L[a] > max) max = L[a]
return max


Problem description:
using this code, however I dont want to return the max value, I want to return the item WITH the max value
Set the return value to 'a' after that if check (.=a), and then remove the return max.
Best response
I have JUST the thing for you!

http://www.byond.com/forum/?post=1606593

The above is a link to my prioritylist datum, which will keep a sorted copy of a list around linked to a weight value.

mob/ai
var
prioritylist/threatlist = new()
proc
Aggro(mob/attacker,amount)
if(attacker in Threat.values)
threatlist.Change(attacker,amount)
else
threatlist.Add(attacker,amount)
checkThreat()

checkThreat()
return threatlist.Get(threatlist.len)


My priority list makes keeping things sorted a cinch. It's also extremely efficient, and mimics to the best of our ability, BYOND's built-in lists.

Go check it out!
In response to Ter13
Ter13 wrote:
I have JUST the thing for you!

http://www.byond.com/forum/?post=1606593

The above is a link to my prioritylist datum, which will keep a sorted copy of a list around linked to a weight value.

> mob/ai
> var
> prioritylist/threatlist = new()
> proc
> Aggro(mob/attacker,amount)
> if(attacker in Threat.values)
> threatlist.Change(attacker,amount)
> else
> threatlist.Add(attacker,amount)
> checkThreat()
>
> checkThreat()
> return threatlist.Get(threatlist.len)
>

My priority list makes keeping things sorted a cinch. It's also extremely efficient, and mimics to the best of our ability, BYOND's built-in lists.

Go check it out!

how do I go about returning the mob with the highest threat?
like if i want to set the AI's target to the person with the highest threat? should i just call Target = checkThreat()
Yep. My prioritylist sorts objects from lowest to highest. based on the numbers you pass into the Add/Change functions.

That means that the highest threat will be at the end of the prioritylist's contents. That's why I'm checking threatlist.len, because by default, the highest threat value is going to be the last item in the list.