GetUnitCastTarget
The GetUnitCastTarget function retrieves the object or unit that the specified target object or unit is currently casting a spell on. This function is useful for determining the target of an ongoing spell cast, which can be important for gameplay mechanics such as interrupting spells or providing support.
Parameters
unit: The unit identifier (GUID) or unit identifier (such as "player", "target", "focus", etc.) for which to retrieve the cast target.
Returns
castTarget: The object identifier (GUID) or unit identifier of the target that the specified unit is casting a spell on.
Example Usage in Lua
Here is an example of how to use the GetUnitCastTarget function in Lua:
local api = ...
-- Function to print the cast target of the player's target
function PrintTargetCastTarget()
local target = "target"
local castTarget = api.GetUnitCastTarget(target)
if castTarget then
local castTargetName = api.GetObjectName(castTarget)
print("The target is casting a spell on: " .. castTargetName)
else
print("The target is not casting a spell.")
end
end
-- Function to print the cast target of a specific unit by GUID
function PrintUnitCastTargetByGUID(unitGUID)
local castTarget = api.GetUnitCastTarget(unitGUID)
if castTarget then
local castTargetName = api.GetObjectName(castTarget)
print("The unit with GUID " .. unitGUID .. " is casting a spell on: " .. castTargetName)
else
print("The unit with GUID " .. unitGUID .. " is not casting a spell.")
end
end
-- Call the functions
PrintTargetCastTarget()
-- Example unit GUID (replace with an actual GUID in your game)
local exampleUnitGUID = "1234-5678-9012-3456"
PrintUnitCastTargetByGUID(exampleUnitGUID)