• 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 1.X+ Please change script from function on kill to function on death in task

damian00912

Member
Joined
Sep 11, 2009
Messages
90
Reaction score
6
Hallo! Please, someone can help me with script for killing on task, because now i have this script if player don't target monster, that's he dont get killing creature to task. I need chnge if every player who make damage, get progress to task. Someon can change this script for correct please? Thanks you so much!!!

Lua:
local killingInTheNameOfKill = CreatureEvent("KillingInTheNameOfKill")

function killingInTheNameOfKill.onKill(creature, target)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if not target:isMonster() or target:getMaster() then
        return true
    end

    local targetName, startedTasks, taskId = target:getName():lower(), player:getStartedTasks()
    for i = 1, #startedTasks do
        taskId = startedTasks[i]
        if isInArray(tasks[taskId].creatures, targetName) then
            local killAmount = player:getStorageValue(KILLSSTORAGE_BASE + taskId)
            if killAmount < tasks[taskId].killsRequired then
                -- Set max kills to adm
                if (player:getAccountType() >= ACCOUNT_TYPE_GOD) then
                    player:setStorageValue(KILLSSTORAGE_BASE + taskId, tasks[taskId].killsRequired)
                    return true
                end

                player:setStorageValue(KILLSSTORAGE_BASE + taskId, killAmount + 1)
            end
        end
    end

    if(isMonster(target)) then
        local killAmount = player:getStorageValue(Storage.KillingInTheNameOf.LugriNecromancerCount)
        if(string.lower(getCreatureName(target)) == "necromancer") and killAmount < 4000 and player:getStorageValue(Storage.KillingInTheNameOf.LugriNecromancers) == 1 then
            player:setStorageValue(Storage.KillingInTheNameOf.LugriNecromancerCount, killAmount + 1)

        elseif(string.lower(getCreatureName(target)) == "priestess") and killAmount < 4000 and player:getStorageValue(Storage.KillingInTheNameOf.LugriNecromancers) == 1 then
            player:setStorageValue(Storage.KillingInTheNameOf.LugriNecromancerCount, killAmount + 1)

        elseif(string.lower(getCreatureName(target)) == "blood priest") and killAmount < 4000 and player:getStorageValue(Storage.KillingInTheNameOf.LugriNecromancers) == 1 then
            player:setStorageValue(Storage.KillingInTheNameOf.LugriNecromancerCount, killAmount + 1)

        elseif(string.lower(getCreatureName(target)) == "blood hand") and killAmount < 4000 and player:getStorageValue(Storage.KillingInTheNameOf.LugriNecromancers) == 1 then
            player:setStorageValue(Storage.KillingInTheNameOf.LugriNecromancerCount, killAmount + 1)

        elseif(string.lower(getCreatureName(target)) == "shadow pupil") and killAmount < 4000 and player:getStorageValue(Storage.KillingInTheNameOf.LugriNecromancers) == 1 then
            player:setStorageValue(Storage.KillingInTheNameOf.LugriNecromancerCount, killAmount + 1)
        end
    end
    return true
end

killingInTheNameOfKill:register()
Post automatically merged:

I think for change is only this part of script

Lua:
function killingInTheNameOfKill.onKill(creature, target)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if not target:isMonster() or target:getMaster() then
        return true
    end
 
For this to work correctly you must change the onKill event to onDeath and register this event in the monster:

The code would be the following:
Lua:
local function getKillers(creature)
    local killers = {}
    for uid, info in pairs(creature:getDamageMap()) do
        local player = Player(uid)
        if player then
            killers[#killers +1] = player
        end
    end
    return killers
end

local monsterNames = {
    "necromancer",
    "priestess",
    "blood priest",
    "blood hand",
    "shadow pupil"
}

local killingInTheNameOfKill = CreatureEvent("KillingInTheNameOfKill")

function killingInTheNameOfKill.onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    if not creature:isMonster() or creature:getMaster() then
        return true
    end

    local killers = getKillers(creature)
    if #killers == 0 then
        return true
    end

    local creatureName = creature:getName():lower()
    for _, player in pairs(killers) do
        for _, taskId in pairs(player:getStartedTasks()) do
            if isInArray(tasks[taskId].creatures, creatureName) then
                local killAmount = player:getStorageValue(KILLSSTORAGE_BASE + taskId)
                if killAmount < tasks[taskId].killsRequired then
                    -- Set max kills to adm
                    if (player:getAccountType() >= ACCOUNT_TYPE_GOD) then
                        player:setStorageValue(KILLSSTORAGE_BASE + taskId, tasks[taskId].killsRequired)
                    else
                        player:setStorageValue(KILLSSTORAGE_BASE + taskId, killAmount + 1)
                    end
                end
            end
        end
        local killAmount = player:getStorageValue(Storage.KillingInTheNameOf.LugriNecromancerCount)
        if isInArray(monsterNames, creatureName) and player:getStorageValue(Storage.KillingInTheNameOf.LugriNecromancers) == 1 then
            player:setStorageValue(Storage.KillingInTheNameOf.LugriNecromancerCount, killAmount + 1)
        end
    end
    return true
end

killingInTheNameOfKill:register()

to register the event in the monster you can use the following code:
this code must be in data/events/scripts/creature.lua in function: Creature:onTargetCombat
Lua:
if creature and target and target:isMonster() and isInArray({"necromancer", "priestess", "blood priest", "blood hand", "shadow pupil"}, target:getName():lower()) then
        target:registerEvent("KillingInTheNameOfKill")
end
 
Back
Top