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

Convert script to tfs 1.3

jel

Member
Joined
Mar 22, 2014
Messages
209
Reaction score
8
good, can someone convert these scripts to tfs 1.3?

Lua:
configurations = {
    Storage = 98170, -- storage utilizada pelo sistema para armazenar os items disponiveis para venda no npc
}


-- Tabela de items a serem comprados pelo Npc --
tb_Items = {
--  [ITEMID] = {price = PRECO QUE O NPC VAI PAGAR AO PLAYER, newPrice = PRECO QUE O NPC VAI VENDER O ITEM}
    [15803] = {price = 10, newPrice = 20}, -- Sapphire Shield
    [15804] = {price = 10, newPrice = 20}, -- Pearl Shield
}


-------- Nao mexa daqui para baixo se não souber
function setStorageTable(storage, tab)
    local tabstr = "&"
    for i,x in pairs(tab) do
        tabstr = tabstr .. i .. "," .. x.itemid .. ","..x.count..";"
    end
    setGlobalStorageValue(storage, tabstr:sub(1, #tabstr-1))
end

function getStorageTable(storage)
    local tabstr = getGlobalStorageValue(storage)
    local tab = {}
    if type(tabstr) ~= "string" then
        return {}
    end
    if tabstr:sub(1,1) ~= "&" then
        return {}
    end
    local tabstr = tabstr:sub(2, #tabstr)
    local a = string.explode(tabstr, ";")
    for i,x in pairs(a) do
        local b = string.explode(x, ",")
        table.insert(tab, {itemid = tonumber(b[2]) or b[2], count = tonumber(b[3]) or b[3]})
    end
    return tab
end

function isInNpcTable(item, tb)
    for _,i in pairs(tb)do
        if tonumber(i.id) == tonumber(item) then
            return true
        end
    end
    return false
end

function addNpcItemTable(item, count)
    local x = getStorageTable(configurations.storage)
    local exist = false
    for v, k in pairs(x) do
        if tonumber(k.itemid) == tonumber(item) then
            k.count = k.count + count
            exist = true
        end
    end
    if not exist then
        table.insert(x,{itemid = tonumber(item), count = count})
        setStorageTable(configurations.storage, x)
    end
    return setStorageTable(configurations.storage, x)
end

function removeNpcItemTable(item, count)
    local x = getStorageTable(configurations.storage)
    for i,v in ipairs(x) do
        if tonumber(v.itemid) == tonumber(item) then
            if v.count > count then
                v.count = v.count - count
            else
                table.remove(x,i)
            end
        end
    end
    return setStorageTable(configurations.storage, x)
end

function attNpcItemsList(cid)
local tb = {}
local npc_items = getStorageTable(configurations.storage)
    for var, ret in pairs(tb_Items) do
        for v, k in pairs(npc_items) do
            if not isInNpcTable(k.itemid, tb) and not isInNpcTable(var, tb) then
                if var == k.itemid then
                    if getItemInfo(k.itemid).stackable == true then
                        if k.count > 500 then
                            table.insert(tb, {id = var, subType = 0, sell = ret.price*0.5, name = getItemNameById(var)})
                        elseif k.count > 400 then
                            table.insert(tb, {id = var, subType = 0, sell = ret.price*0.6, name = getItemNameById(var)})
                        elseif k.count > 300 then
                            table.insert(tb, {id = var, subType = 0, sell = ret.price*0.7, name = getItemNameById(var)})
                        elseif k.count > 200 then
                            table.insert(tb, {id = var, subType = 0, sell = ret.price*0.8, name = getItemNameById(var)})
                        elseif k.count > 100 then
                            table.insert(tb, {id = var, subType = 0, sell = ret.price*0.9, name = getItemNameById(var)})
                        else
                            table.insert(tb, {id = var, subType = 0, sell = ret.price, name = getItemNameById(var)})
                        end
                    else
                        if k.count > 50 then
                            table.insert(tb, {id = var, subType = 0, sell = ret.price*0.5, name = getItemNameById(var)})
                        elseif k.count > 40 then
                            table.insert(tb, {id = var, subType = 0, sell = ret.price*0.6, name = getItemNameById(var)})
                        elseif k.count > 30 then
                            table.insert(tb, {id = var, subType = 0, sell = ret.price*0.7, name = getItemNameById(var)})
                        elseif k.count > 20 then
                            table.insert(tb, {id = var, subType = 0, sell = ret.price*0.8, name = getItemNameById(var)})
                        elseif k.count > 10 then
                            table.insert(tb, {id = var, subType = 0, sell = ret.price*0.9, name = getItemNameById(var)})
                        else
                            table.insert(tb, {id = var, subType = 0, sell = ret.price, name = getItemNameById(var)})
                        end
                    end
                end
            end
        end
        if not isInNpcTable(var, tb) then
            table.insert(tb, {id = var, subType = 0, sell = ret.price, name = getItemNameById(var)})
        end
    end
    for var, ret in pairs(tb_Items) do
        for v, k in pairs(npc_items) do
            if var == k.itemid then
                table.insert(tb, {id = k.itemid, subType = 0, buy = ret.newPrice, count = k.count, name = getItemNameById(k.itemid)})
            end
        end
    end
return tb
end

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
    local shopWindow = {}
    onSelling = function(cid, item, subType, amount, ignoreCap, inBackpacks)
        local store,exausted = 552612,3
        local priceTicks = tb_Items[item].price*amount
        if getPlayerStorageValue(cid, store) >= os.time() then
            doPlayerSendCancel(cid, "Espere " .. getPlayerStorageValue(cid, store) - os.time() .. " segundos para vender seus items.") return true
        end
        if doPlayerRemoveItem(cid, item, amount) then
            doPlayerAddMoney(cid, priceTicks)
            npcHandler:say("Voce vendeu " .. amount .. "x " .. getItemNameById(item) .. " por " .. priceTicks .. " yens.", cid)
            setPlayerStorageValue(cid, store, os.time()+exausted)
            addNpcItemTable(item, amount)
            closeShopWindow(cid)
            local shop = attNpcItemsList(cid)
            openShopWindow(cid, shop, onBuying, onSelling)
        end
        
        return true
    end

    onBuying = function(cid, item, subType, amount, ignoreCap, inBackpacks)
        local store,exausted = 552612,3
        local priceTicks = nil
        priceTicks = tb_Items[item].newPrice*amount
        if getPlayerStorageValue(cid, store) >= os.time() then
            doPlayerSendCancel(cid, "Espere " .. getPlayerStorageValue(cid, store) - os.time() .. " segundos para vender seus items.") return true
        end
        local npc_items = getStorageTable(configurations.storage)
            for v, k in pairs(npc_items) do
                if k.itemid == item then
                    if k.count >= amount then
                        if doPlayerRemoveMoney(cid, priceTicks) then
                            doPlayerAddItem(cid, item, amount)
                            npcHandler:say("Voce comprou " .. amount .. "x " .. getItemNameById(item) .. " por " .. priceTicks .. " yens.", cid)
                            setPlayerStorageValue(cid, store, os.time()+exausted)
                            removeNpcItemTable(item, amount)
                            closeShopWindow(cid)
                            local shop = attNpcItemsList(cid)
                            openShopWindow(cid, shop, onBuying, onSelling)
                        else
                            npcHandler:say("Voce nao possui dinheiro suficiente.", cid)
                        end
                    else
                        npcHandler:say("Lamento, mas atualmente eu so possuo: "..k.count.."x "..getItemNameById(k.itemid)..".", cid)
                    end
                end
            end
        
        return true
    end

    if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
        shopWindow = attNpcItemsList(cid)
        openShopWindow(cid, shopWindow, onBuying, onSelling)
    end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Top