• 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 [TFS 1.2] Task Party.

Zodia

Member
Joined
Feb 21, 2020
Messages
220
Reaction score
20
My task system seems to be set so that only the last player who attacked the monster, counts. I'm trying to get you to tell Party members to attack the monster.

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

    if party...
    for ...  party:getMembers()
    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 back to Tusker in Thais.")
        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


I tried a few things using these tips:


Code:
local party = player:getParty()

if party...
    for ...  party:getMembers()



Could anyone help me with this? How would my Creaturescript code look, so that the desired result was achieved?
Of course. That count only if the Party is active, and that count only for the Party players that attack the monster.

Thanks! <3
 
I tried the following code. I haven't been successful yet.


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

    if party:isSharedExperienceEnabled() and storageValue <= monster.count then
       player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed [" .. storageValue .. "/" .. monster.count .. "] " .. monster.plural .. ".")
    else
       player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have already killed " .. monster.count .. " " .. monster.plural .. ". Report back to Tusker in Thais.")
    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 back to Tusker in Thais.")
        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
 
I tried the following code. I haven't been successful yet.


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

    if party:isSharedExperienceEnabled() and storageValue <= monster.count then
       player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed [" .. storageValue .. "/" .. monster.count .. "] " .. monster.plural .. ".")
    else
       player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have already killed " .. monster.count .. " " .. monster.plural .. ". Report back to Tusker in Thais.")
    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 back to Tusker in Thais.")
        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
You have to iterate over party members and check if they have the storage.
 
Lua:
local storageValue = player:getStorageValue(monster.storage)
local party = player:getParty()
local partyMembers = party:getMembers()

for _, member in pairs(partyMembers) do
    if member:getStorageValue(monster.storage) >= monster.start 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
 
In the code above you can give party to people in temple and they will get task kills.

I never messed up with party functions but I'll try. I didnt test it tho:
Lua:
local function addKill(playerCid, monster)
    local player = Player(playerCid)
    if player then
        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 back to Tusker in Thais.")
                else
                        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed [" .. storageValue .. "/" .. monster.count .. "] " .. monster.plural .. ".")
                end
                player:setStorageValue(monster.storage, storageValue + 1)
        end     
    end
    return true
end


