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

onKill tfs 1.2

president vankk

Web Developer & AuraOT Owner
Joined
Jul 10, 2009
Messages
5,719
Solutions
9
Reaction score
339
Hi folks! Actually I'm having some problems with the script below, it just does not works, the main idea of this script is if you kill a Morgaroth or Ghazbaran then you'll get a achievement.

Code:
function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end
  
    if targetMonster:getName():lower() ~= "morgaroth" or targetMonster:getName():lower() ~= "ghazbaran" then
        return true
    end
  
    local player = creature:getPlayer()
    player:addAchievement('Slayer')
    return true
end

It is already registred in login.lua/monsters files/creaturescripts.xml. What is the problem in here?
Already tried to print everything but just does not works.

Thanks.
 
Code:
function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end
    if targetMonster:getName():lower() ~= "morgaroth" or targetMonster:getName():lower() ~= "ghazbaran" then
        return true
    end
    for pid, _ in pairs(targetMonster:getDamageMap()) do
        local attackerPlayer = Player(pid)
        if attackerPlayer then
            attackerPlayer:addAchievement('Slayer')
        end
    end
    return true
end
the problem is: you don't declare the player as killer, or that he did damage in the monster
 
Code:
-- so you can add more monsters to the list
local monsters = {"morgaroth", "ghazbaran"}

function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end
    -- so you don't need a bunch of or's
    if not isInArray( monsters, targetMonster:getName():lower()) then
        return true
    end
   
    for pid, _ in pairs(targetMonster:getDamageMap()) do
        local attackerPlayer = Player(pid)
        if attackerPlayer then
            attackerPlayer:addAchievement('Slayer')
        end
    end
    return true
end
 
Back
Top