MY
npc

Npc que venda donate itens

Por mylorc, 18 de out. de 2013 em Scripts

npc que venda donate itens
script
otserv
18
4.8k
mylorcM
18 de outubro de 2013 às 10:23

Olá galera,estou precisando de um npc que venda donate itens no meu otserv,porém ele vendera por scarab coins.

Alguém pode me ajudar com isso? Se tiver um script pronto poderia postar e me dar uma esplicadinha?

Agradeço!

markindootM
18 de outubro de 2013 às 10:50

Isso é bem simples, pegue um NPC comun que vende aol, acrescente os items e mude o ID do item que o NPC (ao inveiz de ser Money) aceita, no seu caso é o Scarab Coins


ae achei esse pra voce.

 

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
local shopWindow = {}
local moeda = 9020 -- ID da moeda
local t = {
[2195] = {price = 15}, -- [ITEM ID PARA VENDER] = {QNTO CUSTARÁ}
[2493] = {price = 25},
[2361] = {price = 30},
[8851] = {price = 20},
[8925] = {price = 30},
[2640] = {price = 50},
[2494] = {price = 100},
[9932] = {price = 50},
[2472] = {price = 70},
[8931] = {price = 100}
}
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if t[item] and not doPlayerRemoveItem(cid, moeda, t[item].price) then
selfSay("you dont have"..t[item].price.." "..getItemNameById(moeda), cid)
else
doPlayerAddItem(cid, item)
selfSay("Here your item!", cid)
end
return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
for var, ret in pairs(t) do
table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = getItemNameById(var)})
end
openShopWindow(cid, shopWindow, onBuy, onSell)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

18 de outubro de 2013 às 11:29

acho que duvida sanada.

mylorcM
18 de outubro de 2013 às 11:48

Não esta dando certo,coloquei 6 itens no npc e esta aparecendo apenas um,e ainda estar pelo dinheiro do jogo.

Estou postando o script aqui para que você possa olhar,caso esteja algo errado por favor ajude-me:

 

-> XML

 

<?xml version="1.0" encoding="UTF-8"?>

<npc name="Equip Seller" script="data/npc/scripts/donate.lua" walkinterval="2000" floorchange="0">

<health now="100" max="100"/>

<look type="142" head="57" body="59" legs="40" feet="76" addons="2"/>

<parameters>

<parameter key="module_shop" value="6"/>

<parameter key="shop_buyable" value="shield world war,2540,20"/>

<parameter key="shop_buyable" value="armor world war,2651,20"/>

<parameter key="shop_buyable" value="helmet world war,2663,20"/>

<parameter key="shop_buyable" value="wand world war,7430,20"/>

<parameter key="shop_buyable" value="boots world war,7892,20"/>

<parameter key="shop_buyable" value="legs world war,9928,20"/>

</parameters>

</npc>

 

 

-> LUA

 

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

local shopWindow = {}

local moeda = 2159

local t = {

[2540] = {price = 20},

[2651] = {price = 20},

[2663] = {price = 20},

[7430] = {price = 20},

[7892] = {price = 20},

[9928] = {price = 20},

}

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)

if t[item] and not doPlayerRemoveItem(cid, moeda, t[item].price) then

selfSay("you dont have"..t[item].price.." "..getItemNameById(moeda), cid)

else

doPlayerAddItem(cid, item)

selfSay("Here your item!", cid)

end

return true

end

if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then

for var, ret in pairs(t) do

table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = getItemNameById(var)})

end

openShopWindow(cid, shopWindow, onBuy, onSell)

end

return true

end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())

markindootM
18 de outubro de 2013 às 12:24

xml? minha criança, issu é em NPC/Scripts e o numero do scarab coin é 3440, troca la o local moeda = 2159 <- (3440)

 

e se o script já vende, retira o buyable e ve no que da, se continuar me manda ss do npc em trade com voce

mylorcM
18 de outubro de 2013 às 12:55

