JE
npc

NPC vendendo bless para quem já possui

Por jefersonzc, 27 de out. de 2013 em Scripts

bless
possui
5
1.2k
jefersonzcJ
27 de outubro de 2013 às 11:50

Galera, to com um npc que vende bless, promotion e premium scroll.

Tá tudo funcionando bem, exceto por um único detalhe, ele vende a bless mesmo que o player já tenha.

Queria que ele só vendesse quando o player estivesse sem bless.

 

Segue o LUA dele

 

 

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

	if(msgcontains(msg, 'premium')) then
		selfSay('You must pay 30000 gps for a premium scroll. Is it ok for you?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(doPlayerRemoveMoney(cid, 30000) == TRUE) then
			doPlayerAddItem(cid, 16101)
			selfSay('Enjoy it!', cid)
		else
			selfSay('Sorry, you dont have enough money.', cid)
		end
		talkState[talkUser] = 0
		
		
	elseif(msgcontains(msg, 'bless')) then
		selfSay('I can give you all blessings for an amount of 150000 gps. Is it ok for you?', cid)
		talkState[talkUser] = 2
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
		if(getPlayerPremiumDays(cid) >= 1) then
			if(doPlayerRemoveMoney(cid, 150000) == TRUE) then
				doPlayerAddBlessing(cid, 1)
				doPlayerAddBlessing(cid, 2)
				doPlayerAddBlessing(cid, 3)
				doPlayerAddBlessing(cid, 4)
				doPlayerAddBlessing(cid, 5)
				selfSay('You are now blessed!', cid)
				doSendMagicEffect(getPlayerPosition(cid), 49)
			else
				selfSay('Sorry, you dont have enough money.', cid)
			end
		else
			selfSay('Sorry, you need to be premium.', cid)
		end
		talkState[talkUser] = 0
		
		
	elseif(msgcontains(msg, 'promot')) then
		selfSay('You need to pay 20000 to be promoted. Is it ok for you?', cid)
		talkState[talkUser] = 3
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 3) then
		if(getPlayerPremiumDays(cid) >= 1) then
			if getPlayerPromotionLevel(cid) < 1 then
				if(doPlayerRemoveMoney(cid, 20000) == TRUE) then
					setPlayerPromotionLevel(cid, 1)
					doSendMagicEffect(getPlayerPosition(cid), 49)
					selfSay('Congratulations! You are now promoted.', cid)
				else
					selfSay('Sorry, you dont have enough money.', cid)
				end
			else
				selfSay('You alredy have a promotion.', cid)
			end
		else
			selfSay('Sorry, you need to be premium.', cid)
		end
		talkState[talkUser] = 0
		
		
	elseif(msgcontains(msg, 'no') and isInArray({1,2,3}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end	

	return true
end

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

 

 

 

Acredito que a solução seja trivial, bastando usar um "getPlayerBless", mas qual seria o comando certo? Digo, esse "getPlayerBless" não existe, então como posso verificar se o player já tem as bless?

Editado Outubro 27 por jefersonzc

LumusL
28 de outubro de 2013 às 14:42
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

	if(msgcontains(msg, 'premium')) then
		selfSay('You must pay 30000 gps for a premium scroll. Is it ok for you?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(doPlayerRemoveMoney(cid, 30000) == TRUE) then
			doPlayerAddItem(cid, 16101)
			selfSay('Enjoy it!', cid)
		else
			selfSay('Sorry, you dont have enough money.', cid)
		end
		talkState[talkUser] = 0
		
		
	elseif(msgcontains(msg, 'bless')) then
		if getPlayerBlessing(cid) then
			selfSay('You already blessing', cid)
			else
		selfSay('I can give you all blessings for an amount of 150000 gps. Is it ok for you?', cid)
		talkState[talkUser] = 2
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
		if(getPlayerPremiumDays(cid) >= 1) then
			if(doPlayerRemoveMoney(cid, 150000) == TRUE) then
				doPlayerAddBlessing(cid, 1)
				doPlayerAddBlessing(cid, 2)
				doPlayerAddBlessing(cid, 3)
				doPlayerAddBlessing(cid, 4)
				doPlayerAddBlessing(cid, 5)
				selfSay('You are now blessed!', cid)
				doSendMagicEffect(getPlayerPosition(cid), 49)
			else
				selfSay('Sorry, you dont have enough money.', cid)
			end
		else
			selfSay('Sorry, you need to be premium.', cid)
		end
		end
		talkState[talkUser] = 0
		
		
	elseif(msgcontains(msg, 'promot')) then
		selfSay('You need to pay 20000 to be promoted. Is it ok for you?', cid)
		talkState[talkUser] = 3
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 3) then
		if(getPlayerPremiumDays(cid) >= 1) then
			if getPlayerPromotionLevel(cid) < 1 then
				if(doPlayerRemoveMoney(cid, 20000) == TRUE) then
					setPlayerPromotionLevel(cid, 1)
					doSendMagicEffect(getPlayerPosition(cid), 49)
					selfSay('Congratulations! You are now promoted.', cid)
				else
					selfSay('Sorry, you dont have enough money.', cid)
				end
			else
				selfSay('You alredy have a promotion.', cid)
			end
		else
			selfSay('Sorry, you need to be premium.', cid)
		end
		talkState[talkUser] = 0
		
		
	elseif(msgcontains(msg, 'no') and isInArray({1,2,3}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end	

	return true
end

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

Tenta assim.

jefersonzcJ
28 de outubro de 2013 às 17:18

Fawz, não acredito que passei tão perto, tava tentando getPlayerBless ao invés de getPlayerBlessing. Uahauhauhaha!!!

 

Vlw brother, ta show agora ;)

 

rep+

LumusL
28 de outubro de 2013 às 17:44

Que isso carinha!! Precisando, só falar :)

 

Reportado para que movam :D

OmegaO
29 de outubro de 2013 às 17:16

Essa seção não deve ser usada para pedidos ou dúvidas, temos uma seção específica para isso. Por favor, preste mais atenção da próxima vez.
Movido para Pedidos e Dúvidas Resolvidos - Scripting.