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

RevScripts TFS 1.3 Change task reward from mount to item

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hi guys, I would like to change the reward the player receive when he completes the task. Right now it's set for the player to receive mount, however I would like for the player to receive a item, I've tried to look at similar scripts, but I didn't manage to make it on my own.

Lua:
local config = {
    [{"centipede", "bug", "moss bug", "cockroach"}]                    = {mountReward = 93, killGoal = 1000,  storage = 84755, monsterType = "bugs"}, -- check mounts.xml for the mountIds
    [{"ancient scarab", "giant spider"}]    = {mountReward = 1111, killGoal = 2500,  storage = 45002, monsterType = "crawly things"},
    [{"kollos", "spidris"}]                    = {mountReward = 1111, killGoal = 3500, storage = 45003, monsterType = "bosses"}
}

local killEvent = CreatureEvent("newOnKillEvent")
killEvent:type("kill")

function killEvent.onKill(creature, target)
    if not creature:isPlayer() then
        return true
    end
    if not target:isMonster() then
        return true
    end
    local monsterName = target:getName():lower()
    for v, k in pairs(config) do
        if table.contains(v, monsterName) then
            local currentStorage = creature:getStorageValue(k.storage)
            if currentStorage >= k.killGoal then
                return true
            end
            currentStorage = currentStorage < 1 and 1 or currentStorage + 1
            creature:setStorageValue(k.storage, currentStorage)
            if currentStorage == k.killGoal then
                creature:addMount(k.mountReward)
            end
            creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed " .. currentStorage .. "/" .. k.killGoal .. " " .. k.monsterType .. ".")
            return true
        end
    end
    return true
end

killEvent:register()


local loginEvent = CreatureEvent("registerOnKill")
loginEvent:type("login")

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

loginEvent:register()

Credits for @Xikini for the original script.
 
Solution
Lua:
local config = {
    [{"centipede", "bug", "moss bug", "cockroach"}]                    = {itemReward = 2263, itemCount = 1, killGoal = 1000,  storage = 84755, monsterType = "bugs"},
    [{"ancient scarab", "giant spider"}]    = {itemReward = 2263, itemCount = 2, killGoal = 2500,  storage = 45002, monsterType = "crawly things"},
    [{"kollos", "spidris"}]                    = {itemReward = 2263, itemCount = 3, killGoal = 3500, storage = 45003, monsterType = "bosses"}
}

local killEvent = CreatureEvent("newOnKillEvent")
killEvent:type("kill")

function killEvent.onKill(creature, target)
    if not creature:isPlayer() then
        return true
    end
    if not target:isMonster() then
        return true
    end
    local monsterName...
Lua:
local config = {
    [{"centipede", "bug", "moss bug", "cockroach"}]                    = {itemReward = 2263, itemCount = 1, killGoal = 1000,  storage = 84755, monsterType = "bugs"},
    [{"ancient scarab", "giant spider"}]    = {itemReward = 2263, itemCount = 2, killGoal = 2500,  storage = 45002, monsterType = "crawly things"},
    [{"kollos", "spidris"}]                    = {itemReward = 2263, itemCount = 3, killGoal = 3500, storage = 45003, monsterType = "bosses"}
}

local killEvent = CreatureEvent("newOnKillEvent")
killEvent:type("kill")

function killEvent.onKill(creature, target)
    if not creature:isPlayer() then
        return true
    end
    if not target:isMonster() then
        return true
    end
    local monsterName = target:getName():lower()
    for v, k in pairs(config) do
        if table.contains(v, monsterName) then
            local currentStorage = creature:getStorageValue(k.storage)
            if currentStorage >= k.killGoal then
                return true
            end
            currentStorage = currentStorage < 1 and 1 or currentStorage + 1
            creature:setStorageValue(k.storage, currentStorage)
            if currentStorage == k.killGoal then
                creature:addItem(k.itemReward, k.itemCount)
            end
            creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed " .. currentStorage .. "/" .. k.killGoal .. " " .. k.monsterType .. ".")
            return true
        end
    end
    return true
end

killEvent:register()


local loginEvent = CreatureEvent("registerOnKill")
loginEvent:type("login")

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

loginEvent:register()
 
Solution
local config = { [{"centipede", "bug", "moss bug", "cockroach"}] = {itemReward = 2263, itemCount = 1, killGoal = 1000, storage = 84755, monsterType = "bugs"}, [{"ancient scarab", "giant spider"}] = {itemReward = 2263, itemCount = 2, killGoal = 2500, storage = 45002, monsterType = "crawly things"}, [{"kollos", "spidris"}] = {itemReward = 2263, itemCount = 3, killGoal = 3500, storage = 45003, monsterType = "bosses"} } local killEvent = CreatureEvent("newOnKillEvent") killEvent:type("kill") function killEvent.onKill(creature, target) if not creature:isPlayer() then return true end if not target:isMonster() then return true end local monsterName = target:getName():lower() for v, k in pairs(config) do if table.contains(v, monsterName) then local currentStorage = creature:getStorageValue(k.storage) if currentStorage >= k.killGoal then return true end currentStorage = currentStorage < 1 and 1 or currentStorage + 1 creature:setStorageValue(k.storage, currentStorage) if currentStorage == k.killGoal then creature:addItem(k.itemReward, k.itemCount) end creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have killed " .. currentStorage .. "/" .. k.killGoal .. " " .. k.monsterType .. ".") return true end end return true end killEvent:register() local loginEvent = CreatureEvent("registerOnKill") loginEvent:type("login") function loginEvent.onLogin(player) player:registerEvent("newOnKillEvent") return true end loginEvent:register()
Thanks you very much.
 
Back
Top