• 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.3] Upgrade System - quest reward

SorketROrk

Well-Known Member
Joined
Oct 14, 2020
Messages
152
Solutions
1
Reaction score
69
Location
Sweden
Hi! :)

I was hoping to get some help with this system - CreatureEvent - [TFS 1.3] Upgrade System (https://otland.net/threads/tfs-1-3-upgrade-system.264672/)

I would like for a player to open a quest chest and get an item with attributes like the ones you get from the upgrade system.

Something like this:
Player opens chest > gets an item, lets say Demon Legs, add item level "200" & set rarity to "Epic or Legendary"
using the functions from the developer notes:

Lua:
item:setItemLevel(item_level, true)
item:rollRarity()
item:setRarity(rarity)

Here is the quest script I have, might not be the best but it works:

Lua:
function onUse(cid, item, frompos, item2, topos)

    if item.itemid == 1740 then
          queststatus = getPlayerStorageValue(cid, 9070)

          if queststatus == -1 then
                     setPlayerStorageValue(cid, 9070, 1)
            doPlayerAddItem(cid, 2495, 1)
            doPlayerSendTextMessage(cid,22,"You have found Demon Legs.")
        else
                doPlayerSendTextMessage(cid, 22, "it is empty.")
        end
     end
       return 1
end

So maybe the player could get a reward of demon legs with item lvl 200 and random rarity or a set rarity, with stats, I appreciate all help, as I would like to learn more about this system myself, hopefully someone can help me out here!


Yours,
SRO
 
Solution
Hey

thanks for replying, im getting:
attempt to index local 'reward' (a number value)

I tried getting help from the scripter and he mentioned to use it like this in some way, maybe it will help solve the problem

Lua:
local item = Game.createItem(itemId, count)
if item then
  item:setItemLevel(chest.itemLevel, true) -- you should have table with rewards for each chest, add itemLevel and use it in code
  player:addItemEx(item)
end

thats just for the itemlevel tho.

/SRO
Lua:
local config ={
    storagevalue = 9070,
    giveitem = 2495,
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1740 then
        local queststatus = player:getStorageValue(config.storagevalue)...
Should definitely look into using proper 1.3 scripting style.

But try this.

Lua:
function onUse(cid, item, frompos, item2, topos)
	if item.itemid == 1740 then
		local queststatus = getPlayerStorageValue(cid, 9070)
		if queststatus == -1 then
			setPlayerStorageValue(cid, 9070, 1)
			local reward = doPlayerAddItem(cid, 2495, 1)
			reward:setItemLevel(200, true)
			reward:setRarity((math.random(3, 4)))
			doPlayerSendTextMessage(cid, 22, "You have found Demon Legs.")
		else
			doPlayerSendTextMessage(cid, 22, "it is empty.")
		end
	end
	return 1
end
 
Should definitely look into using proper 1.3 scripting style.

But try this.

Lua:
function onUse(cid, item, frompos, item2, topos)
    if item.itemid == 1740 then
        local queststatus = getPlayerStorageValue(cid, 9070)
        if queststatus == -1 then
            setPlayerStorageValue(cid, 9070, 1)
            local reward = doPlayerAddItem(cid, 2495, 1)
            reward:setItemLevel(200, true)
            reward:setRarity((math.random(3, 4)))
            doPlayerSendTextMessage(cid, 22, "You have found Demon Legs.")
        else
            doPlayerSendTextMessage(cid, 22, "it is empty.")
        end
    end
    return 1
end
Hey

thanks for replying, im getting:
attempt to index local 'reward' (a number value)

I tried getting help from the scripter and he mentioned to use it like this in some way, maybe it will help solve the problem

Lua:
local item = Game.createItem(itemId, count)
if item then
  item:setItemLevel(chest.itemLevel, true) -- you should have table with rewards for each chest, add itemLevel and use it in code
  player:addItemEx(item)
end

thats just for the itemlevel tho.

/SRO
 
Hey

thanks for replying, im getting:
attempt to index local 'reward' (a number value)

I tried getting help from the scripter and he mentioned to use it like this in some way, maybe it will help solve the problem

Lua:
local item = Game.createItem(itemId, count)
if item then
  item:setItemLevel(chest.itemLevel, true) -- you should have table with rewards for each chest, add itemLevel and use it in code
  player:addItemEx(item)
end

thats just for the itemlevel tho.

/SRO
Lua:
local config ={
    storagevalue = 9070,
    giveitem = 2495,
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1740 then
        local queststatus = player:getStorageValue(config.storagevalue)
        if queststatus == -1 then
            local reward = Game.createItem(config.giveitem, count)
            if reward then
                player:setStorageValue(config.storagevalue,1)
                reward:setItemLevel(200, true)
                reward:setRarity((math.random(3, 4)))
                player:addItemEx(reward)
                player:sendTextMessage(22, "You have found Demon Legs.")
            end
        else
            player:sendTextMessage(22, "it is empty.")
        end
    end
    return 1
end

1610646936809.png
 
Solution
Lua:
local config ={
    storagevalue = 9070,
    giveitem = 2495,
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 1740 then
        local queststatus = player:getStorageValue(config.storagevalue)
        if queststatus == -1 then
            local reward = Game.createItem(config.giveitem, count)
            if reward then
                player:setStorageValue(config.storagevalue,1)
                reward:setItemLevel(200, true)
                reward:setRarity((math.random(3, 4)))
                player:addItemEx(reward)
                player:sendTextMessage(22, "You have found Demon Legs.")
            end
        else
            player:sendTextMessage(22, "it is empty.")
        end
    end
    return 1
end

View attachment 53721
Wow thats an improvement, thank you very much! I got the same results as you :)
I was wondering how I would go about to get an item as reward like the ones dropped by monsters?

Example:
20:26 You see an unidentified demon shield (Def:44).
Item Level: 109
It can only be wielded properly by players of level 109 or higher.
It weighs 26.00 oz.
This powerful shield seems to be as light as air.

If anyone is using this script do you know if this is possible? and if true, how?
 
Not tested, may have some bugs, may not work, the code isn't the best that it could be.
Usage: Place chest/whatever on map with actionid X and uniqueid matching with the REWARD ex. 16000, edit the config to match items, there are some example usages also so good luck.

XML:
<action actionid="X" script="upgrade_system_quest.lua" />

Lua:
local REWARD = {
    [16000] = {
        [1] = {id = 2495, useUpgradeSystem = true, minimumLevel = 100, maximumLevel = 200, minimumRarity = COMMON, maximumRarity = LEGENDARY},
        [2] = (id = 2494, useUpgradeSystem = false}
    },
    [16001] = {
        [1] = {id = 2400, useUpgradeSystem = true, minimumLevel = 100, maximumLevel = 200, isUnidentified = true},
        [2] = (id = 2160, useUpgradeSystem = false, count = 100}
    }
}

local STRING_QUEST_DONE = "It is empty."
local STRING_QUEST_REWARD = "You have found%s."

local QUEST_NOT_COMPLETED = -1
local QUEST_COMPLETED = 1

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local uniqueId = item:getUniqueId()
    local storage = player:getStorageValue(uniqueId)

    if storage ~= QUEST_NOT_COMPLETED then
        player:sendTextMessage(MESSAGE_INFO_DESCR, STRING_QUEST_DONE)
        return true
    end

    player:setStorageValue(uniqueId, QUEST_COMPLETED)
    local rewardText = ""

    for i = 1, #REWARD[uniqueId], 1 do
        local currentItem = REWARD[uniqueId][i]
        local id = currentItem.id
        local itemType = ItemType(id)
        local count = 1
       
        if currentItem.count ~= nil then
            count = currentItem.count
        end
       
        if not itemType:isStackable() then
            count = 1
        end

        local itemObject = Game.createItem(id, count)
       
        if currentItem.useUpgradeSystem and itemType:isUpgradable() then
            itemObject:setItemLevel(math.random(currentItem.minimumLevel, math.random(currentItem.maximumLevel))
            if currentItem.isUnidentified ~= nil and currentItem.isUnidentified then
                itemObject:unidentify()
            else
                itemObject:setRarity(math.random(currentItem.minimumRarity, currentItem].maximumRarity))
            end
        end

        player:addItemEx(itemObject)
        if count > 1 then
            rewardText = rewardText .. string.format(" %i %s", count, itemObject:getPluralName())
        else
            rewardText = rewardText .. string.format(" %s", itemObject:getName())
        end

        if i ~= #REWARD[uniqueId] then
            rewardText = rewardText .. ","
        end
    end

    player:sendTextMessage(MESSAGE_INFO_DESCR, string.format(STRING_QUEST_REWARD, rewardText))
    return true
end
 
Last edited:
Not tested, may have some bugs, may not work, the code isn't the best that it could be.
Usage: Place chest/whatever on map with actionid X and uniqueid matching with the REWARD ex. 16000, edit the config to match items, there are some example usages also so good luck.

XML:
<action actionid="X" script="upgrade_system_quest.lua" />

Lua:
local REWARD = {
    [16000] = {
        [1] = {id = 2495, useUpgradeSystem = true, minimumLevel = 100, maximumLevel = 200, minimumRarity = COMMON, maximumRarity = LEGENDARY},
        [2] = (id = 2494, useUpgradeSystem = false}
    },
    [16001] = {
        [1] = {id = 2400, useUpgradeSystem = true, minimumLevel = 100, maximumLevel = 200, isUnidentified = true},
        [2] = (id = 2160, useUpgradeSystem = false, count = 100}
    }
}

local STRING_QUEST_DONE = "It is empty."
local STRING_QUEST_REWARD = "You have found%s."

local QUEST_NOT_COMPLETED = -1
local QUEST_COMPLETED = 1

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local uniqueId = item:getUniqueId()
    local storage = player:getStorageValue(uniqueId)

    if storage ~= QUEST_NOT_COMPLETED then
        player:sendTextMessage(MESSAGE_INFO_DESCR, STRING_QUEST_DONE)
        return true
    end

    player:setStorageValue(uniqueId, QUEST_COMPLETED)
    local rewardText = ""

    for i = 1, #REWARD[uniqueId], 1 do
        local currentItem = REWARD[uniqueId][i]
        local id = currentItem.id
        local itemType = ItemType(id)
        local count = 1
      
        if currentItem.count ~= nil then
            count = currentItem.count
        end
      
        if not itemType:isStackable() then
            count = 1
        end

        local itemObject = Game.createItem(id, count)
      
        if currentItem.useUpgradeSystem and itemType:isUpgradable() then
            itemObject:setItemLevel(math.random(currentItem.minimumLevel, math.random(currentItem.maximumLevel))
            if currentItem.isUnidentified ~= nil and currentItem.isUnidentified then
                itemObject:unidentify()
            else
                itemObject:setRarity(math.random(currentItem.minimumRarity, currentItem].maximumRarity))
            end
        end

        player:addItemEx(itemObject)
        if count > 1 then
            rewardText = rewardText .. string.format(" %i %s", count, itemObject:getPluralName())
        else
            rewardText = rewardText .. string.format(" %s", itemObject:getName())
        end

        if i ~= #REWARD[uniqueId] then
            rewardText = rewardText .. ","
        end
    end

    player:sendTextMessage(MESSAGE_INFO_DESCR, string.format(STRING_QUEST_REWARD, rewardText))
    return true
end
Thats nice bro, I fixed some typos and now its working perfectly, great that you did add different rewards in a way, learned a lot :D

Thank you!
 
Back
Top