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

SOLVED

Hello Otlanders ,
I use this script but i need add something.
this npc take gold nuggets only and i need to add more items to this script.
i use tfs 0.3.6
Tibia 8.6
Here is The Script.
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local t = {}

local item = 6527 -- item id
local count = 150 -- count of itemID
local points = 5 -- amount of premium points

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
elseif msgcontains(msg, 'change') then
selfSay('are you sure you want to change '.. count ..' of '.. getItemNameById(item) ..' for '.. points ..' premium points?', cid)
t[cid] = 1
elseif t[cid] == 1 then
npcHandler:releaseFocus(cid)
t[cid] = nil
if msgcontains(msg, 'yes') then
if doPlayerRemoveItem(cid, item, count) then
local p = "UPDATE `accounts` SET `premium_points` = `premium_points` + "..points.." where id="..getPlayerAccountId(cid)
db.executeQuery(p)
selfSay('you have recieved '.. points ..' premium points', cid)
else
selfSay('you don\'t have enough coins you need '.. count ..' of '.. getItemNameById(item) ..' to recieve '.. points ..' premium points', cid)
end
end
end
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


Best way would be to make item into a table like this:

local item = {
6527,
2160, --- example using crystal coin
}

Then ask the player what item they wish to trade for points, then check if the player has that item, don't know the correct functions for your server, but check if the player has that item, then if they do, make npc ask if they want to trade for points, then if they say yes, then remove the that item from the player... I don't really know your functions, this is an easy one though, if no one else has posted the pieces of code you need, when I get home I will check it out for you...
 
no work :(
BUMP !! ANY ONE HELP !


Sorry man, don't use 0.3.6 and don't really support it, but I forgot I said I would help. I didn't do a very advanced way, took the lazy way, but it's meant to be an example so you can start building the table and the script. I don't know if it works, like I said I don't use 0.3.6 so test this and let me know...


Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local t = {}

local item = {
6527,
2160, -- crystal coin example
}
local count = 150 -- count of itemID
local points = 5 -- amount of premium points

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
elseif msgcontains(msg, 'change') then
    if getPlayerItemCount(cid, item[1]) ~=0 or getPlayerItemCount(cid, item[2]) ~= 0 then  --- here we check for either item in the table
selfSay('are you sure you want to change '.. count ..' of '.. getItemNameById(item) ..' for '.. points ..' premium points?', cid)
t[cid] = 1
else
---- here you would want to send a cancel message since the player doesn't have 1 of either item
end
elseif t[cid] == 1 then
npcHandler:releaseFocus(cid)
t[cid] = nil
if msgcontains(msg, 'yes') then
if doPlayerRemoveItem(cid, item, count) then
local p = "UPDATE `accounts` SET `premium_points` = `premium_points` + "..points.." where id="..getPlayerAccountId(cid)
db.executeQuery(p)
selfSay('you have recieved '.. points ..' premium points', cid)
else
selfSay('you don\'t have enough coins you need '.. count ..' of '.. getItemNameById(item) ..' to recieve '.. points ..' premium points', cid)
end
end
end
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
not tested
Code:
local table = {
  ["what player sayss"] = { points = 1, itemid = 2675, amount = 10},
  ["what player says2"] = { points = 2, itemid = 2159, amount = 10}
}

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 
     if table[msg] then 
      local t = table[msg] 
      talkState[talkUser] = 1  
         if doPlayerTakeItem(cid, t.itemid, t.amount) then
    local p = "UPDATE `accounts` SET `premium_points` = `premium_points` + "..t.points.." where id="..getPlayerAccountId(cid) 
          db.executeQuery(p) 
          selfSay("You just traded ".. t.amount .." " .. getItemNameById(t.itemid) .. ".", cid)
          talkState[talkUser] = 0 
         else 
          selfSay("I am sorry You need ".. t.amount .." " .. getItemNameById(t.itemid) .. ".", cid) 
          talkState[talkUser] = 0 
         end  
    else 
    selfSay("I am sorry You need ".. t.amount .." " .. getItemNameById(t.itemid) .. ".", cid)
    talkState[talkUser] = 0 
   end 
   return true 
end 

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) 
npcHandler:addModule(FocusModule:new())
 
or if you can make him allow you to say yes / no use this one i dont have much time right now but yeah it has something to do with
t[cid] == 1 --line 24
t[cide] -- line 23
PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local t = {
-- {"offer name", item id, Amount, Points gicen} --
    {'crystal', 2160, 100, 1},
    {'emerald', 2160, 200, 2}
}

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)
for _, cid in ipairs(getPlayersOnline()) do
        for i = 1, #t do
if not npcHandler:isFocused(cid) then
return false
elseif msgcontains(msg, t[i][1]) then
selfSay('are you sure you want to change '.. t[i][3] ..' '.. getItemNameById(t[i][2]) ..' for '.. t[i][4] ..' premium points?', cid)
t[cid] = 2
elseif t[cid] == 1 then
npcHandler:releaseFocus(cid)
t[cid] = nil
if msgcontains(msg, 'yes') then
if doPlayerRemoveItem(cid, t[i][2], t[i][3]) then
local p = "UPDATE `accounts` SET `premium_points` = `premium_points` + "..t[i][4].." where id="..getPlayerAccountId(cid)
db.executeQuery(p)
selfSay('you have recieved '.. t[i][4] ..' premium points', cid)
else
selfSay('you don\'t have enough coins you need '.. t[i][3] ..' of '.. getItemNameById(t[i][2]) ..' to recieve '.. t[i][4] ..' premium points', cid)
                end
            end
        end
    end
end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I want the npc to take the 2 items with amount and give 5 points and if someone can make it a limit number of exchange like only 5 exchanges for per acc i will be happy
 
Back
Top