Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local items = {
- ["nomedoitem"] = {itemid = xxx , cost = xxx},
- ["nomedoitem"] = {itemid = xxx , cost = xxx},
- }
- local coins = 6527
- 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
- msg = msg:lower()
- local item_name = items[msg]
- if msgcontains(msg, item_name) then
- selfSay("you are sure ?", cid)
- talkState[talkUser] = 1
- end
- if msgcontains(msg, "yes") and talkState[talkUser] == 1 then
- doPlayerAddItem(cid, items[msg].itemid, 1)
- doPlayerRemoveItem(cid, coins, items[msg].cost)
- selfSay("you received "..items[msg]..".", cid)
- talkState[talkUser] = 0
- elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
- selfSay("Bye!!", cid)
- talkState[talkUser] = 0
- end
- return true
- end
- npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
- npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement