Lopaskurwa
Active Member
- Joined
- Oct 6, 2017
- Messages
- 873
- Solutions
- 2
- Reaction score
- 49
Hi
how can i set x requirement amount to craft a item like x100 Addon doll because now you it doesnt have a function to set amount
TFS 1.2
how can i set x requirement amount to craft a item like x100 Addon doll because now you it doesnt have a function to set amount
TFS 1.2
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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 config =
{
[1] =
{
name = 'Mage Helmet',
itemsRequired = {'Addon doll', 'leaf', 'yalahari mask', 'Outfiter', 'RS Remover'} -- qty is always 1. you can add here as many items as you want
},
[2] =
{
name = 'Knight Donate UH',
itemsRequired = {'Addon doll', 'warlord sword', 'demon helmet', 'Outfiter', 'RS Remover'}
},
[3] =
{
name = 'Paladin Donate UH/MR',
itemsRequired = {'Addon doll', 'arbalest', 'demon helmet', 'Outfiter', 'RS Remover'}
}
}
local Topic = {}
local function checkItems(cid, table)
for _, item in ipairs(table) do
if Player(cid):getItemCount(ItemType(item):getId()) == 0 then
return false
end
end
return true
end
local function removeItems(cid, table)
for _, item in ipairs(table) do
Player(cid):removeItem(ItemType(item):getId(), 1)
end
end
function creatureSayCallback(cid, type, msg)
msg = msg:lower()
if not npcHandler:isFocused(cid) then
return false
elseif msgcontains(msg, 'runes') then
local str = 'I can craft for you all these runes: '
for _, item in ipairs(config) do
if _ ~= #config - 1 then
str = str .. '{' .. item.name:lower() .. '}, '
else
str = str .. '{' .. item.name:lower() .. '} and '
end
end
str = str:sub(1, str:len() - 2)
str = str .. '.'
npcHandler:say(str, cid)
elseif Topic[cid] ~= nil then
if msgcontains(msg, 'yes') then
if checkItems(cid, config[Topic[cid]].itemsRequired) then
removeItems(cid, config[Topic[cid]].itemsRequired)
Player(cid):addItem(ItemType(config[Topic[cid]].name):getId(), 1)
npcHandler:say('Thank you very much! Come back anytime you want!!', cid)
Topic[cid] = nil
else
npcHandler:say('Do not waste my time.', cid)
Topic[cid] = nil
end
else
npcHandler:say('Do not waste my time.', cid)
Topic[cid] = nil
end
else
for _, item in ipairs(config) do
if msgcontains(msg, item.name) then
Topic[cid] = _
local str = 'To craft a ' .. item.name:lower() .. ' you will need: '
for _, items in ipairs(item.itemsRequired) do
if _ ~= #item.itemsRequired - 1 then
str = str .. 'a {' .. items:lower() .. '}, '
else
str = str .. 'a {' .. items:lower() .. '} and '
end
end
str = str:sub(1, str:len() - 2)
str = str .. '. Do you have them?'
npcHandler:say(str, cid)
break
end
end
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())