Skip to content

Commit

Permalink
Fix errors in autotarget
Browse files Browse the repository at this point in the history
  • Loading branch information
zygzagZ committed Apr 23, 2017
1 parent 0ae9c28 commit afb2e0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions modules/04-targets/events/autoloot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ function AutoLoot.canLoot(creature)
if (not targets or not table.contains(targets, creature)) and not Position.isInRange(player:getPosition(), creature:getPosition(), 3, 3) and (not attacking or attacking ~= creature) then
return false
end
if AutoLoot.lootList[creature:getId()] then
return false
end
local target = TargetsModule.getTarget(creature:getName())
if target then
return target:getLoot()
Expand Down
13 changes: 9 additions & 4 deletions modules/04-targets/events/autotarget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ end
function AutoTarget.addCreature(creature)
-- Avoid adding new targets when attacking
if creature and creature:isMonster() then
--connect(creature, { onHealthPercentChange = AutoTarget.onTargetHealthChange })
connect(creature, { onHealthPercentChange = AutoTarget.onTargetHealthChange })
connect(creature, { onDeath = AutoLoot.onTargetDeath })
connect(creature, { onDisappear = AutoTarget.removeCreature })

Expand All @@ -80,7 +80,7 @@ end

function AutoTarget.removeCreature(creature)
if creature then
--disconnect(creature, { onHealthPercentChange = AutoTarget.onTargetHealthChange })
disconnect(creature, { onHealthPercentChange = AutoTarget.onTargetHealthChange })
disconnect(creature, { onDeath = AutoLoot.onTargetDeath })
disconnect(creature, { onDisappear = AutoTarget.removeCreature })

Expand All @@ -106,7 +106,10 @@ function AutoTarget.checkStance(target)
end

function AutoTarget.onTargetHealthChange(creature)

if creature:getHealthPercent() < 1 then
AutoTarget.removeCreature(creature)
AutoLoot.onTargetDeath(creature)
end
end

function AutoTarget.directionMatches(creature, player)
Expand All @@ -121,7 +124,9 @@ function AutoTarget.isValidTarget(creature)
local player = g_game.getLocalPlayer()
local target = TargetsModule.getTarget(creature:getName())
local creaturePos = creature:getPosition()
if not Position.isInRange(player:getPosition(), creaturePos, 7, 5) or
if creature:getHealthPercent() < 1 or
not creaturePos or
not Position.isInRange(player:getPosition(), creaturePos, 7, 5) or
not target or
not player:canStandBy(creature, 200) then
return false
Expand Down

0 comments on commit afb2e0e

Please sign in to comment.