Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- #### worthdavi
- #### 12/07/2019
- --]]
- local moeda = 21400
- local itens = {
- [2798] = {valor = 25},
- [20620] = {valor = 50},
- [33082] = {valor = 50},
- [33083] = {valor = 50},
- [33084] = {valor = 50},
- [33085] = {valor = 50},
- [33086] = {valor = 50},
- [33087] = {valor = 50},
- [23588] = {valor = 100},
- [16007] = {valor = 150},
- [27063] = {valor = 150},
- [27063] = {valor = 150}
- }
- local clothes = {
- -- [idF or idM] = {valor = x, idM = y, idF = z},
- }
- local mounts = {
- [44] = {valor = 250},
- [45] = {valor = 250},
- [37] = {valor = 250}
- }
- local inicioDaLista = 0
- local fimDaLista = 4
- 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 playerTopic = {}
- local function greetCallback(cid)
- local player = Player(cid)
- if player then
- npcHandler:setMessage(MESSAGE_GREET, "Hello, ".. player:getName() .."! With me you can buy {clothes}, {mounts}, {artifacts} and some {other stuff}, would you be interested?")
- playerTopic[cid] = 1
- end
- npcHandler:addFocus(cid)
- return true
- end
- local valor = {}
- local quantidade = {}
- local itemName = {}
- local precoTotal = {}
- local itemId = {}
- local function showItemsCatalog(table)
- local max = 0
- for _, k in pairs(table) do
- max = max + 1
- end
- local msg = ""
- local c = 0
- for i, k in pairs(table) do
- local virgula = ", "
- if c ~= (max - 1) then
- c = c + 1
- else
- virgula = ""
- end
- msg = msg .. "{".. ItemType(i):getName():lower() .. "}" .. virgula
- end
- return msg
- end
- local function showMountCatalog(table)
- local max = 0
- for _, k in pairs(table) do
- max = max + 1
- end
- local msg = ""
- local c = 0
- for i, k in pairs(table) do
- local virgula = ", "
- if c ~= (max - 1) then
- c = c + 1
- else
- virgula = ""
- end
- msg = msg .. "{".. Mount(i):getName():lower() .. "}" .. virgula
- end
- return msg
- end
- local function creatureSayCallback(cid, type, msg)
- if not npcHandler:isFocused(cid) then
- return false
- end
- npcHandler.topic[cid] = playerTopic[cid]
- local player = Player(cid)
- local arrayProdutos = ""
- local plural = ""
- local function sendHello(topic)
- npcHandler:say({"Glad you were interested. I'm a different merchant ... My currency is based on the players participating in server events. Do you have event tokens?"}, cid)
- npcHandler.topic[cid] = topic
- playerTopic[cid]= topic
- end
- if (msgcontains(msg, "artifacts") or msgcontains(msg, "items")) and (npcHandler.topic[cid] == 1) then
- sendHello(2)
- -- Prosseguindo com a partes de itens
- elseif npcHandler.topic[cid] == 2 then
- if msgcontains(msg, "sim") or msgcontains(msg, "yes") then
- local arrayProdutos = showItemsCatalog(itens)
- npcHandler:say({"How nice! Then browse my catalog of artifacts and let me know if something interests you: ".. arrayProdutos .."."}, cid)
- npcHandler.topic[cid] = 3
- playerTopic[cid]= 3
- end
- elseif npcHandler.topic[cid] == 3 then
- local itemType = ItemType(msg)
- if not itemType then
- npcHandler:say({"An error has ocurred, please contact an administrator."}, cid)
- return false
- end
- local itensTable = itens[itemType:getId()]
- if itensTable then
- valor[cid] = itensTable.valor
- itemName[cid] = msg
- npcHandler:say({"Good choice! If you really want the ".. itemName[cid] ..", it will cost you ".. valor[cid] .." ".. ItemType(moeda):getName():lower() .." each. How many would you be interested in?"}, cid)
- npcHandler.topic[cid] = 4
- playerTopic[cid]= 4
- else
- npcHandler:say({"This item is not in my catalog."}, cid)
- end
- elseif npcHandler.topic[cid] == 4 then
- quantidade[cid] = tonumber(msg)
- if quantidade[cid] then
- if quantidade[cid] > 1 then
- plural = plural .. "s"
- end
- if quantidade[cid] >= 20 then
- npcHandler:say({"Calm down!! It doesn't fit in a bag!"}, cid)
- else
- precoTotal[cid] = valor[cid]*quantidade[cid]
- npcHandler:say({"So you want ".. quantidade[cid] .." ".. itemName[cid] .. plural ..". Hmmmm, this will give a total of ".. precoTotal[cid] .." ".. ItemType(moeda):getName():lower() .."s. Do you accept?"}, cid)
- playerTopic[cid] = 5
- npcHandler.topic[cid] = 5
- end
- else
- npcHandler:say({"I did not understand."}, cid)
- end
- elseif npcHandler.topic[cid] == 5 then
- if msgcontains(msg, "yes") or msgcontains(msg, "sim") then
- if player:getItemCount(moeda) >= precoTotal[cid] then
- itemId[cid] = ItemType(itemName[cid]):getId()
- -- Criando container no mailbox
- local parcel = player:getInbox():addItem(2596, 1, false, 1)
- parcel:addItem(1988, 1, false, 1):addItem(itemId[cid], quantidade[cid], false, 1)
- player:removeItem(moeda, precoTotal[cid])
- npcHandler:say({"Great. I will ask my delivery boy to leave the items in your mailbox."}, cid)
- else
- npcHandler:say({"You don't have enough event tokens..."}, cid)
- npcHandler.topic[cid] = 1
- playerTopic[cid]= 1
- end
- end
- -- Prosseguindo com a parte de mounts
- elseif (msgcontains(msg, "mount") or msgcontains(msg, "mounts")) and (npcHandler.topic[cid] == 1) then
- sendHello(6)
- elseif npcHandler.topic[cid] == 6 then
- if msgcontains(msg, "sim") or msgcontains(msg, "yes") then
- local arrayMounts = showMountCatalog(mounts)
- npcHandler:say({"How nice! Then browse my catalog of mounts and let me know if something interests you: ".. arrayMounts .."."}, cid)
- npcHandler.topic[cid] = 7
- playerTopic[cid]= 7
- end
- elseif npcHandler.topic[cid] == 7 then
- local mount = Mount(msg)
- if not mount then
- npcHandler:say({"An error has ocurred, please contact an administrator."}, cid)
- return false
- end
- local mountTable = mounts[mount:getId()]
- if mountTable then
- valor[cid] = itensTable.valor
- itemName[cid] = msg
- npcHandler:say({"Good choice! If you really want the ".. itemName[cid] ..", it will cost you ".. valor[cid] .." ".. ItemType(moeda):getName():lower() .."s. Are you sure?"}, cid)
- npcHandler.topic[cid] = 8
- playerTopic[cid]= 8
- else
- npcHandler:say({"I did not understand."}, cid)
- end
- elseif npcHandler.topic[cid] == 8 then
- if msgcontains(msg, "yes") or msgcontains(msg, "sim") then
- if player:getItemCount(moeda) >= precoTotal[cid] then
- if player:hasMount(itemName[cid]) then
- npcHandler:say({"You already have this mount. Choose another one."}, cid)
- npcHandler.topic[cid] = 7
- playerTopic[cid]= 7
- else
- player:addMount(itemName[cid])
- player:removeItem(moeda, precoTotal[cid])
- npcHandler:say({"Great. Here it is."}, cid)
- npcHandler.topic[cid] = 0
- playerTopic[cid]= 0
- end
- else
- npcHandler:say({"You don't have enough event tokens..."}, cid)
- npcHandler.topic[cid] = 1
- playerTopic[cid]= 1
- end
- end
- -- Prosseguindo com a parte de clothes
- elseif (msgcontains(msg, "clothes") or msgcontains(msg, "outfit")) and (npcHandler.topic[cid] == 1) then
- -- Prosseguindo com a parte de other stuff
- elseif (msgcontains(msg, "other stuff") or msgcontains(msg, "other") or msgcontains(msg, "stuff")) and (npcHandler.topic[cid] == 1) then
- else
- npcHandler:say({"I did not understand."}, cid)
- end
- if msgcontains(msg, "no") or msgcontains(msg, "nao") then
- npcHandler:say({"Ah feel free to talk to me whenever I am here."}, cid)
- npcHandler.topic[cid] = 0
- playerTopic[cid]= 0
- end
- return true
- end
- npcHandler:setMessage(MESSAGE_WALKAWAY, 'Valeu, |PLAYERNAME|!')
- npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
- npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)
- npcHandler:setCallback(CALLBACK_GREET, greetCallback)
- npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
- npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement