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

[TFS 1.3] [Action] Raise item level with item

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,713
Solutions
31
Reaction score
965
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Last edited:
Solution
Not tested since I don't have that system installed anywhere but this should work 🤔
The item that will upgrade target items ofc needs to be useWith (IE: a pick)
LUA:
local itemLimit = 5 -- Max level that this item can upgrade target item.
local successChance = 50 -- 50% chance to success.
local reduceLevelOnFail = false -- Set to true to reduce level of the item on fail.
local removeItemOnFail = false -- Set to true to remove the item if you fail to upgrade your target item.

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target:isItem() then
        return false
    end

    math.randomseed(os.time() + tonumber(tostring({}):sub(8)))
    local rand = math.random(1, 100)
    local itemLevel =...
I did an attempt to do something.. im not good at all :/
LUA:
local storage = 10002
local iLvl = 1
local items = {
[1] = {itemid = 2383, count = 1},
[2] = {itemid = 2393, count = 1},
}

function onUse(player, item, fromPosition, target, toPosition)
     if player:getStorageValue(storage) ~= -1 then
          return player:sendCancelMessage("You cannot use this item more than once.")
     end

for i = 1, #items do
     player:addItem(items[i].itemid, items[i].count)
     item:setItemLevel(math.min(US_CONFIG.MAX_ITEM_LEVEL, math.random(math.max(1, iLvl - 5), iLvl)), true)
end
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have received your items!")
--player:setStorageValue(storage, 1)
return true
end

Is this too bad? Please give me some hints I will really appreciate! Its supposed to change Item Level attribute, but I dont know how to call that attribute, the idea of the script is an action that should give 2 items with random Item Level
 
In your script, you should be creating a variable for the returned item from Player.addItem, and use that as the object for the setItemLevel method. Aka, do something like:
LUA:
local newItem = player:addItem(items[i].itemid, items[i].count)
newItem:setItemLevel(stuff...)
 
Not tested since I don't have that system installed anywhere but this should work 🤔
The item that will upgrade target items ofc needs to be useWith (IE: a pick)
LUA:
local itemLimit = 5 -- Max level that this item can upgrade target item.
local successChance = 50 -- 50% chance to success.
local reduceLevelOnFail = false -- Set to true to reduce level of the item on fail.
local removeItemOnFail = false -- Set to true to remove the item if you fail to upgrade your target item.

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target:isItem() then
        return false
    end

    math.randomseed(os.time() + tonumber(tostring({}):sub(8)))
    local rand = math.random(1, 100)
    local itemLevel = target:getItemLevel()

    if itemLevel >= itemLimit then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You have reached the limit to upgrade your item, which is "..itemLimit.."!")
        return false
    end

    if rand <= successChance then
        local plusLevel = itemLevel + 1
        target:setItemLevel(plusLevel, true)
        item:remove(1)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You have upgraded your item from level "..itemLevel.." to level "..plusLevel.."!")
    elseif rand > successChance and reduceLevelOnFail and itemLevel > 1 then
        local minusLevel = itemLevel - 1
        target:setItemLevel(minusLevel, true)
        if removeItemOnFail then
            item:remove(1)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "Upgrade failed! Your item has been downgraded to Level "..minusLevel.."!")
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "Upgrade failed! Your item has been downgraded to Level "..minusLevel.."!")
        end
    elseif rand > successChance and not reduceLevelOnFail then
        if removeItemOnFail then
            item:remove(1)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "Upgrade failed!")
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "Upgrade failed!")
        end
    end
    return true
end

PS: You look kinda like Rubius
 
Last edited:
Solution
In your script, you should be creating a variable for the returned item from Player.addItem, and use that as the object for the setItemLevel method. Aka, do something like:
LUA:
local newItem = player:addItem(items[i].itemid, items[i].count)
newItem:setItemLevel(stuff...)

thanks!! I'll try, this things make me think more than the usual xD

Not tested since I don't have that system installed anywhere but this should work 🤔
(....)

Im so happy to see is working!!😁 really, Thanks a lot!!
This are the results from testing, still missing something, the limit to upgrade is being ignored... You can use the object even if you reached level 5 of upgrading, infinite times

test.pngtest2.png

PS: You look kinda like Rubius

You're the second person who told me xD, maybe it's true
 
thanks!! I'll try, this things make me think more than the usual xD



Im so happy to see is working!!😁 really, Thanks a lot!!
This are the results from testing, still missing something, the limit to upgrade is being ignored... You can use the object even if you reached level 5 of upgrading, infinite times

View attachment 40919View attachment 40920



You're the second person who told me xD, maybe it's true
You're right, I forgot something, copy again the script, should work correctly now.
Also if after that the script is 100% working do remember to mark that answer as best answer and mark the thread as solved :P.
 

Similar threads

Back
Top