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())
no work
BUMP !! ANY ONE HELP !
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())
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())
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())