• 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 Task Counting Problem

Yalasari

Active Member
Joined
Jul 16, 2017
Messages
82
Solutions
8
Reaction score
46
Hi, i have this piece of code:

Lua:
broadcastMessage('script loading', MESSAGE_STATUS_WARNING)

function onKill(player, target)
    broadcastMessage('onkill activated', MESSAGE_STATUS_WARNING)
    if(player:getStorageValue(72003) == 1) then  

        if target:isPlayer() or target:getMaster() then
            return true
        end
        broadcastMessage('questactive', MESSAGE_STATUS_WARNING)
        local targetName = target:getName():lower()

        if targetName == "kongra" then
            broadcastMessage('it is kongra', MESSAGE_STATUS_WARNING)
            local killAmount = player:getStorageValue(70001)
            if killAmount < 100 then
                broadcastMessage('added...', MESSAGE_STATUS_WARNING)
                player:setStorageValue(70001, 10 + 1)
            end
        end

    end

    return true

end

I want to count how many kongra u killed (until number of kills reach 100) it's like task system, this piece of code is edited piece of "Killing in the name of..." quest, while abovementioned quest works, this script doesn't, Script is loaded but not working (function onKill isn't called), I registered event in login.lua and added in creaturescripts.xml, version is TFS 1.2

Thanks in advance for help.
 
Solution
Code:
function onKill(player, target)
    if target:isPlayer() or target:getMaster() then
        return true
    end
  
    local targetName = target:getName():lower()
    if targetName == "kongra" and player:getStorageValue(123) < 100 then
        player:setStorageValue(123, player:getStorageValue(123) + 1)
        print("Kongras killed ".. player:getStorageValue(123))
    end
  
    return true
end
This should work.. Make sure you have this registered in creaturescripts.xml like this
Code:
<event type="death" name="killCount" script="killCount.lua"/>

then make sure you are registering the event in login.lua
Code:
player:registerEvent(killCount)

Lua:
broadcastMessage('script loading', MESSAGE_STATUS_WARNING)
function onKill(player, target)
    broadcastMessage('onkill activated', MESSAGE_STATUS_WARNING)
 
    if player:getStorageValue(72003) == 1 then
        if target:isPlayer() or target:getMaster() then
            return true
        end
    
        broadcastMessage('questactive', MESSAGE_STATUS_WARNING)
        local targetName = target:getName():lower()
        if targetName == "kongra" then
            broadcastMessage('it is kongra', MESSAGE_STATUS_WARNING)
            local killAmount = player:getStorageValue(70001)
            if killAmount < 100 then
                broadcastMessage('added...', MESSAGE_STATUS_WARNING)
                player:setStorageValue(70001, killAmount+ 1)
            end
        end
    end
    return true
end
 
Still not working, 0 errors, onKill isn't even initiated (registred in login.lua and creaturescripts.xml, but i needed to change form "death" to "kill" because, when it was "death" i got error there's no onDeath function in this file)
 
Code:
function onKill(player, target)
    if target:isPlayer() or target:getMaster() then
        return true
    end
  
    local targetName = target:getName():lower()
    if targetName == "kongra" and player:getStorageValue(123) < 100 then
        player:setStorageValue(123, player:getStorageValue(123) + 1)
        print("Kongras killed ".. player:getStorageValue(123))
    end
  
    return true
end
 
Last edited:
Solution
Back
Top