Postado Maio 31, 2015 10 anos Preciso de uma NPC que troque: npc que troque [7636], 100 100 vials de id 7636 por um 5957, loterry ticket E uma action: e action 5957 on use ter 5% de chance de virar 5958 e 95% de chance de virar 5956
Postado Maio 31, 2015 10 anos Solução NPC: Em "Data/npc/scripts", crie nome_do_arquivo.lua e cole: local t = { item = {7636, 100}, -- ID do item e quantidade necessária. reward = 5957 -- Item que irá ganhar. } 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 msg = msg:lower(); local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if msgcontains(msg, "vial") or msgcontains(msg, "ticket") then selfSay("You want to exchange 100 vials for a ticket?", cid) talkState[talkUser] = 1 elseif msgcontains(msg, "yes") then if talkState[talkUser] == 1 then if doPlayerRemoveItem(cid, t.item[1], t.item[2]) then doPlayerAddItem(cid, t.reward, 1) selfSay("Here it is.", cid) talkState[talkUser] = 0 else selfSay("You don't have 100 vials.", cid) talkState[talkUser] = 0 end end elseif msgcontains(msg, "no") then if talkState[talkUser] == 1 then selfSay("Okay...") talkState[talkUser] = 0 end end end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) Em "Data/npc", crie nome_do_npc.xml e cole: <?xml version="1.0" encoding="UTF-8"?> <npc name="NOMEDONPC" script="data/npc/scripts/nome_do_script.lua" walkinterval="2000" floorchange="0"> <health now="100" max="100"/> <look type="156" head="57" body="59" legs="40" feet="76" addons="0"/> <parameters> <parameter key="message_greet" value="Hello, |PLAYERNAME|."/> </parameters> </npc> Vou ver se consigo fazer o segundo pedido e caso eu consiga eu edito aqui! Não está perfeito pois não manjo dessa função ainda: Em "Data/actions/scripts", crie nome_do_script.lua e cole: local t = { fail = 5956, win = 5958 } function onUse(cid, item) local chance = math.random(0, 101) if chance < 96 then doPlayerAddItem(cid, t.fail, 1) doRemoveItem(item.uid) elseif chance > 95 then doPlayerAddItem(cid, t.win, 1) doRemoveItem(item.uid) end return true end Em "Data/actions", abra o arquivo actions.xml e adicione a tag: <action itemid="5957" script="nome_do_script.lua" /> Se der algum problema, me avise . ➥ Regras | Seções OTServ | Seções BOT
Postado Junho 2, 2015 10 anos Autor NPC: Em "Data/npc/scripts", crie nome_do_arquivo.lua e cole: local t = { item = {7636, 100}, -- ID do item e quantidade necessária. reward = 5957 -- Item que irá ganhar. } 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 msg = msg:lower(); local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if msgcontains(msg, "vial") or msgcontains(msg, "ticket") then selfSay("You want to exchange 100 vials for a ticket?", cid) talkState[talkUser] = 1 elseif msgcontains(msg, "yes") then if talkState[talkUser] == 1 then if doPlayerRemoveItem(cid, t.item[1], t.item[2]) then doPlayerAddItem(cid, t.reward, 1) selfSay("Here it is.", cid) talkState[talkUser] = 0 else selfSay("You don't have 100 vials.", cid) talkState[talkUser] = 0 end end elseif msgcontains(msg, "no") then if talkState[talkUser] == 1 then selfSay("Okay...") talkState[talkUser] = 0 end end end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) Em "Data/npc", crie nome_do_npc.xml e cole: <?xml version="1.0" encoding="UTF-8"?> <npc name="NOMEDONPC" script="data/npc/scripts/nome_do_script.lua" walkinterval="2000" floorchange="0"> <health now="100" max="100"/> <look type="156" head="57" body="59" legs="40" feet="76" addons="0"/> <parameters> <parameter key="message_greet" value="Hello, |PLAYERNAME|."/> </parameters> </npc> Vou ver se consigo fazer o segundo pedido e caso eu consiga eu edito aqui! Não está perfeito pois não manjo dessa função ainda: Em "Data/actions/scripts", crie nome_do_script.lua e cole: local t = { fail = 5956, win = 5958 } function onUse(cid, item) local chance = math.random(0, 101) if chance < 96 then doPlayerAddItem(cid, t.fail, 1) doRemoveItem(item.uid) elseif chance > 95 then doPlayerAddItem(cid, t.win, 1) doRemoveItem(item.uid) end return true end Em "Data/actions", abra o arquivo actions.xml e adicione a tag: <action itemid="5957" script="nome_do_script.lua" /> Se der algum problema, me avise . Obrigado
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.