GR

[Npc] Vende Soul

By groku, 01 de out. de 2011 in Archived

4
568
grokuG
01 de outubro de 2011 às 07:27

Olá!

Estou fazendo um projeto com meu primo, não posso falar de que é. Mas achei uma outra função para o SOUL e preciso muito (mesmo) de um NPC que vende a quantidade de soul que o player pedir.

Por exemplo:

-Hi

-Buy Soul

-100

PS: Mas assim, a quantidade de soul comprada seja a que o PLAYER ESCOLHER

PS: Para versão 8.54

Edited Outubro 1 by groku

VodkartV
01 de outubro de 2011 às 22:34
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 talkState = {}
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 p = 50 -- preço de cada soul
local max = 100 -- quantidade max que podera ser vendida

if msgcontains(msg, "soul") then
selfSay("Você deseja comprar quantos soul?", cid)
talkState[talkUser] = 1
elseif talkState[talkUser] == 1 then
if getNumber(msg) <= max then
n = getNumber(msg)
if n ~= 0 then
if getPlayerMoney(cid) > p*n then
selfSay('Você deseja mesmo comprar '..n..' soul por '..n*(p)..' gold coins {yes}?', cid)
talkState[talkUser] = 2
else
selfSay('Desculpe, você não possue dinheiro suficiente para comprar '..n..' soul.', cid)
talkState[talkUser] = 0
end
else
selfSay('Escolha um numero maior que 0.', cid)
talkState[talkUser] = 0
end
else
selfSay('Você não pode comprar mais que '..max..' soul.', cid)
talkState[talkUser] = 0
end
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2  then
if doPlayerRemoveMoney(cid,  p*n) == TRUE then
doPlayerSoulPoints (cid, n)
selfSay('Obrigado,receba suas soul!', cid)
talkState[talkUser] = 0
npcHandler:releaseFocus(cid)
else
selfSay('Desculpe, você não possue dinheiro suficiente.', cid)
talkState[talkUser] = 0
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())
function getNumber(txt)
x = string.gsub(txt,"%a","")
x = tonumber(x)
if x ~= nill and x > 0 then
return x
else
return 0
end
end

grokuG
02 de outubro de 2011 às 06:14

Vlw cara, quando der pra dar REP+ eu te dou ;d hoje nem dei rep e falo que eu ja dei

3 months later...
WatersonW
31 de janeiro de 2012 às 15:47

Tem como fazer um igual a esse só que assim, o player fala o nome do item(entre varios que poderá falar) ai ele compra o item, e o player escolhe a quantidade que quer comprar...