Agora esta aparecendo os itens no npc ,porem o dinheiro de compra ainda não é o scarab coin,e sim no meu ot o id é 2159. Você poderia ver os lugares que troca o id para mim?

markindootM
18 de outubro de 2013 às 13:14

Você pode postar uma ss? com o trade aberto e com 1kk na bag e mostrando no npc pra ver oq ele ta aceitando e não.

mylorcM
18 de outubro de 2013 às 13:35

Ai cara estou colocando o print do npc no jogo como que ta.

Obs: os itens estão editados,as bolinhas meio douradas são os scarabs coins,que também foi editado.

post-274954-0-89196500-1382114126_thumb.png

post-274954-0-59333200-1382114145_thumb.png

Editado Outubro 18 por mylorc

markindootM
18 de outubro de 2013 às 14:38

Show de bola o servidor eim... voltando:

 

tenta esse aqui

 

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

-- Conversa Jogador/NPC
if(msgcontains(msg, 'list')) then
selfSay('Eu vendo {Vip Helmet }, {Vip Armor}.', cid)
elseif(msgcontains(msg, 'Vip Helmet')) then
selfSay('Voc\ê quer comprar Vip Helmet por 20 moedas de ouro?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'Vip Armor')) then
selfSay('Voc\ê quer comprar Vip Armor por 100 moedas de ouro?', cid)
talkState[talkUser] = 2
-- Confirmação da Compra
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(doPlayerRemoveItem(cid, 2159, 20) == true) then
selfSay('Obrigado por comprar!', cid)
doPlayerAddItem(cid, xxxx, 1)
talkState[talkUser] = 0
else
selfSay('Voc\ê n\ão tem 20 moedas de ouro', cid)
talkState[talkUser] = 0
end
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
if(doPlayerRemoveItem(cid, 2159, 100) == true) then
selfSay('Obrigado por comprar!', cid)
doPlayerAddItem(cid, xxxx, 1)
talkState[talkUser] = 0
else
selfSay('Voc\ê n\ão tem 100 moedas de ouro', cid)
talkState[talkUser] = 0
end
end
end

npcHandler
:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


sanada? REP+ porfavor e reportar para ser movido!

Editado Outubro 18 por markindoot

mylorcM
18 de outubro de 2013 às 14:46

Obrigado.

Voltando ao assunto,também não deu certo,o script anterior:pode haver alguma coisa errada,um nome por exemplo,pois não há o id de outra moeda e mesmo assim aparece,faz uma ideia do que pode ser?

markindootM
18 de outubro de 2013 às 14:55

nesse que lhe passei deu oq? vou dar uma olhada no script anterior e vejo oq posso fazer


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

local shopWindow = {}

local moeda = 2159

local t = {

[2540] = {price = 20},

[2651] = {price = 20},

[2663] = {price = 20},

[7430] = {price = 20},

[7892] = {price = 20},

[9928] = {price = 20},

}

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)

if t[item] and not doPlayerRemoveItem(cid, 2159, t[item].price) then

selfSay("you dont have"..t[item].price.." "..getItemNameById(2159), cid)

else

doPlayerAddItem(cid, item)

selfSay("Here your item!", cid)

end

return true

end

if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then

for var, ret in pairs(t) do

table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = getItemNameById(var)})

end

openShopWindow(cid, shopWindow, onBuy, onSell)

end

return true

end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())

ve se vai esse, vou chegar em casa e vou criar 1 npc para testar antes de ficar lhe mandando ok? é que tou no trampo e n tenho o tibia e pior ainda 1 otserv, entao 16:30 eu chego e jogo até...

Abraço!

mylorcM
18 de outubro de 2013 às 15:15

Ok,obrigado.

O anterior eu falo trade e ele não abre a barra ou nem se quer responde.

O outro que me passou primeiro realmente parece bom,só que falta trocar o scarab coin pelo iten.

markindootM
19 de outubro de 2013 às 17:10

tenta esse npc, ele é um NPC de troca, ele troca Queijo por items, troque o ID do queiro pelo Scarab Coins e o item que o NPC dará ao player pelo seu shop.

-- NPC de troca - By Conde Sapo
local focus = 0
local talk_start = 0
local target = 0
local following = false
local attacking = false
local addon_state = 0

function onThingMove(creature, thing, oldpos, oldstackpos)
end

function onCreatureAppear(creature)
end

function onCreatureDisappear(cid, pos)
if focus == cid then
selfSay('Good bye then.')
focus = 0
talk_start = 0
end
end

function onCreatureTurn(creature)
end

function msgcontains(txt, str)
return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end

function onCreatureSay(cid, type, msg)
msg = string.lower(msg)

if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
selfSay('Olá ' .. getCreatureName(cid) .. '... Eu daria tudo por alguns queijos... Você tem 5 sobrando aí? Eu posso te dar meu escudo em troca!')
focus = cid
talk_start
= os.clock()

elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
selfSay('Sorry, ' .. getCreatureName(cid) .. '! I talk to you in a minute.')

elseif focus == cid then
talk_start = os.clock()
if msgcontains(msg, 'queijo') or msgcontains(msg, 'escudo') then
if doPlayerRemoveItem(cid,2696,5) == 0 then
selfSay('Eu disse 5 QUEIJOS!')
addon_state = 0
else
selfSay('Obrigado, muito mesmo! Tome, isto pode ser útil para você!')
doPlayerAddItem(cid, 2512, 1)
talk_start = 0
end

elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
selfSay('Good bye, ' .. getCreatureName(cid) .. '! Come back soon..')
focus = 0
talk_start = 0
end
end
end

function onCreatureChangeOutfit(creature)
end

function onThink()
doNpcSetCreatureFocus(focus)
if (os.clock() - talk_start) > 30 then
if focus > 0 then
selfSay('Next Please...')
end
focus = 0
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 5 then
selfSay('Good bye then.')
focus = 0
end
end
end

 

 

 

 

 

em NPC

 

 

<?xml version="1.0"?>

<npc name="Taxijab" script="data/npc/scripts/Cheese.lua" access="3" lookdir="1" autowalk="200" speed="200">
<health now="1" max="1"/>
<look type="120" head="38" body="79" legs="107" feet="114"/>
</npc>

mylorcM
19 de outubro de 2013 às 19:58

É realmente troca,porém quando estou sem o scarab coins ele ainda da o item,no caso item gratis.

Sabe consertar esse ou arrumar outro?

ScythePhantomS
19 de outubro de 2013 às 20:08

Tente esse:

 

 

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
local msg = string.lower(msg)
local moeda = 9020
local t = {
["boots of haste"] = {15, 2195}, -- ["nome do item"] = {quanto vai custar, id do tem que sera vendido}
["demon helmet"] = {25, 2493},
["frozen starlight"] = {30, 2361},
["royal crossbow"] = {20, 8851},
["solar axe"] = {30, 8925},
["soft boots"] = {50, 2640},
["demon armor"] = {100, 2494},
["firewalker boots"] = {50, 9932},
["magic plate armor"] = {70, 2472},
["flame blade"] = {100, 8931}
}

if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
local str = ""
str = str .. "Eu vendo estes items: "
for name, pos in pairs(t) do
str = str.." {"..name.."} = "..pos[1].." Moedas /"
end
str = str .. "."
npcHandler:say(str, cid)
elseif t[msg] then
if doPlayerRemoveItem(cid,moeda,t[msg][1]) then
doPlayerAddItem(cid,t[msg][2],1)
npcHandler:say("Aqui está seu ".. getItemNameById(t[msg][2]) .."!", cid)
else
npcHandler:say("você não tem "..t[msg][1].." ".. getItemNameById(moeda), cid)
end
end
return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())

 

 

Créditos: Vodkart