function onKill(player, target)
    local monster = config[target:getName():lower()]
    if not monster or target:getMaster() then
        return true
    local party = player:getParty()
        if not party then
            addKill(player:getId(), monster)
        else
            local membersList = party:getMembers()
            membersList[#membersList + 1] = party:getLeader()
            if membersList == nil or type(membersList) ~= 'table' or #membersList <= 1 then
                addKill(player:getId(), monster)
                return false
            end     

            local affectedList = {}
            for _, targetPlayer in ipairs(membersList) do
                if targetPlayer:getPosition():getDistance(position) <= 36 then
                    affectedList[#affectedList + 1] = targetPlayer
                end
            end     
          
            local tmp = #affectedList
            if tmp <= 1 then
                addKill(player:getId(), monster)
                return false
            end         
          
            for _, targetPlayer in ipairs(affectedList) do
                addKill(targetPlayer:getId(), monster)                 
            end         
        end
    return true
end
 
Last edited:
In the code above you can give party to people in temple and they will get task kills.

I never messed up with party functions but I'll try. I didnt test it tho:
Lua:
local function addKill(playerCid, monster)
    local player = Player(playerCid)
    if player then
        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 back to Tusker in Thais.")
                else
                        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed [" .. storageValue .. "/" .. monster.count .. "] " .. monster.plural .. ".")
                end
                player:setStorageValue(monster.storage, storageValue + 1)
        end  
    end
    return true
end


function onKill(player, target)
    local monster = config[target:getName():lower()]
    if not monster or target:getMaster() then
        return true
    local party = player:getParty()
        if not party then
            addKill(player:getId(), monster)
        else
            local membersList = party:getMembers()
            membersList[#membersList + 1] = party:getLeader()
            if membersList == nil or type(membersList) ~= 'table' or #membersList <= 1 then
                addKill(player:getId(), monster)
                return false
            end  

            local affectedList = {}
            for _, targetPlayer in ipairs(membersList) do
                if targetPlayer:getPosition():getDistance(position) <= 36 then
                    affectedList[#affectedList + 1] = targetPlayer
                end
            end  
       
            local tmp = #affectedList
            if tmp <= 1 then
                addKill(player:getId(), monster)
                return false
            end      
       
            for _, targetPlayer in ipairs(affectedList) do
                addKill(targetPlayer:getId(), monster)              
            end      
        end
    return true
end

I will test and return you. Thank you so much for this!



---------------
The code I got was really bad. In addition to a duplicate message when you kill a task monster ... If I kill any other monster I get a message even if I didn't get a task. And there's more ... A task counts only for those who have done the most damage, or for those who finish the monster (last hit). That is, if I do more damage, and also give the last hit, it will only count for me. If I have done more damage, and the player has finished, it counts for both.

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 back to Tusker in Thais.")
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed [" .. storageValue .. "/" .. monster.count .. "] " .. monster.plural .. ".")
        end
            player:setStorageValue(monster.storage, storageValue + 1)
    end

    local party = player:getParty()

    if party and party:isSharedExperienceEnabled() and storageValue >= monster.count then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have already killed " .. monster.count .. " " .. monster.plural .. ". Report back to Tusker in Thais.")
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed [" .. storageValue .. "/" .. monster.count .. "] " .. monster.plural .. ".")
    end
    return true
end


Post automatically merged:


@Edit
In the code above you can give party to people in temple and they will get task kills.

I never messed up with party functions but I'll try. I didnt test it tho:
Lua:
local function addKill(playerCid, monster)
    local player = Player(playerCid)
    if player then
        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 back to Tusker in Thais.")
                else
                        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed [" .. storageValue .. "/" .. monster.count .. "] " .. monster.plural .. ".")
                end
                player:setStorageValue(monster.storage, storageValue + 1)
        end  
    end
    return true
end


function onKill(player, target)
    local monster = config[target:getName():lower()]
    if not monster or target:getMaster() then
        return true
    local party = player:getParty()
        if not party then
            addKill(player:getId(), monster)
        else
            local membersList = party:getMembers()
            membersList[#membersList + 1] = party:getLeader()
            if membersList == nil or type(membersList) ~= 'table' or #membersList <= 1 then
                addKill(player:getId(), monster)
                return false
            end  

            local affectedList = {}
            for _, targetPlayer in ipairs(membersList) do
                if targetPlayer:getPosition():getDistance(position) <= 36 then
                    affectedList[#affectedList + 1] = targetPlayer
                end
            end  
       
            local tmp = #affectedList
            if tmp <= 1 then
                addKill(player:getId(), monster)
                return false
            end      
       
            for _, targetPlayer in ipairs(affectedList) do
                addKill(targetPlayer:getId(), monster)              
            end      
        end
    return true
end

Using this code in task.lua lá in responses., the task system works when we are alone. When I activate a party, it doesn't have a mission for either player.
 
Last edited:
Only players who have dealt damage to the monster can receive storage, obviously if everyone who hurt the monster is at the same party then everyone gets

If a player without a party kills him, only he receives the points

Solution:
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
 
Last edited:
Only players who have dealt damage to the monster can receive storage, obviously if everyone who hurt the monster is at the same party then everyone gets

If a player without a party kills him, only he receives the points

Solution:
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())
    killers[#killers +1] = player
    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

Thank you for taking the time to help us.

I found a problem, the one that gives the last hit to the creature, counts +2 to the dead creature.

1616909930701.png


only the one who gave the last hit to the creature counts +2. to the party member only one.
 
yeah, sorry, check again
I already edited the code
 
yeah, sorry, check again
I already edited the code


now counts +2 :(, to the 2 players
 
Back
Top