Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local keywordHandler = KeywordHandler:new()
- local npcHandler = NpcHandler:new(keywordHandler)
- NpcSystem.parseParameters(npcHandler)
- local Topic = {}
- local items = {
- ["shrimp"] = { 2670, 10, 10000 }
- }
- 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)
- for m, v in ipairs(items) do
- if (msgcontains(msg, "hello") or msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) then
- for i = 1, #v do
- if getPlayerItemCount(cid, v[1][i]) >= 1 then
- npcHandler:say("Hello " .. getCreatureName(cid) .. ". How can I help you?", cid)
- Topic[cid] == 1
- else
- npcHandler:say("How can I help you?", cid)
- Topic[cid] = nil
- end
- break
- end
- npcHandler:addFocus(cid)
- elseif(not npcHandler:isFocused(cid)) then
- return false
- elseif Topic[cid] == 1 then
- for i = 1, #m do
- if msgcontains(msg, m[i]) then
- npcHandler:say("Do you want to trade " .. m[i] .. " for experience?", cid)
- Topic[cid] = 2
- else
- npcHandler:say("Sorry, what was that?", cid)
- Topic[cid] = 0
- end
- break
- end
- elseif Topic[cid] == 2 then
- if msgcontains(cid, "yes") then
- for i = 1, #v do
- if doPlayerRemoveItem(cid, v[1][i], v[2][i] or 1) then
- npcHandler:say("Here you are!", cid)
- doPlayerAddExperience(cid, v[3][i])
- doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
- Topic[cid] = 0
- else
- npcHandler:say("You don't have the items!", cid)
- Topic[cid] = 0
- end
- break
- end
- elseif msgcontains(cid, "no") then
- npcHandler:say("Then not.", cid)
- Topic[cid] = 0
- end
- elseif msgcontains(msg, "bye") or msgcontains(msg, "farewell") and npcHandler:isFocused(cid) then
- npcHandler:say("Good bye.", cid, TRUE)
- Topic[cid] = nil
- npcHandler:releaseFocus(cid)
- end
- return true
- end
- end
- npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
- npcHandler:setMessage(MESSAGE_WALKAWAY, "How rude!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement