• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Problem with action script

wafuboe

Active Member
Joined
Dec 24, 2010
Messages
884
Solutions
2
Reaction score
26
Hello i got this problem from a action script that upgrade items
this appears in console
any help ill appreciate it

dxl9ac.png

Script:
Code:
local conf = {
    ["level"] = {
        -- [item_level] = {successPercent= CHANCE TO UPGRADE ITEM, downgradeLevel = ITEM GETS THIS LEVEL IF UPGRADE FAILS}
        [1] = {successPercent = 85, downgradeLevel = 0},
        [2] = {successPercent = 80, downgradeLevel = 1},
        [3] = {successPercent = 75, downgradeLevel = 2},
        [4] = {successPercent = 70, downgradeLevel = 3},
        [5] = {successPercent = 65, downgradeLevel = 4},
        [6] = {successPercent = 60, downgradeLevel = 5},
        [7] = {successPercent = 55, downgradeLevel = 0},
        [8] = {successPercent = 50, downgradeLevel = 0},
        [9] = {successPercent = 45, downgradeLevel = 0}
    },
    ["upgrade"] = { -- how many percent attributes are rised?
        attack = 5, -- attack %
        defense = 5, -- defense %
        extraDefense = 10, -- extra defense %
        armor = 5, -- armor %
        hitChance = 5, -- hit chance %
    }
}
-- // do not touch // --
-- Upgrading system by Azi [Ersiu] --
-- Edited for TFS 1.1 by Zbizu --
local upgrading = {
    upValue = function (value, level, percent)
    if value < 0 then return 0 end
    if level == 0 then return value end
    local nVal = value
    for i = 1, level do
        nVal = nVal + (math.ceil((nVal / 100 * percent)))
    end
        return nVal > 0 and nVal or value
    end,
    getLevel = function (item)
    local name = Item(item):getName():split('+')
    if (#name == 1) then
        return 0
    end
    return math.abs(name[2])
  end,
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local it, itx = ItemType(itemEx.itemid), itemEx.uid
    if ((it:getWeaponType() > 0 or itemEx.uid:getAttribute(ITEM_ATTRIBUTE_ARMOR) > 0) and not it:isStackable()) then
        local level = upgrading.getLevel(itx)
        if(level < #conf["level"])then
            local nLevel = (conf["level"][(level + 1)].successPercent >= math.random(1, 100)) and (level + 1) or conf["level"][level].downgradeLevel
            if(nLevel > level)then
                toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Upgrade to level " .. nLevel .. " successful!")
            else
                toPosition:sendMagicEffect(CONST_ME_BLOCKHIT)
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Upgrade failed. Your " .. it:getName() .. " is now on level " .. nLevel .. "")
            end
            itx:setAttribute(ITEM_ATTRIBUTE_NAME, it:getName()..((nLevel>0) and "+"..nLevel or ""))
            itx:setAttribute(ITEM_ATTRIBUTE_ATTACK, upgrading.upValue(it:getAttack(), nLevel, conf["upgrade"].attack))
            itx:setAttribute(ITEM_ATTRIBUTE_DEFENSE, upgrading.upValue(it:getDefense(), nLevel, conf["upgrade"].defense))
            itx:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, upgrading.upValue(it:getExtraDefense(), nLevel, conf["upgrade"].extraDefense)
            itx:setAttribute(ITEM_ATTRIBUTE_ARMOR, upgrading.upValue(it:getArmor(), nLevel, conf["upgrade"].armor))
            itx:setAttribute(ITEM_ATTRIBUTE_HITCHANCE, upgrading.upValue(it:getHitChance(), nLevel, conf["upgrade"].hitChance))
            item.uid:remove(1)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Your " .. it:getName() .. " is on max level alredy.")
        end
    else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot upgrade this item.")
    end
end
Also i got this mining script and i have this problem
29z20d1.png

Code:
terra = {351,352,353,354,355}
levels = {
[-1] = 2229, ---- skull
[0] = 1294, --- small stone
[1] = 3976, --- worm
[10] = 2149, -- Small Emerald
[12] = 2146, -- Small Sapphire
[15] = 2145, -- Small Diamond
[17] = 2150, -- Small Amethyst
[20] = 2147, -- Small Ruby
[25] = 2144, -- Black Pearls
[27] = 2143, -- White Pearls
[30] = 2157, -- Gold Nuggets
[35] = 2156, --- red gem
[36] = 2158, -- blue gem
[37] = 2155, -- green gem
[38] = 2153, -- violet gem
[39] = 2154, -- yellow gem
[40] = 7761, -- small enchanted emerald
[42] = 7759, -- Small Enchanted Sapphiire
[45] = 7762, -- Small Enchanted Amethyst
[50] = 7760, -- Small Enchanted Ruby
[70] = 2177  -- Life Crystal
}


local config = {
storage = 19333,
chance = 40, --- chance de achar um item ou não
k = 2, --- constante de level.. quanto maior, mais fácil é upar. (a fórmula é level ao quadrado dividido pela constante)
experience = 19334
}


function onUse(cid, item, fromPosition, itemEx, toPosition)


local drops = {}


function getDrops(cid)
for i= -1,getPlayerStorageValue(cid, config.storage) do
if levels[i] then
table.insert(drops, levels[i])
end
end
return true
end


if isInArray(terra, itemEx.itemid) then
getDrops(cid)
doPlayerSetStorageValue(cid, config.experience, getPlayerStorageValue(cid, config.experience)+1)
local experience = getPlayerStorageValue(cid, config.experience)
if experience >= (8+(getPlayerStorageValue(cid, config.storage)^2))/config.k then
doPlayerSetStorageValue(cid, config.storage, getPlayerStorageValue(cid, config.storage)+1)
doPlayerSendTextMessage(cid, 27, "Congratulations, you have leveled! Your currect level is "..getPlayerStorageValue(cid, config.storage) ..".")
if getPlayerStorageValue(cid, config.storage) == 50 then
doPlayerSendTextMessage(cid, 20, "For reaching level "..getPlayerStorageValue(cid, config.storage) .." you have been awarded with Mining Helmet.")
doPlayerAddItem(cid, 7497, 1, true)
end
end
if config.chance >= math.random(1,100) then
if #drops >= 1 then
local item = drops[math.random(1,#drops)]
doPlayerSendTextMessage(cid, 27, "You have found a "..getItemNameById(item)..".")
doPlayerAddItem(cid, item, 1, true)
end
doSendMagicEffect(toPosition, 3)
else
doSendMagicEffect(toPosition, 2)
return true
end
elseif itemEx.itemid == item.itemid then
doPlayerSendTextMessage(cid, 27, "You're currenctly level "..getPlayerStorageValue(cid, config.storage)..".")
else
return false
end
return true
end

Im using TFS 1.3

thank you
 
Last edited:
add a ) at the end of itx:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, upgrading.upValue(it:getExtraDefense(), nLevel, conf["upgrade"].extraDefense)
your 2nd error means you need to use player:setStorageValue, not the old functions
if you insist on using the old functions however, throw this in your compat.lua
LUA:
function doPlayerSetStorageValue(cid, key, value) local p = Player(cid) if player then p:setStorageValue(key, value) end end
 
add a ) at the end of itx:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, upgrading.upValue(it:getExtraDefense(), nLevel, conf["upgrade"].extraDefense)
your 2nd error means you need to use player:setStorageValue, not the old functions
if you insist on using the old functions however, throw this in your compat.lua
LUA:
function doPlayerSetStorageValue(cid, key, value) local p = Player(cid) if player then p:setStorageValue(key, value) end end

i got this error on upgrade script
106kpkp.png


i think im kind of confuse of the functions and tfs version in my console at the start it says that is TFS 1.3 is it compatible with 1.2, 1.1 scripts? can you explain a little bit of this if you dont mind?
 
it's mostly compatible but you're not using a 1.2 or 1.1 script, you're using an 0.x script which uses cid and not player
that's why you get that error, just use my 2nd solution with the compat.lua function instead so you don't haave to bother upgrading it
 
it's mostly compatible but you're not using a 1.2 or 1.1 script, you're using an 0.x script which uses cid and not player
that's why you get that error, just use my 2nd solution with the compat.lua function instead so you don't haave to bother upgrading it

i put it on the end of compat.lua and im getting the same error :/
 
i put it on the end of compat.lua and im getting the same error :/
are you still trying to use player:setStorageValue?
if so that's wrong and not what i'm telling you to do with this compat function
put your old script back the way it was and put the compat function inside of compat.lua and it will work fine, it won't tell you that doSetPlayerStorageValue is a nil value.
 
Line 59
Change to:
LUA:
itx:setAttribute(ITEM_ATTRIBUTE_EXTRADEFENSE, upgrading.upValue(it:getExtraDefense(), nLevel, conf["upgrade"].extraDefense))

Mining TFS 1.3 (NOT TESTED)

LUA:
terra = {351, 352, 353, 354, 355}
levels = {
    [-1] = 2229, ---- skull
    [0] = 1294, --- small stone
    [1] = 3976, --- worm
    [10] = 2149, -- Small Emerald
    [12] = 2146, -- Small Sapphire
    [15] = 2145, -- Small Diamond
    [17] = 2150, -- Small Amethyst
    [20] = 2147, -- Small Ruby
    [25] = 2144, -- Black Pearls
    [27] = 2143, -- White Pearls
    [30] = 2157, -- Gold Nuggets
    [35] = 2156, --- red gem
    [36] = 2158, -- blue gem
    [37] = 2155, -- green gem
    [38] = 2153, -- violet gem
    [39] = 2154, -- yellow gem
    [40] = 7761, -- small enchanted emerald
    [42] = 7759, -- Small Enchanted Sapphiire
    [45] = 7762, -- Small Enchanted Amethyst
    [50] = 7760, -- Small Enchanted Ruby
    [70] = 2177  -- Life Crystal
}
local config = {
    storage = 19333,
    chance = 40, --- chance de achar um item ou não
    k = 2, --- constante de level.. quanto maior, mais fácil é upar. (a fórmula é level ao quadrado dividido pela constante)
    experience = 19334
}

function getDrops(cid)
    for i = -1, cid:getStorageValue(config.storage) do
        if levels[i] then
            table.insert(drops, levels[i])
        end
    end
    return true
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local drops = {}
     if table.contains(terra, itemEx.itemid) then
         getDrops(player.uid)
         player:setStorageValue(config.experience, math.max(0, player:getStorageValue(config.experience)) + 1)
         local experience = player:getStorageValue(config.experience)
         if experience >= (8 + (player:getStorageValue(config.storage) ^ 2)) / config.k then
             player:setStorageValue(config.experience, math.max(0, player:getStorageValue(config.experience)) + 1)
             player:sendTextMessage(27, "Congratulations, you have leveled! Your currect level is "..player:getStorageValue(config.storage) ..".")
             if player:getStorageValue(config.storage) == 50 then
                 player:sendTextMessage(20, "For reaching level "..player:getStorageValue(config.storage) .." you have been awarded with Mining Helmet.")
                 player:addItem(7497, 1, true)
             end
         end
         if config.chance >= math.random(1, 100) then
             if #drops >= 1 then
                 local item = drops[math.random(1, #drops)]
                 player:sendTextMessage(27, "You have found a "..item:getName()..".")
                 player:addItem(item, 1, true)
             end
             toPosition:sendMagicEffect(CONST_ME_POFF)
         else
             toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
             return true
         end
     elseif itemEx.itemid == item.itemid then
         player:sendTextMessage(27, "You're currenctly level "..player:getStorageValue(config.storage)..".")
     else
         return false
     end
     return true
end
 
Last edited:
are you still trying to use player:setStorageValue?
if so that's wrong and not what i'm telling you to do with this compat function
put your old script back the way it was and put the compat function inside of compat.lua and it will work fine, it won't tell you that doSetPlayerStorageValue is a nil value.

i used the old script and compat stuff you mention, it kind of works. it says that it advanced to lvl 1 but nothing happens

2yvsc2r.png
 
i used the old script and compat stuff you mention, it kind of works. it says that it advanced to lvl 1 but nothing happens

2yvsc2r.png
put this in compat.lua
LUA:
function doItemSetAttribute(uid, key, value)
    local item = Item(uid)
    if item then
        item:setAttribute(key, value)
    end
end
 
Back
Top