Rômulo Souza 14 #1 Posted May 19, 2014 (edited) Nome: The Merchant (V1.0)Autor: Rômulo Souza (Criação) e Longhart (Ideia e Tradução) Versão Testada: TFS 0.4 (8.6) É um NPC que vende itens ( que você configurou ) mas de forma que o comprador tenha que esperar um tempo pra chegar a encomenda! Isto é útil em servers onde o RPG é prioridade. Instalação Crie um arquivo: data/npc/Merchant.xml <?xml version="1.0" encoding="UTF-8"?> <npc name="The Merchant" script="merchant.lua" walkinterval="2000" floorchange="0"> <health now="150" max="150"/> <look type="128" head="20" body="100" legs="50" feet="99" corpse="2212"/> <parameters> </parameters> </npc> Crie um arquivo: data/npc/scripts/merchant.lua --// Creditos: Rômulo Souza (Criação) Longhart (Ideia e Tradução) local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} local name --// Config Here// local min_hour = 2 -- Min hour of wait local max_hour = 12 -- Max hour of wait local items = {['katana']={itemid=2412, cust=100}, ['naginata']={itemid=2426, cust=200}} -- Items to Sell local config_str = {s_itemid=4251, s_comming=4241} -- Storage ( Dont change if you dont know ) --/////////////// function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) selfSay("Hey! Hey! I got some good stuff for you, come here!",cid) end function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if(msgcontains(msg, 'hi') or msgcontains(msg, 'hello')) then if (getPlayerStorageValue(cid,config_str.s_comming) ~= -1) then local itemid = getPlayerStorageValue(cid,config_str.s_itemid) local time = getPlayerStorageValue(cid,config_str.s_comming) if (getPlayerStorageValue(cid,config_str.s_comming) <= os.time()) then selfSay('Hello! Your '..getItemNameById(itemid)..' is ready! You want get it now?', cid) talkState[talkUser] = 3 else min = math.floor((time-os.time())/60) hours = math.floor((time-os.time())/60/60) selfSay('Your '..getItemNameById(itemid)..' will take '.. min..' minutes (~'..hours..' hours) to come for me.', cid) end else local str = '' local cont = 1 for name,tab in pairs(items) do str = str.. name.. (cont >= count(items) and '.' or ',') cont = cont+1 end selfSay('Hello, i can bring some kind of itens for you, just say what you want. Items: '..str, cid) talkState[talkUser] = 1 end elseif (talkState[talkUser] == 1 and msg ~='bye') then if (items[msg] ~= nil) then selfSay('You want to request the '..msg..'? it will cost '..items[msg].cust..' gold coins, are you sure?', cid) talkState[talkUser] = 2 name = msg else selfSay('I\'m not selling the '..msg..'!', cid) talkState[talkUser] = 1 end elseif(msgcontains(msg, 'no') and talkState[talkUser] == 2) then selfSay("Don\'t worry, i can bring this anytime you want.",cid) talkState[talkUser] = 1 elseif(msgcontains(msg, 'yes') and isInArray({2,3}, talkState[talkUser])) then if (talkState[talkUser] == 2) then if (doPlayerRemoveMoney(cid,items[name].cust)) then hours = doStorage(cid, items[name].itemid) selfSay('Thanks for requesting '..name..', it will take '..hours..' hours before come.', cid) talkState[talkUser] = 0 else selfSay('You don\'t have enough money, you need '.. items[name].cust..' gold coins.', cid) talkState[talkUser] = 1 end elseif (talkState[talkUser] == 3) then local itemid = getPlayerStorageValue(cid,config_str.s_itemid) selfSay('Here you are, come back again!.', cid) doPlayerAddItem(cid,itemid,1) setPlayerStorageValue(cid,config_str.s_itemid,-1) setPlayerStorageValue(cid,config_str.s_comming,-1) talkState[talkUser] = 0 end end return true end function onThink() npcHandler:onThink() end function creatureSayCallback(cid, type, msg) if(not npcHandler:isFocused(cid)) then return false end end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) function doStorage(cid,itemid) str = getPlayerStorageValue(cid,config_str.s_comming) hours = math.random(min_hour,max_hour) local time = (os.time())+(1*60*60*hours) setPlayerStorageValue(cid,config_str.s_itemid,itemid) setPlayerStorageValue(cid,config_str.s_comming,time) return hours end function count(t) sum = 0 for k,v in pairs(t) do sum = sum + 1 end return sum end Outras Informações Este Script faz parte de um futuro projeto OpenSource que visa criar NPCS, Quests, Mapas, e Sistemas sempre inovadores. E estimular o desenvolvimento livre de otservers. Faça sua sugestão! Mais Trabalhos realizados em prol do Projeto: ShowOff do Mapa Edited May 19, 2014 by Rômulo Souza 3 1 Leohige, Lyon, Deragon and 1 other reacted to this Share this post Link to post
Longhart 16 #2 Posted May 19, 2014 Aguardo por mais NPCs, esse se mostrou funcional. Completo e configurável, manipulável também. Posso fazer o tempo, os itens e o dinheiro configurável. Agora, uma pequena duvida: Se o Player sair do jogo, o tempo continua contando? 1 Rômulo Souza reacted to this Share this post Link to post
Rômulo Souza 14 #3 Posted May 19, 2014 Sim! Se o player deslogar o tempo continua contando. Share this post Link to post
Deragon 25 #4 Posted May 20, 2014 bem legal, acho que no global tem um npc parecido com esse, mas seria interessante colocar um range de tempo pra cada item especifico (itens de ouro poderiam demorar mais tempo do que itens de couro, por exemplo) 1 Rômulo Souza reacted to this Share this post Link to post