• 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 Nostalrius - Shared Party Kills?

Neptera

Member
Joined
Mar 3, 2018
Messages
71
Reaction score
17
How can I make this lua script give one kill to each player in a party and not just to the killer?

Lua:
function onKill(player, target)
    local monster = config[target:getName():lower()]
    if not monster or target:getMaster() then
        return true
    end

    local storageValue = player:getStorageValue(monster.storage)
    if storageValue >= monster.start then
        if storageValue >= monster.count then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have already killed " .. monster.count .. " " .. monster.plural .. ". report the task to any npc post office.")
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed [" .. storageValue .. "/" .. monster.count .. "] " .. monster.plural .. ".")
        end
            player:setStorageValue(monster.storage, storageValue + 1)
    end
    return true
end
 
Lua:
function onKill(player, target)
    if player:isPlayer() and target:isMonster() then
        local party = player:getParty()
        local members = {}

        if party then
            members = party:getMembers()
            table.insert(members, party:getLeader())
        else
            members = {player}
        end

        for _, member in pairs(members) do
            local monster = config[target:getName():lower()]
            if not monster or target:getMaster() then
                return true
            end

            local storageValue = member:getStorageValue(monster.storage)
            if storageValue >= monster.start then
                if storageValue >= monster.count then
                    member:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have already killed " .. monster.count .. " " .. monster.plural .. ". Report the task to any NPC post office.")
                else
                    member:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed [" .. storageValue .. "/" .. monster.count .. "] " .. monster.plural .. ".")
                end
                member:setStorageValue(monster.storage, math.min(storageValue + 1, monster.count))
            end
        end
    end
    return true
end
 
Last edited:

Yes, but this code only register kills when player is in party (not solo kills):

Lua:
local function getKillers(creature, party)
    local killers = {}
    local timeNow = os.mtime()
    local inFightTicks = configManager.getNumber(configKeys.PZ_LOCKED)
    for uid, cb in pairs(creature:getDamageMap()) do
        local attacker = Player(uid)
        if (attacker and attacker ~= creature and timeNow - cb.ticks <= inFightTicks) then
            local p = attacker:getParty()
            if p and p == party then
                killers[#killers +1] = attacker
            end
        end
    end
    return killers
end

function onKill(player, target)
    local monster = config[target:getName():lower()]
    if not monster or target:getMaster() then
        return true
    end
    
    local killers = getKillers(target, player:getParty())
    for k, member in pairs(killers) do
        local storageValue = member:getStorageValue(monster.storage)
        if storageValue >= monster.start then
            if storageValue >= monster.count then
                member:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have already killed " .. monster.count .. " " .. monster.plural .. ". Report back to Tusker in Thais.")
            else
                member:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed [" .. storageValue .. "/" .. monster.count .. "] " .. monster.plural .. ".")
            end
            member:setStorageValue(monster.storage, storageValue + 1)
        end
    end
    return true
end


This code adds for solo kills, but not for party:

Lua:
function onKill(player, target)
    local monster = config[target:getName():lower()]
    if not monster or target:getMaster() then
        return true
    end

    local storageValue = player:getStorageValue(monster.storage)
    if storageValue >= monster.start then
        if storageValue >= monster.count then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have already killed " .. monster.count .. " " .. monster.plural .. ". report the task to any npc post office.")
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed [" .. storageValue .. "/" .. monster.count .. "] " .. monster.plural .. ".")
        end
            player:setStorageValue(monster.storage, storageValue + 1)
    end
    return true
end


How can we combine the two?
Post automatically merged:

Lua:
function onKill(creature, target)
    local party = creature:getParty()
    if not party then
        return originalOnKill(creature, target)
    end

    local members = party:getMembers()
    local leader = party:getLeader()

    for _, member in pairs(members) do
        local player = member:isPlayer() and member:asPlayer()
        if player and player ~= leader then
            local monster = config[target:getName():lower()]
            if not monster or target:getMaster() then
                return true
            end

            local storageValue = player:getStorageValue(monster.storage)
            if storageValue >= monster.start then
                if storageValue >= monster.count then
                    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have already killed " .. monster.count .. " " .. monster.plural .. ". Report the task to any NPC post office.")
                else
                    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed [" .. storageValue .. "/" .. monster.count .. "] " .. monster.plural .. ".")
                end
                player:setStorageValue(monster.storage, storageValue + 1)
            end
        end
    end

    return originalOnKill(creature, target)
end

1715165136416.png
 
Back
Top Bottom