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

Solved Kill bosses and do something [TFS 1.2]

Joined
Jul 18, 2014
Messages
193
Solutions
2
Reaction score
15
Hi, im trying to make a script that when you kill some bosses, it gives you a storage value and teleports you to an specific position, but when i kill the boss, nothing happens :/ and i already verified on creaturescripts.xml, on login.lua (register the event) and the script but i cant find the error.
This is the script (IT'S FOR TFS 1.2):

Code:
local bosses = {
    ['Red Undergrounder'] = {status = 2, storage = 4565},
    ['Green Undergrounder'] = {status = 2, storage = 4566},
    ['Yellow Undergrounder'] = {status = 2, storage = 4567},
    ['Blue Undergrounder'] = {status = 2, storage = 4568}
}

function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    local bossConfig = bosses[targetMonster:getName():lower()]
    if not bossConfig then
        return true
    end

    for pid, _ in pairs(targetMonster:getDamageMap()) do
        local attackerPlayer = Player(pid)
        if attackerPlayer then
            if attackerPlayer:getStorageValue(bossConfig.storage) < bossConfig.status then
                attackerPlayer:setStorageValue(bossConfig.storage, bossConfig.status)
                Game.setStorageValue(bossConfig.storage, 0)
                attackerPlayer:teleportTo({x = 248, y = 115, z = 10})
            end
        end
    end
end

Please help. Thanks :)
 
Hi, im trying to make a script that when you kill some bosses, it gives you a storage value and teleports you to an specific position, but when i kill the boss, nothing happens :/ and i already verified on creaturescripts.xml, on login.lua (register the event) and the script but i cant find the error.
This is the script (IT'S FOR TFS 1.2):

Code:
local bosses = {
    ['Red Undergrounder'] = {status = 2, storage = 4565},
    ['Green Undergrounder'] = {status = 2, storage = 4566},
    ['Yellow Undergrounder'] = {status = 2, storage = 4567},
    ['Blue Undergrounder'] = {status = 2, storage = 4568}
}

function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    local bossConfig = bosses[targetMonster:getName():lower()]
    if not bossConfig then
        return true
    end

    for pid, _ in pairs(targetMonster:getDamageMap()) do
        local attackerPlayer = Player(pid)
        if attackerPlayer then
            if attackerPlayer:getStorageValue(bossConfig.storage) < bossConfig.status then
                attackerPlayer:setStorageValue(bossConfig.storage, bossConfig.status)
                Game.setStorageValue(bossConfig.storage, 0)
                attackerPlayer:teleportTo({x = 248, y = 115, z = 10})
            end
        end
    end
end

Please help. Thanks :)

Add a print to every block in the code and tell us where the code stops printing.
 
Test this
Code:
local bosses = {
    ['Red Undergrounder'] = {status = 2, storage = 4565},
    ['Green Undergrounder'] = {status = 2, storage = 4566},
    ['Yellow Undergrounder'] = {status = 2, storage = 4567},
    ['Blue Undergrounder'] = {status = 2, storage = 4568}
}

function onKill(creature, target)
    local position = {}
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    local bossConfig = bosses[targetMonster:getName():lower()]
    if not bossConfig then
        return true
    end

    for pid, _ in pairs(targetMonster:getDamageMap()) do
        local attackerPlayer = Player(pid)
        if attackerPlayer then
            if attackerPlayer:getStorageValue(bossConfig.storage) < bossConfig.status then
                attackerPlayer:setStorageValue(bossConfig.storage, bossConfig.status)
                Game.setStorageValue(bossConfig.storage, 0)
                position = {x = 248, y = 115, z = 10}
            else
                position = attackerPlayer:getPosition()
            end
            attackerPlayer:teleportTo(position, false)
        end
    end
    return true
end
 
Last edited:
Test this
Code:
local bosses = {
    ['Red Undergrounder'] = {status = 2, storage = 4565},
    ['Green Undergrounder'] = {status = 2, storage = 4566},
    ['Yellow Undergrounder'] = {status = 2, storage = 4567},
    ['Blue Undergrounder'] = {status = 2, storage = 4568}
}

function onKill(creature, target)
    local position = {}
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    local bossConfig = bosses[targetMonster:getName():lower()]
    if not bossConfig then
        return true
    end

    for pid, _ in pairs(targetMonster:getDamageMap()) do
        local attackerPlayer = Player(pid)
        if attackerPlayer then
            if attackerPlayer:getStorageValue(bossConfig.storage) < bossConfig.status then
                attackerPlayer:setStorageValue(bossConfig.storage, bossConfig.status)
                Game.setStorageValue(bossConfig.storage, 0)
                position = {x = 248, y = 115, z = 10}
            else
                position = attackerPlayer:getPosition()
            end
            attackerPlayer:teleportTo(position, false)
        end
    end
    return true
end

The error was here: local bossConfig = bosses[targetMonster:getName():lower()]
I remember that the lower() is when the monsters name are in lowercase, but not this time, so i delete it and now works perfectly ^^ Thanks anyway :)
 
The error was here: local bossConfig = bosses[targetMonster:getName():lower()]
I remember that the lower() is when the monsters name are in lowercase, but not this time, so i delete it and now works perfectly ^^ Thanks anyway :)
Yea, I over looked the names, I've been up all night/day trying to get my sleeping schedule back in order.
 
Back
Top