Killroy

Killroy

37.6k Downloads

Functions for distance and Occlusion

Togglebutton opened this issue · 1 comments

commented

I did these to see if I could help.

function InRange(unitTarget)
    if self.bUseDistance ~= true then return nil end

    local unitPlayer = GameLib.GetPlayerUnit()
    if type(unitTarget) == "string" then
        unitTarget = GameLib.GetPlayerUnitByName(tostring(unitTarget))
    end

    if not unitTarget or not unitPlayer then
        return 0
    end

    tPosTarget = unitTarget:GetPosition()
    tPosPlayer = unitPlayer:GetPosition()

    if tPosTarget == nil or tPosPlayer == nil then
        return 0
    end

    local nDeltaX = tPosTarget.x - tPosPlayer.x
    local nDeltaY = tPosTarget.y - tPosPlayer.y
    local nDeltaZ = tPosTarget.z - tPosPlayer.z

    local nDistance = math.floor(math.sqrt((nDeltaX ^ 2) + (nDeltaY ^ 2) + (nDeltaZ ^ 2)))
    return nDistance < math.floor(self.nMaxDistance)
end

-- unitTarget unit or string    The target of the check
-- returns (true or false) or nil   if not using distance range

function CheckOcclusion(unitTarget)
    if type(unitTarget) == "string" then
        unitTarget = GameLib.GetPlayerUnitByName(tostring(unitTarget))
    end

    if not unitTarget then return end

    if self.bUseOcclusion == true then
        return unitTarget:IsOccluded()
    else
        return nil
    end
end
-- unitTarget unit or string    The target of the check
-- returns (true or false) or nil   if not using occlusion
commented

Appreciated. Was building the UI, deciding what I wanted to put in. This will save me some time.

-------Original Message-------
From: Togglebutton [email protected]
To: baslack/Killroy [email protected]
Subject: [Killroy] Functions for distance and Occlusion (#1)
Sent: Jun 18 '14 16:12

I did these to see if I could help.

function InRange(unitTarget) if self.bUseDistance ~= true then return
nil end local unitPlayer = GameLib.GetPlayerUnit() if
type(unitTarget) == "string" then unitTarget =
GameLib.GetPlayerUnitByName(tostring(unitTarget)) end if not
unitTarget or not unitPlayer then return 0 end tPosTarget
= unitTarget:GetPosition() tPosPlayer = unitPlayer:GetPosition()
if tPosTarget == nil or tPosPlayer == nil then return 0 end
local nDeltaX = tPosTarget.x - tPosPlayer.x local nDeltaY =
tPosTarget.y - tPosPlayer.y local nDeltaZ = tPosTarget.z - tPosPlayer.z
local nDistance = math.floor(math.sqrt((nDeltaX ^ 2) + (nDeltaY ^ 2) +
(nDeltaZ ^ 2))) return nDistance < math.floor(self.nMaxDistance) end
-- unitTarget unit or string The target of the check -- returns (true or
false) or nil if not using distance range function
CheckOcclusion(unitTarget) if type(unitTarget) == "string" then
unitTarget = GameLib.GetPlayerUnitByName(tostring(unitTarget)) end
if not unitTarget then return end if self.bUseOcclusion == true then
return unitTarget:IsOccluded() else return nil end
end -- unitTarget unit or string The target of the check -- returns
(true or false) or nil if not using occlusion


Reply to this email directly or [LINK:
https://github.com//issues/1] view it on GitHub.