• 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.X+ Change Scripts To Tfs 1.2

Forkz

Well-Known Member
Joined
Jun 29, 2020
Messages
380
Solutions
1
Reaction score
89
Hello,
I need someone to help transform these scripts into TFS 1.2, below.

otland.png

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

local items = {
          item1 = {2177, 2168}
}
local counts = {
          count1 = {1, 1}
}

function creatureSayCallback(cid, type, msg)
          if(not npcHandler:isFocused(cid)) then
                    return false
          end
          local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
          if msgcontains(msg, 'life crystal') then
                    selfSay('You want to swap '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemNameById(items.item1[2]) ..'.',cid)
                    talkState[talkUser] = 1
          elseif talkState[talkUser] == 1 then
                    if msgcontains(msg, 'yes') then
                              if getPlayerItemCount(cid, items.item1[1]) >= counts.count1[1] then
                                        doPlayerRemoveItem(cid, items.item1[1], counts.count1[1])
                                        doPlayerAddItem(cid, items.item1[2], counts.count1[2])
                                        selfSay('You just swap '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..' for '.. counts.count1[2] ..' '.. getItemNameById(items.item1[2]) ..'.', cid)
          talkState[talkUser] = 0
                              else
                                        selfSay('You need '.. counts.count1[1] ..' '.. getItemNameById(items.item1[1]) ..'.', cid)
                              end
                    else
                              selSay('Ok then!', cid)
         talkState[talkUser] = 0
                    end
          end
          return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 

Attachments

Solution
E
okay, if the script in the first post was working, all you need to do is add this line at the end of data/lib/compat/compat.lua

getItemNameById = getItemName
add this to your global.lua
Lua:
function getItemNameById(itemid)
    return getItemDescriptionsById(itemid).name
end
if there another error send it
 
yes, i added.
Post automatically merged:

you don't have the main function too,
Lua:
function getItemDescriptions(uid)
    local thing = getThing(uid)
    if(thing.itemid < 100) then
        return false
    end

    local item = getItemInfo(thing.itemid)
    return {
        name = getItemAttribute(uid, "name") or item.name,
        plural = getItemAttribute(uid, "pluralname") or item.plural,
        article = getItemAttribute(uid, "article") or item.article,
        special = getItemAttribute(uid, "description") or "",
        text = getItemAttribute(uid, "text") or "",
        writer = getItemAttribute(uid, "writer") or "",
        date = getItemAttribute(uid, "date") or 0
    }
end
 
you don't have the main function too,
Lua:
function getItemDescriptions(uid)
    local thing = getThing(uid)
    if(thing.itemid < 100) then
        return false
    end

    local item = getItemInfo(thing.itemid)
    return {
        name = getItemAttribute(uid, "name") or item.name,
        plural = getItemAttribute(uid, "pluralname") or item.plural,
        article = getItemAttribute(uid, "article") or item.article,
        special = getItemAttribute(uid, "description") or "",
        text = getItemAttribute(uid, "text") or "",
        writer = getItemAttribute(uid, "writer") or "",
        date = getItemAttribute(uid, "date") or 0
    }
end
add where is this?
 
no sorry, but i think you just need to add this one too
Lua:
function getItemDescriptionsById(uid)
    local thing = getThing(uid)
    if(thing.itemid < 100) then
        return false
    end

    local item = getItemInfo(thing.itemid)
    return {
        name = getItemAttribute(uid, "name") or item.name,
        plural = getItemAttribute(uid, "pluralname") or item.plural,
        article = getItemAttribute(uid, "article") or item.article,
        special = getItemAttribute(uid, "description") or "",
        text = getItemAttribute(uid, "text") or "",
        writer = getItemAttribute(uid, "writer") or "",
        date = getItemAttribute(uid, "date") or 0
    }   
end

it was a little typo
 
change:

getItemNameById(items.item1[1])

to:

(items.item1[1]):getName()
otland.png
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

local items = {
          item1 = {2177, 2168} -- item1 item que será pedido e que será dado na primeira troca
}
local counts = {
          count1 = {1, 1} -- count1 quantidade que será pedido e que será dado na primeira troca
}

