• 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 Look for boss reward script

Tbol

Well-Known Member
Joined
Apr 7, 2019
Messages
526
Reaction score
54
Hello im looking for boss reward script if you kill each boss one time or w/e value you set you get reward like
achievementName = "test",

so i imagine table like

Lua:
local main = {
    [1] = {
        achievementName = "Test Achievement", //so this achievement will add if you kill every single named monster one time
        ["Rat Boss"] = 1
        ["Slime Boss"] = 1
        ["Dog Boss"] = 1
        ["Cat Boss"] = 1
    },
    [2] = {
        achievementName = "Test Achievement 12", //this achievement will add if you kill each monster 5 times
        ["Dragon Boss"] = 5
        ["Gnar Boss"] = 5
        ["Thot Boss"] = 5
        ["God Boss"] = 5
    }
}
 
There you go:
Lua:
-- you must add the achievements in data/lib/core/achievements.lua
local config = {
    {
        achievement = "Foo bar",
        monsters = {
            ["rat"] = {storage = 9899, count = 1},
            ["cave rat"] = {storage = 9900, count = 1}
        }
    },
    {
        achievement = "Lorem ipsum",
        monsters = {
            ["dragon"] = {storage = 9901, count = 2},
            ["dragon lord"] = {storage = 9902, count = 1}
        }
    }
}

local killEvent = CreatureEvent("BossRewardKill")

function killEvent.onKill(creature, target)
    -- is monster
    if not target:isMonster() or target:getMaster() then
        return true
    end

    -- add kill
    local player = Player(creature)
    local targetName = target:getName():lower()
    for _, config in ipairs(config) do
        local monster = config.monsters[targetName]
        if monster then
            local value = player:getStorageValue(monster.storage) + 1
            player:setStorageValue(monster.storage, value == 0 and 1 or value)

            -- check reward
            local done = true
            for _, check in pairs(config.monsters) do
                if player:getStorageValue(check.storage) < check.count then
                    done = false
                    break
                end
            end

            -- add achievement
            if done then
                player:addAchievement(config.achievement)
            end
        end
    end

    return true
end

killEvent:register()

local loginEvent = CreatureEvent("BossRewardLogin")

function loginEvent.onLogin(player)
    player:registerEvent("BossRewardKill")
    return true
end

loginEvent:register()
However, It would have been better to create an onDeath event and register it on every boss. I leave it to you as an exercise.

Here's a demo.

Pretty sure no one is gonna do it :D
Cringe.
 
Last edited:
There you go:
Lua:
-- you must add the achievements in data/lib/core/achievements.lua
local config = {
    {
        achievement = "Foo bar",
        monsters = {
            ["rat"] = {storage = 9899, count = 1},
            ["cave rat"] = {storage = 9900, count = 1}
        }
    },
    {
        achievement = "Lorem ipsum",
        monsters = {
            ["dragon"] = {storage = 9901, count = 2},
            ["dragon lord"] = {storage = 9902, count = 1}
        }
    }
}

local killEvent = CreatureEvent("BossRewardKill")

function killEvent.onKill(creature, target)
    -- is monster
    if not target:isMonster() or target:getMaster() then
        return true
    end

    -- add kill
    local player = Player(creature)
    local targetName = target:getName():lower()
    for _, config in ipairs(config) do
        local monster = config.monsters[targetName]
        if monster then
            local value = player:getStorageValue(monster.storage) + 1
            player:setStorageValue(monster.storage, value == 0 and 1 or value)

            -- check reward
            local done = true
            for _, check in pairs(config.monsters) do
                if player:getStorageValue(check.storage) < check.count then
                    done = false
                    break
                end
            end

            -- add achievement
            if done then
                player:addAchievement(config.achievement)
            end
        end
    end

    return true
end

killEvent:register()

local loginEvent = CreatureEvent("BossRewardLogin")

function loginEvent.onLogin(player)
    player:registerEvent("BossRewardKill")
    return true
