• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 0.X Detect monster attacking

Solution
The function return the uid of the creature, so once u get the uid then u can check the name
Lua:
local target = getCreatureTarget(cid)
if getCreatureName(target):lower() == "troll" then
    -- do something
end

And to properly check
Lua:
local target = getCreatureTarget(cid)
if target > 0 then
    if isMonster(target) and getCreatureName(target):lower() == "troll" then
        -- do something
    end
end
The function return the uid of the creature, so once u get the uid then u can check the name
Lua:
local target = getCreatureTarget(cid)
if getCreatureName(target):lower() == "troll" then
    -- do something
end

And to properly check
Lua:
local target = getCreatureTarget(cid)
if target > 0 then
    if isMonster(target) and getCreatureName(target):lower() == "troll" then
        -- do something
    end
end
 
Last edited:
Solution
The function return the uid of the creature, so once u get the uid then u can check the name
Lua:
local target = getCreatureTarget(cid)
if getCreatureName(target):lower() == "troll" then
    -- do something
end

And to properly check
Lua:
local target = getCreatureTarget(cid)
if target > 0 then
    if isMonster(target) and getCreatureName(target):lower() == "troll" then
        -- do something
    end
end
ttyyyy
 
The number you're seeing is targetted creature identifier (cid is short for creature identifier btw).

If you call this, you will get target creature name
Code:
local targetId = getCreatureTarget(cid)
local targetName = getCreatureName(targetId)
print(targetName)
 
Back
Top