• 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!

Lua target:getDamageMap()

Fortera Global

Intermediate OT User
Joined
Nov 20, 2015
Messages
1,180
Solutions
2
Reaction score
117
Why its ever return false?
if not isInArray(target:getDamageMap(), player) then

Lua:
local function checkTask(player, target)
    if not isInArray(target:getDamageMap(), player) then
        return false
    end
-- something
end

function onKill(player, target)
    if target:isPlayer() or target:getMaster() then
        return true
    end
checkTask(player, target)
return true
end

tfs 1.2
 
Solution
try this
Lua:
local function checkTask(player, target)
    local pid = player:getId()
    for cid, damage in pairs(target:getDamageMap()) do
        if cid == pid then
            return true
        end
    end
    return false
end

function onKill(player, target)
    if target:isPlayer() or target:getMaster() then
        return true
    end
    if checkTask(player, target) then
        print("yes")
    end
    return true
end
Because you are comparing apples to oranges, player is userdata and getDamageMap returns a table of properties these properties total & ticks, hold number values.
C++:
int LuaScriptInterface::luaCreatureGetDamageMap(lua_State* L)
{
    // creature:getDamageMap()
    Creature* creature = getUserdata<Creature>(L, 1);
    if (!creature) {
        lua_pushnil(L);
        return 1;
    }

    lua_createtable(L, creature->damageMap.size(), 0);
    for (auto damageEntry : creature->damageMap) {
        lua_createtable(L, 0, 2);
        setField(L, "total", damageEntry.second.total);
        setField(L, "ticks", damageEntry.second.ticks);
        lua_rawseti(L, -2, damageEntry.first);
    }
    return 1;
}
 
Last edited:
try this
Lua:
local function checkTask(player, target)
    local pid = player:getId()
    for cid, damage in pairs(target:getDamageMap()) do
        if cid == pid then
            return true
        end
    end
    return false
end

function onKill(player, target)
    if target:isPlayer() or target:getMaster() then
        return true
    end
    if checkTask(player, target) then
        print("yes")
    end
    return true
end
 
Solution
try this
Lua:
local function checkTask(player, target)
    local pid = player:getId()
    for cid, damage in pairs(target:getDamageMap()) do
        if cid == pid then
            return true
        end
    end
    return false
end

function onKill(player, target)
    if target:isPlayer() or target:getMaster() then
        return true
    end
    if checkTask(player, target) then
        print("yes")
    end
    return true
end
Isn't it unsafe to pass player to a method? Why not just pass the id? Or does he really need the method? But then again we don't know the real reason for the method other than what is written..
 
Isn't it unsafe to pass player to a method? Why not just pass the id? Or does he really need the method? But then again we don't know the real reason for the method other than what is written..
unsafe to pass it to a timed event
this won't be executed at a later time since he doesn't use addEvent, so it's still safe
i kept the method because it was in his original code
 
try this
Lua:
local function checkTask(player, target)
    local pid = player:getId()
    for cid, damage in pairs(target:getDamageMap()) do
        if cid == pid then
            return true
        end
    end
    return false
end

function onKill(player, target)
    if target:isPlayer() or target:getMaster() then
        return true
    end
    if checkTask(player, target) then
        print("yes")
    end
    return true
end
You can just use:
Code:
local damageMap = target:getDamageMap()
if damageMap[player:getId()] then
-- player is in damage map
 
Last edited:
Back
Top