end

loginEvent:register()
However, It would have been better to create an onDeath event and register it on every boss. I leave it to you as an exercise.

Here's a demo.


Cringe.
Hmm, something isnt right with this part
Lua:
            -- add achievement
            if done then
                print(1)
                player:addAchievement(config.achievementName)
            end
killed named monsters, it prints 1 but it doesnt add the achievement

Lua:
local config = {
    {
        achievementName = "Foo Bar",
        monsters = {
            ["rat"] = {storage = 9100, count = 1},
            ["cave rat"] = {storage = 9101, count = 1}
        }
    },
and yes i have it created in lib
 
Post your data/lib/core/achievements.lua. TFS version? I am no magician.
Lua:
Player.addAchievement = function(self, name)
    local achievement = getAchievementByName(name)
    if not achievement then
        return false
    end

    local needCounter = achievement.counter
    local currentCounter = self:getAchievementCounter(achievement.id)
    if currentCounter >= needCounter then
        return false
    end

    local counter = self:addAchievementCounter(achievement.id)
    if not counter or counter < needCounter then
        return false
    end

    local reward = achievement.reward
    if reward then
        self:takeReward(achievement.reward, false)
        self:enableAchievementRegeneration(achievement.id)
    end

    return true
end

//example how its made in other scripts

Lua:
    for _, config in ipairs(main) do
        if isInArray(config.monsters, monsterName) then
            player:addAchievement(config.achievementName)
        end
    end
 
Last edited:
Again: post your data/lib/core/achievements.lua. TFS version? I am no magician. Also, what does print(player:addAchievement(config.achievement)) print to the console? Moreover, copy and paste the snippet above as it is. Once it works, you are free to modify it.
 
Again: post your data/lib/core/achievements.lua. TFS version? I am no magician. Also, what does print(player:addAchievement(config.achievement)) print to the console? Moreover, copy and paste the snippet above as it is. Once it works, you are free to modify it.
Its TFS 1.2
Prints absolutly nothing.
 
There is nothing I can do then, the script above is 1.3 compliant. However, you can send me the files he sold you (PM me here in OTLand), so I can further investigate the problem and provide you with a solution.
 
There is nothing I can do then, the script above is 1.3 compliant. However, you can send me the files he sold you (PM me here in OTLand), so I can further investigate the problem and provide you with a solution.
the overall code sctructure is prety much same. For example this is a code that works perfectly
Lua:
local main = {
    [1] = {
        achievementName = "Templar",
        monsters = {"Monster Name 1", "Monster Name 2", "Monster Name 3"}
    },
    [2] = {
        achievementName = "Defender",
        monsters = {"Monster Fighter 1", "Monster Fighter 2", "Monster Fighter 3", "Monster Fighter 4", "Monster Fighter 5", "Monster Fighter 6"}
    },
    [3] = {
        achievementName = "Defense Tamer",
        monsters = {"Defender 1", "Defender 2", "Defender 3"}
    },
    [4] = {
        achievementName = "Master",
        monsters = {"Machine 1", "Machine 2", "Machine 3"}
    }
}

for _, config in ipairs(main) do
    for i = 1, #config.monsters do
        config.monsters[i] = config.monsters[i]:lower()
    end
end

function onKill(creature, target)
    if not creature:isPlayer() or not target:isMonster() or target:getMaster() then 
        return true 
    end

    local monsterName = target:getName():lower()
    local player = Player(creature)

    for _, config in ipairs(main) do
        if isInArray(config.monsters, monsterName) then
            player:addAchievement(config.achievementName)
        end
    end

    return true
end
 
Lua:
local main = {
    [1] = {
        achievementName = "Templar",
        toKill = 5,
        storage = 3005,
        monsters = {"Rat", "Monster Name 2", "Monster Name 3"}
    },
    [2] = {
        achievementName = "Clay to Fame",
        toKill = 5,
        storage = 3019,
        monsters = {"Ghastly Dragon", "Monster Fighter 2", "Monster Fighter 3", "Monster Fighter 4", "Monster Fighter 5", "Monster Fighter 6"}
    },
    [3] = {
        achievementName = "Defense Tamer",
        toKill = 5,
        storage = 3001,
        monsters = {"Cave Rat", "Defender 2", "Defender 3"}
    },
    [4] = {
        achievementName = "Firewalker",
        toKill = 5,
        storage = 3100,
        monsters = {"War Golem", "Machine 2", "Machine 3"}
    }
}

for _, config in ipairs(main) do
    for i = 1, #config.monsters do
        config.monsters[i] = config.monsters[i]:lower()
    end
end

function onKill(creature, target)
    if not creature:isPlayer() or not target:isMonster() or target:getMaster() then
        return true
    end
    local monsterName = target:getName():lower()
    local player = Player(creature)

    for _, config in ipairs(main) do
        if isInArray(config.monsters, monsterName) then
           player:setStorageValue(config.storage, player:getStorageValue(config.storage) + 1)       
        if player:getStorageValue(config.storage) == config.toKill then
            player:addAchievement(config.achievementName)
            end
        end
    end

    return true
    end
I'm not quite sure, is this what u wanted?
 
Lua:
local main = {
    [1] = {
        achievementName = "Templar",
        toKill = 5,
        storage = 3005,
        monsters = {"Rat", "Monster Name 2", "Monster Name 3"}
    },
    [2] = {
        achievementName = "Clay to Fame",
        toKill = 5,
        storage = 3019,
        monsters = {"Ghastly Dragon", "Monster Fighter 2", "Monster Fighter 3", "Monster Fighter 4", "Monster Fighter 5", "Monster Fighter 6"}
    },
    [3] = {
        achievementName = "Defense Tamer",
        toKill = 5,
        storage = 3001,
        monsters = {"Cave Rat", "Defender 2", "Defender 3"}
    },
    [4] = {
        achievementName = "Firewalker",
        toKill = 5,
        storage = 3100,
        monsters = {"War Golem", "Machine 2", "Machine 3"}
    }
}

for _, config in ipairs(main) do
    for i = 1, #config.monsters do
        config.monsters[i] = config.monsters[i]:lower()
    end
end

function onKill(creature, target)
    if not creature:isPlayer() or not target:isMonster() or target:getMaster() then
        return true
    end
    local monsterName = target:getName():lower()
    local player = Player(creature)

    for _, config in ipairs(main) do
        if isInArray(config.monsters, monsterName) then
           player:setStorageValue(config.storage, player:getStorageValue(config.storage) + 1)      
        if player:getStorageValue(config.storage) == config.toKill then
            player:addAchievement(config.achievementName)
            end
        end
    end

    return true
    end
I'm not quite sure, is this what u wanted?
I assume its if you kill every named monster of that list, it will give achievement only then, but im not sure if its it because it doesnt work either :D
 
I assume its if you kill every named monster of that list, it will give achievement only then, but im not sure if its it because it doesnt work either :D
Yeah, it does work but on TFS 1.3 xD, my bad assuming that you are using 1.3 when u wrote 1.2 😵 // even tho maybe someone's gonna use it :D
 
To be clear, there is a perfectly fine and working script for what you want to happen, except for the achievement issue. (1 line of code)

You aren't looking for another script, you are currently looking for a solution to a custom made function / feature in your tfs 1.2 installation.

Unless you post more information about your custom achievement system, namely data/lib/core/achievements.lua there is literally nothing else we can do for you.

Every script will fail to meet your expectations, because we don't know exactly how your system is working.

---
To be extra clear, there is a very large chance you failed to update your achievements.lua with "foo bar" or "Lorem ipsum", and is most likely the reason the script is failing to execute as you were expecting.

But, we have no way of knowing that, because you refuse to post relevant information.

You should stop asking for help, if you refuse to be helped.
 
Back
Top