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
local c = {
tokenid = 1234, -- id of the token
num = 10, -- number of tokens
pos = {x=100, y=100, z=7} -- teleport position
}
if(msgcontains(msg, 'event')) then
selfSay('Do you have the '..c.num..' tokens?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if getPlayerItemCount(cid, c.tokenid) >= c.num then
doPlayerRemoveItem(cid, c.tokenid, c.num)
doTeleportThing(cid, c.pos)
selfSay('Good luck.', cid)
else
selfSay("Sorry, you don\'t have the "..c.num.." tokens.", cid)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
talkState[talkUser] = 0
selfSay('Ok then.', cid)
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 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
local c = {
tokenid = 1234, -- id of the token
num = 10, -- number of tokens
pos = {x=100, y=100, z=7} -- teleport position
}
if(msgcontains(msg, 'event')) then
selfSay('Congratulations! You win the event, are you prepared to be teleported?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if INSERT_FUNCTION_HERE then
doPlayerAddItem(cid, c.tokenid, c.num)
doTeleportThing(cid, c.pos)
selfSay('Good luck.', cid)
else
selfSay("Sorry, you don\'t win the event.", cid)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
talkState[talkUser] = 0
selfSay('Ok then.', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
<?xml version="1.0" encoding="UTF-8"?>
<npc name="NPCNAME" script="event.lua" walkinterval="2000" floorchange="0">
<health now="150" max="150"/>
<look type="129" head="114" body="119" legs="114" feet="114" corpse="2212"/>
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|."/>
</parameters>
</npc>
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
local c = {
tokenid = 1234, -- id of the token
num = 10, -- number of tokens
temple = false,
pos = {x=1000, y=1000, z=6} -- teleport position
}
if(msgcontains(msg, 'event')) then
selfSay('Congratulations! You win the event, are you prepared to be teleported?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
doPlayerAddItem(cid, c.tokenid, c.num)
doTeleportThing(cid, (c.temple and getTownTemplePosition(getPlayerTown(cid))) or c.pos)
selfSay('Good luck.', cid)
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
talkState[talkUser] = 0
selfSay('Ok then.', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
local c = {
tokenid = 1234, -- id of the token
num = 10, -- number of tokens
temple = false, -- tp to temple or pos (true to temple, false to configurable pos)
pos = {x=1000, y=1000, z=6} -- teleport position if temple = false
}