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 temp = {}
local cfg = {
stg = 2500, -- The storage,
buyAble = {
['war horse'] = {
cost = 20, -- The amount it should cost to get the mount.
mountId = 17, -- The id of the mount.
},
['armoured fire horse'] = {
cost = 40,
mountId = 18,
},
},
}
function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
if npcHandler.topic[cid] < 2 then
if msgcontains(msg, 'offers') then
local str = "I have these mount"..(#cfg.buyAble > 1 and "s " or " ").."to offer: "
for k,v in pairs(cfg.buyAble) do
str = str .. "({"..k.."}) "
end
selfSay(str, cid)
npcHandler.topic[cid] = 2
temp[cid] = nil
end
elseif npcHandler.topic[cid] == 2 then
for k,v in pairs(cfg.buyAble) do
if msg == k then
selfSay('Are you sure you would like to buy the '..k..' mount for '..cfg.buyAble[k].cost..' points?', cid)
npcHandler.topic[cid] = 3
temp[cid] = k
break
end
end
elseif npcHandler.topic[cid] == 3 then
if msgcontains(msg, 'yes') then
if temp[cid] ~= nil then
if player:getStorageValue(cfg.stg) >= cfg.buyAble[temp[cid]].cost then
if not player:hasMount(cfg.buyAble[temp[cid]].mountId) then
player:addMount(cfg.buyAble[temp[cid]].mountId)
player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
player:setStorageValue(cfg.stg, (player:getStorageValue(cfg.stg)-cfg.buyAble[temp[cid]].cost))
selfSay('Hope you enjoy your new mount!', cid)
else
selfSay('Sorry, buy you already have this mount.', cid)
end
else
selfSay('Sorry.. You still need '..(player:getStorageValue(cfg.stg) < 0 and cfg.buyAble[temp[cid]].cost or cfg.buyAble[temp[cid]].cost-player:getStorageValue(cfg.stg))..' points in order to buy this mount. Come back once you have them', cid)
end
else
selfSay('Sorry, somethings not right. Please try again later.', cid)
print('Error: Got to .Buy mount. With a nil value on Temp[cid].')
end
elseif msgcontains(msg, 'no') then
selfSay('Would you like to look at my {offers} again?', cid)
end
npcHandler.topic[cid] = 0
temp[cid] = nil
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())