Explicação:
é dada uma lista na ordem alfabética com os pokemons que esse NPC compra,depois disso há 2 versões
V 1.0 --[[ PokeServer ]] -- : basta dizer o nome do pokemon que você quer vender e colocar o mesmo no slot da pokebola...
V 2.0 --[[ Pokemon Dash --]] : a pokebola tem que estar dentro da backpack,com a função "sellPokemon(cid, name, price)" que não é minha
NPC/SCRIPT
buy_pokemons.lua
V 1.0
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 function pairsByKeys (t, f) -- function for alphabetical order in list local a = {} for n in pairs(t) do table.insert(a, n) end table.sort(a, f) local i = 0 local iter = function () i = i + 1 if a[i] == nil then return nil else return a[i], t[a[i]] end end return iter end local Pokemons = { ["gloom"] = {price = 150000}, ["kakuna"] = {price = 25000}, ["sandshrew"] = {price = 85000}, ["pidgeot"] = {price = 550000}, ["rattata"] = {price = 130000}, ["pidgeotto"] = {price = 120000}, ["poliwag"] = {price = 11000}, ["horsea"] = {price = 20000}, ["oddish"] = {price = 8000}, ["bellsprout"] = {price = 10000}, ["pidgey"] = {price = 5000}, ["beedrill"] = {price = 120000}, ["magnemite"] = {price = 60000}, ["magneton"] = {price = 250000}, ["raticate"] = {price = 85000}, ["seadra"] = {price = 250000}, ["doduo"] = {price = 65000}, ["dodrio"] = {price = 300000}, ["golbat"] = {price = 120000}, ["graveler"] = {price = 160000}, ["electrode"] = {price = 200000}, ["victreebel"] = {price = 500000}, ["poliwhirl"] = {price = 220000}, ["bulbasaur"] = {price = 300000} } local idballs = { [2532] = {2531}, [2653] = {2557}, [2654] = {2525}, [2652] = {2524}, [2195] = {2523}, [2531] = {2532}, [2557] = {2653}, [2525] = {2654}, [2524] = {2652}, [2523] = {2195}, } local balls = idballs[getPlayerSlotItem(cid,8).itemid] if(msgcontains(msg, "pokemon") or msgcontains(msg, "pokemon")) then selfSay("Qual o pokemon que você quer me vender? quer olhar a {list} ?", cid) talkState[talkUser] = 1 elseif (msgcontains(msg, "list") or msgcontains(msg, "LIST")) and talkState[talkUser] == 1 then local str = "" str = str .. "Pokemon Prices :\n\n" for name, pos in pairsByKeys(Pokemons) do str = str..name.." = "..pos.price.."\n" end str = str .. "" doShowTextDialog(cid, 6579, str) elseif Pokemons[msg] and talkState[talkUser] == 1 then if getPlayerStorageValue(cid, 25000) == 5 then return selfSay('Você está montando.',cid) elseif getPlayerStorageValue(cid, 23000) == 5 then return selfSay('Você está voando.',cid) elseif #getCreatureSummons(cid) >= 1 then return selfSay('Voce precisa botar seus pokemons dentro da pokebola.',cid) elseif balls == nil then return selfSay('Coloque seu pokemon slot da Pokeball para que eu possar examinar!!',cid) end local a = getItemAttribute(getPlayerSlotItem(cid,8).uid,"name") if string.find(tostring(a),msg) then doRemoveItem(getPlayerSlotItem(cid,8).uid, 1) doPlayerAddMoney(cid, Pokemons[msg].price) selfSay('Obrigado por vender o pokemon '..msg..' por '..Pokemons[msg].price..' meu amigo!', cid) else selfSay('vc n tem o pokemon '..msg..' para vender!', cid) end elseif msg == "no" and talkState[talkUser] >= 1 then selfSay("Then not", cid) talkState[talkUser] = 0 npcHandler:releaseFocus(cid) end return TRUE end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new())
V 2.0
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 function pairsByKeys (t, f) -- function for alphabetical order in list local a = {} for n in pairs(t) do table.insert(a, n) end table.sort(a, f) local i = 0 local iter = function () i = i + 1 if a[i] == nil then return nil else return a[i], t[a[i]] end end return iter end function sellPokemon(cid, name, price) -- n sei de quem é essa função local pokename = name local bp = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK) local itemsball = getItemsInContainerById(bp.uid, 2222) local itemsultra = getItemsInContainerById(bp.uid, 2220) for _, pok in pairs(itemsball) do if string.lower(getItemAttribute(pok, "poke"):sub(9, findLetter(getItemAttribute(pok, "poke"), "'")-1)) == pokename then doRemoveItem(pok, 1) doPlayerAddMoney(cid, price) selfSay("Wow! Thanks for this wonderful pokemon! Take your money.",cid) return true end break end for _, pok in pairs(itemsultra) do if string.lower(getItemAttribute(pok, "poke"):sub(9, findLetter(getItemAttribute(pok, "poke"), "'")-1)) == pokename then doRemoveItem(pok, 1) doPlayerAddMoney(cid, price) selfSay("Wow! Thanks for this wonderful pokemon! Take your money.",cid) return true end break end selfSay("Hey, you dont have this pokemon("..pokename..")! Make sure if its not fainted and it is inside your backpack!",cid) end local Pokemons = { ["gloom"] = {price = 150000}, ["kakuna"] = {price = 25000}, ["sandshrew"] = {price = 85000}, ["pidgeot"] = {price = 550000}, ["rattata"] = {price = 130000}, ["pidgeotto"] = {price = 120000}, ["poliwag"] = {price = 11000}, ["horsea"] = {price = 20000}, ["oddish"] = {price = 8000}, ["bellsprout"] = {price = 10000}, ["pidgey"] = {price = 5000}, ["beedrill"] = {price = 120000}, ["magnemite"] = {price = 60000}, ["magneton"] = {price = 250000}, ["raticate"] = {price = 85000}, ["seadra"] = {price = 250000}, ["doduo"] = {price = 65000}, ["dodrio"] = {price = 300000}, ["golbat"] = {price = 120000}, ["graveler"] = {price = 160000}, ["electrode"] = {price = 200000}, ["victreebel"] = {price = 500000}, ["poliwhirl"] = {price = 220000}, ["bulbasaur"] = {price = 300000} } if(msgcontains(msg, "pokemon") or msgcontains(msg, "pokemon")) then selfSay("has some pokemon you want sell me? or you can look at the {list}!", cid) talkState[talkUser] = 1 elseif (msgcontains(msg, "list") or msgcontains(msg, "LIST")) and talkState[talkUser] == 1 then local str = "" str = str .. "Pokemon Prices :\n\n" for name, pos in pairsByKeys(Pokemons) do str = str..name.." = "..pos.price.."\n" end str = str .. "" doShowTextDialog(cid, 6579, str) elseif Pokemons[msg] and talkState[talkUser] == 1 then if getPlayerStorageValue(cid, 25000) == 5 then return selfSay("Você está montando.",cid) elseif getPlayerStorageValue(cid, 23000) == 5 then return selfSay("Você está voando.",cid) elseif #getCreatureSummons(cid) >= 1 then return selfSay("Voce precisa botar seus pokemons dentro da pokebola.",cid) end sellPokemon(cid, msg, Pokemons[msg].price) elseif msg == "no" and talkState[talkUser] >= 1 then selfSay("Then not", cid) talkState[talkUser] = 0 npcHandler:releaseFocus(cid) end return TRUE end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new())
NPC
Comprador.xml
<?xml version="1.0"?> <npc name="Comprador" script="data/npc/scripts/buy_pokemons.lua" walkinterval="5000" floorchange="0"> <health now="100" max="100"/> <look type="134" head="78" body="88" legs="0" feet="88" addons="3"/> <parameters> <parameter key="message_greet" value="Ola |PLAYERNAME|. quer me vender alguns {pokemon}? " /> </parameters> </npc>