Forkz
Well-Known Member
- Joined
- Jun 29, 2020
- Messages
- 380
- Solutions
- 1
- Reaction score
- 89
Hi otlanders,
I need a talkactions to buy items mentioned, as in the model below, but for the TFS 1.5 version.
I need a talkactions to buy items mentioned, as in the model below, but for the TFS 1.5 version.
XML:
<!-- Buy Command -->
<config name="command-buy-config"><![CDATA[
items = {
['brown backpack'] = {cost = 500, id = 1988},
['backpack'] = {cost = 500, id = 1988},
['bp'] = {cost = 500, id = 1988},
['green backpack'] = {cost = 500, id = 1998},
['yellow backpack'] = {cost = 500, id = 1999},
['red backpack'] = {cost = 500, id = 2000},
['purple backpack'] = {cost = 500, id = 2001},
['grey backpack'] = {cost = 500, id = 2003},
['blue backpack'] = {cost = 500, id = 2002},
['gold backpack'] = {cost = 500, id = 2004},
['rope'] = {cost = 500, id = 2120},
['shovel'] = {cost = 500, id = 2554},
['machete'] = {cost = 500, id = 2420},
['aol'] = {cost = 100000, id = 2173}
}
]]></config>
<talkaction words="!buy;/buy" event="script"><![CDATA[
domodlib('command-buy-config')
local config = {
items = items
}
function onSay(cid, words, param, channel)
if(param == '') then
local str = ""
for name, options in pairs(config.items) do
str = str .. "\n" .. name
end
doShowTextDialog(cid, 1950, "/buy or !buy:\n" .. str)
return true
end
local item = config.items[param]
if(item ~= nil) then
if(not doPlayerRemoveMoney(cid, item.cost)) then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Not enough money to buy " .. param .. ".\n(" .. item.cost .. "gp)")
return true
end
local amount = item.amount and item.amount or 1
doPlayerAddItem(cid, item.id, amount)
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
else
doPlayerSendCancel(cid, "Item not found. Use '!buy' to see the list.")
end
return true
end
]]></talkaction>