From 6e4e77f18d895b8f972565b75c5769cd255840e5 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sat, 14 Jun 2014 12:35:01 +0300 Subject: [PATCH] Update CreatureMethods.h --- CreatureMethods.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/CreatureMethods.h b/CreatureMethods.h index 26d5c3f..23a2cf1 100644 --- a/CreatureMethods.h +++ b/CreatureMethods.h @@ -330,10 +330,12 @@ namespace LuaCreature uint32 targetType = Eluna::CHECKVAL(L, 2); bool playerOnly = Eluna::CHECKVAL(L, 3, false); uint32 position = Eluna::CHECKVAL(L, 4, 0); - float dist = Eluna::CHECKVAL(L, 5, -1.0f); + float dist = Eluna::CHECKVAL(L, 5, 0.0f); int32 aura = Eluna::CHECKVAL(L, 6, 0); - ThreatList const& threatlist = creature->getThreatManager().getThreatList(); + ThreatList const& threatlist = creature->getThreatManager().getThreatList(); + if (threatlist.empty()) + return 1; if (position >= threatlist.size()) return 1; @@ -351,9 +353,13 @@ namespace LuaCreature continue; if (dist > 0.0f && !creature->IsWithinDist(target, dist)) continue; + else if (dist < 0.0f && creature->IsWithinDist(target, -dist)) + continue; targetList.push_back(target); } + if (targetList.empty()) + return 1; if (position >= targetList.size()) return 1; @@ -366,7 +372,8 @@ namespace LuaCreature case SELECT_TARGET_TOPAGGRO: { std::list::const_iterator itr = targetList.begin(); - std::advance(itr, position); + if (position) + std::advance(itr, position); Eluna::Push(L, *itr); } break; @@ -374,14 +381,16 @@ namespace LuaCreature case SELECT_TARGET_BOTTOMAGGRO: { std::list::reverse_iterator ritr = targetList.rbegin(); - std::advance(ritr, position); + if (position) + std::advance(ritr, position); Eluna::Push(L, *ritr); } break; case SELECT_TARGET_RANDOM: { std::list::const_iterator itr = targetList.begin(); - std::advance(itr, urand(position, targetList.size() - 1)); + if (position) + std::advance(itr, urand(0, position)); Eluna::Push(L, *itr); } break; @@ -400,8 +409,9 @@ namespace LuaCreature uint32 i = 0; ThreatList const& threatList = creature->getThreatManager().getThreatList(); - ThreatList::const_iterator itr; - for (itr = threatList.begin(); itr != threatList.end(); ++itr) + if (threatList.empty()) + return 1; + for (ThreatList::const_iterator itr = threatList.begin(); itr != threatList.end(); ++itr) { Unit* target = (*itr)->getTarget(); if (!target)