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
local config = {
stone = {
{id = 1296, pos = {x = 963, y = 175, z = 7}},
{id = 1297, pos = {x = 964, y = 175, z = 7}},
{id = 1298, pos = {x = 963, y = 176, z = 7}},
{id = 1299, pos = {x = 964, y = 176, z = 7}}
},
walkpos = {
{x = 957, y = 176, z = 7},
{x = 958, y = 176, z = 7},
{x = 959, y = 176, z = 7},
{x = 960, y = 176, z = 7},
{x = 961, y = 176, z = 7},
{x = 962, y = 176, z = 7}
},
walktime = 1, -- time in seconds for every step
npcpos = {x = 956, y = 176, z = 7},
stonebacktime = 10
}
local function removeStone()
for s = 1, #config.stone do
doRemoveItem(getTileItemById(config.stone[s].pos, config.stone[s].id).uid, 1)
doSendMagicEffect(config.stone[s].pos, CONST_ME_GROUNDSHAKER)
end
return true
end
local function addStone()
for s = 1, #config.stone do
doCreateItem(config.stone[s].id, 1, config.stone[s].pos)
end
return true
end
local function npcBack(getNpc)
local nbp = #config.walkpos
local time = 0
for pos = 1, #config.walkpos do
if(nbp > 1) then
nbp = nbp - 1
time = time + (config.walktime*1000)
addEvent(doTeleportThing, time, getNpc, config.walkpos[nbp])
end
end
addEvent(doTeleportThing, (config.walktime*1000) + time, getNpc, config.npcpos)
addEvent(doCreatureSetLookDirection, (config.walktime*1200) + time, getNpc, 2)
return true
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(msgcontains(msg, 'destruir')) then
if(getTileItemById(config.stone[1].pos,config.stone[1].id).uid > 0) then
selfSay('Yo puedo remover las rocas por 100gp. Tu quieres?', cid)
talkState[talkUser] = 1
else
selfSay('Sorry, there is no stone to remove.', cid)
npcHandler:releaseFocus(cid)
end
elseif(msgcontains(msg, 'si') and talkState[talkUser] == 1) then
if(doPlayerRemoveMoney(cid, 100)) then
selfSay('Ok, one moment.', cid)
npcHandler:releaseFocus(cid)
local time = 0
for pos = 1, #config.walkpos do
time = time + (config.walktime*1000)
addEvent(doTeleportThing, time, getNpcId(), config.walkpos[pos])
end
local xtime = (config.walktime*1000) + time
addEvent(removeStone, xtime)
addEvent(npcBack, (config.stonebacktime * 1000) + xtime, getNpcId())
addEvent(addStone, (config.stonebacktime * 1000) + xtime)
else
selfSay('You don\'t have enough money.', cid)
end
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())