function creatureSayCallback(cid, type, msg)
          if(not npcHandler:isFocused(cid)) then
                    return false
          end
          local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
          if msgcontains(msg, 'life crystal') then
                    selfSay('You want to swap '.. counts.count1[1] ..' '.. (items.item1[1]):getName() ..' for '.. counts.count1[2] ..' '.. getItemNameById(items.item1[2]) ..'.',cid)
                    talkState[talkUser] = 1
          elseif talkState[talkUser] == 1 then
                    if msgcontains(msg, 'yes') then
                              if getPlayerItemCount(cid, items.item1[1]) >= counts.count1[1] then
                                        doPlayerRemoveItem(cid, items.item1[1], counts.count1[1])
                                        doPlayerAddItem(cid, items.item1[2], counts.count1[2])
                                        selfSay('You just swap '.. counts.count1[1] ..' '.. (items.item1[1]):getName() ..' for '.. counts.count1[2] ..' '.. getItemNameById(items.item1[2]) ..'.', cid)
          talkState[talkUser] = 0
                              else
                                        selfSay('You need '.. counts.count1[1] ..' '.. (items.item1[1]):getName() ..'.', cid)
                              end
                    else
                              selSay('Ok then!', cid)
         talkState[talkUser] = 0
                    end
          end
          return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
no sorry, but i think you just need to add this one too
Lua:
function getItemDescriptionsById(uid)
    local thing = getThing(uid)
    if(thing.itemid < 100) then
        return false
    end

    local item = getItemInfo(thing.itemid)
    return {
        name = getItemAttribute(uid, "name") or item.name,
        plural = getItemAttribute(uid, "pluralname") or item.plural,
        article = getItemAttribute(uid, "article") or item.article,
        special = getItemAttribute(uid, "description") or "",
        text = getItemAttribute(uid, "text") or "",
        writer = getItemAttribute(uid, "writer") or "",
        date = getItemAttribute(uid, "date") or 0
    }  
end

it was a little typo
there is no getItemAttribute function in tfs 1.x
Post automatically merged:

@Forkz
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

local items = {
    item1 = {2177, 2168} -- item1 item que será pedido e que será dado na primeira troca
}
local counts = {
    count1 = {1, 1} -- count1 quantidade que será pedido e que será dado na primeira troca
}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if msgcontains(msg, 'life crystal') then
        selfSay('You want to swap '.. counts.count1[1] ..' '.. (items.item1[1]):getName() ..' for '.. counts.count1[2] ..' '.. (items.item1[2]):getName() ..'.',cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'yes') then
            if getPlayerItemCount(cid, items.item1[1]) >= counts.count1[1] then
                doPlayerRemoveItem(cid, items.item1[1], counts.count1[1])
                doPlayerAddItem(cid, items.item1[2], counts.count1[2])
                selfSay('You just swap '.. counts.count1[1] ..' '.. (items.item1[1]):getName() ..' for '.. counts.count1[2] ..' '.. (items.item1[2]):getName() ..'.', cid)
                talkState[talkUser] = 0
            else
                selfSay('You need '.. counts.count1[1] ..' '.. (items.item1[1]):getName() ..'.', cid)
                end
        else
            selSay('Ok then!', cid)
            talkState[talkUser] = 0
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
there is no getItemAttribute function in tfs 1.x
Post automatically merged:

@Forkz
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

local items = {
    item1 = {2177, 2168} -- item1 item que será pedido e que será dado na primeira troca
}
local counts = {
    count1 = {1, 1} -- count1 quantidade que será pedido e que será dado na primeira troca
}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if msgcontains(msg, 'life crystal') then
        selfSay('You want to swap '.. counts.count1[1] ..' '.. (items.item1[1]):getName() ..' for '.. counts.count1[2] ..' '.. (items.item1[2]):getName() ..'.',cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'yes') then
            if getPlayerItemCount(cid, items.item1[1]) >= counts.count1[1] then
                doPlayerRemoveItem(cid, items.item1[1], counts.count1[1])
                doPlayerAddItem(cid, items.item1[2], counts.count1[2])
                selfSay('You just swap '.. counts.count1[1] ..' '.. (items.item1[1]):getName() ..' for '.. counts.count1[2] ..' '.. (items.item1[2]):getName() ..'.', cid)
                talkState[talkUser] = 0
            else
                selfSay('You need '.. counts.count1[1] ..' '.. (items.item1[1]):getName() ..'.', cid)
                end
        else
            selSay('Ok then!', cid)
            talkState[talkUser] = 0
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
otland.png
Perhaps the item quantity would not have to stay in the same position?
 
okay, if the script in the first post was working, all you need to do is add this line at the end of data/lib/compat/compat.lua

getItemNameById = getItemName
 
Solution
Back
Top