Ir para conteúdo
  • Cadastre-se

Arrumar um problema script


Posts Recomendados

Achei e editei esse script vendedor de magias, mas o problema dele é que quando o npc diz quais magias ele vai vender, chega num limite ai só manda algumas

Tava pensando em:

Só mostrar as magias que o jogador ainda não comprou

Ou qualquer outra coisa quem puder me ajudar dou 6reps

 

 


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 t = {
-- all
["light healing"] = {price = 170,vocations = {1,2,3,4,5,6,7,8},level = 1},
["find person"] = {price = 60,vocations = {1,2,3,4,5,6,7,8},level = 1},
["magic rope"] = {price = 200,vocations = {1,2,3,4,5,6,7,8},level = 1},
["cure poison"] = {price = 150,vocations = {1,2,3,4,5,6,7,8},level = 1},
["levitate"] = {price = 500,vocations = {1,2,3,4,5,6,7,8},level = 1},
["great light"] = {price = 500,vocations = {1,2,3,4,5,6,7,8},level = 1},
["haste"] = {price = 600,vocations = {1,2,3,4,5,6,7,8},level = 1},
["food"] = {price = 300,vocations = {1,2,3,4,5,6,7,8},level = 1},
["magic shield"] = {price = 450,vocations = {1,2,3,5,6,7},level = 1},
 
["light magic missile"] = {price = 500,vocations = {1,2,5,6},level = 1},
["poison field"] = {price = 300,vocations = {1,2,5,6},level = 1},
["fire field"] = {price = 500,vocations = {1,2,5,6},level = 1},
["destroy field"] = {price = 700,vocations = {1,2,5,6},level = 1},
["energy field"] = {price = 700,vocations = {1,2,5,6},level = 1},
 
 
["energy strike"] = {price =800,vocations = {1,2,5,6},level = 1},
["poison strike"] = {price =800,vocations = {1,2,5,6},level = 1},
["ice strike"] = {price =800,vocations = {1,2,5,6},level = 1},
["flame strike"] = {price =800,vocations = {1,2,5,6},level = 1},
["death strike"] = {price =800,vocations = {1,2,5,6},level = 1},
 
["fire wave"] = {price =850,vocations = {1,5},level = 1},
["ice wave"] = {price =850,vocations = {2,6},level = 1},
["strong haste"] = {price =1300,vocations = {1,2,5,6},level = 1},
["creature illusion"] = {price =1000,vocations = {1,2,5,6},level = 1},
["summon creature"] = {price =2000,vocations = {1,2,5,6},level = 1},
["ultimate light"] = {price =1600,vocations = {1,2,5,6},level = 1},
["fire bomb"] = {price =1500,vocations = {1,2,5,6},level = 1},
["soul fire"] = {price =1800,vocations = {1,2,5,6},level = 1},
["energy bomb"] = {price =2300,vocations = {1,2,5,6},level = 1},
["poison wall"] = {price =1600,vocations = {1,2,5,6},level = 1},
["fire wall"] = {price =2000,vocations = {1,2,5,6},level = 1},
["energy wall"] = {price =2500,vocations = {1,2,5,6},level = 1},
["great fireball"] = {price =1200,vocations = {1,2,5,6},level = 1},
["ultimate healing"] = {price =1000,vocations = {1,2,3,5,6,7},level = 1},
["invisible"] = {price =2000,vocations = {1,2,3,5,6,7},level = 1},
["magic wall"] = {price =2100,vocations = {1,5},level = 1},
["mort wave"] = {price =2500,vocations = {1,5},level = 1},
["enchant staff"] = {price =2000,vocations = {1,5},level = 1},
["sudden death"] = {price =3000,vocations = {1,5},level = 1},
["rage of the skies"] = {price =6000,vocations = {1,5},level = 1},
["explosion"] = {price =1800,vocations = {1,5},level = 1},
 
-- All
["Light healing"] = {price = 170,vocations = {1,2,3,4,5,6,7,8},level = 1},
["Find person"] = {price = 60,vocations = {1,2,3,4,5,6,7,8},level = 1},
["Magic rope"] = {price = 200,vocations = {1,2,3,4,5,6,7,8},level = 1},
["Cure poison"] = {price = 150,vocations = {1,2,3,4,5,6,7,8},level = 1},
["Levitate"] = {price = 500,vocations = {1,2,3,4,5,6,7,8},level = 1},
["Great light"] = {price = 500,vocations = {1,2,3,4,5,6,7,8},level = 1},
["Haste"] = {price = 600,vocations = {1,2,3,4,5,6,7,8},level = 1},
["Food"] = {price = 300,vocations = {1,2,3,4,5,6,7,8},level = 1},
["Magic shield"] = {price = 450,vocations = {1,2,3,5,6,7},level = 1},
 
["Light Magic Missile"] = {price = 500,vocations = {1,2,5,6},level = 1},
["Poison Field"] = {price = 300,vocations = {1,2,5,6},level = 1},
["Fire Field"] = {price = 500,vocations = {1,2,5,6},level = 1},
["Destroy Field"] = {price = 700,vocations = {1,2,5,6},level = 1},
["Energy Field"] = {price = 700,vocations = {1,2,5,6},level = 1},
 
 
["Energy Strike"] = {price =800,vocations = {1,2,5,6},level = 1},
["Poison Strike"] = {price =800,vocations = {1,2,5,6},level = 1},
["Ice Strike"] = {price =800,vocations = {1,2,5,6},level = 1},
["Flame Strike"] = {price =800,vocations = {1,2,5,6},level = 1},
["Death Strike"] = {price =800,vocations = {1,2,5,6},level = 1},
 
["Fire Wave"] = {price =850,vocations = {1,5},level = 1},
["Ice Wave"] = {price =850,vocations = {2,6},level = 1},
["Strong Haste"] = {price =1300,vocations = {1,2,5,6},level = 1},
["Creature Illusion"] = {price =1000,vocations = {1,2,5,6},level = 1},
["Summon Creature"] = {price =2000,vocations = {1,2,5,6},level = 1},
["Ultimate Light"] = {price =1600,vocations = {1,2,5,6},level = 1},
["Fire Bomb"] = {price =1500,vocations = {1,2,5,6},level = 1},
["Soul Fire"] = {price =1800,vocations = {1,2,5,6},level = 1},
["Energy Bomb"] = {price =2300,vocations = {1,2,5,6},level = 1},
["Poison Wall"] = {price =1600,vocations = {1,2,5,6},level = 1},
["Fire Wall"] = {price =2000,vocations = {1,2,5,6},level = 1},
["Energy Wall"] = {price =2500,vocations = {1,2,5,6},level = 1},
["Great Fireball"] = {price =1200,vocations = {1,2,5,6},level = 1},
["Ultimate Healing"] = {price =1000,vocations = {1,2,3,5,6,7},level = 1},
["Invisible"] = {price =2000,vocations = {1,2,3,5,6,7},level = 1},
["Magic Wall"] = {price =2100,vocations = {1,5},level = 1},
["Mort Wave"] = {price =2500,vocations = {1,5},level = 1},
["Enchant Staff"] = {price =2000,vocations = {1,5},level = 1},
["Sudden Death"] = {price =3000,vocations = {1,5},level = 1},
["Rage of the Skies"] = {price =6000,vocations = {1,5},level = 1},
["Explosion"] = {price =1800,vocations = {1,5},level = 1},
 
-- Pally
["conjure arrow"] = {price =450,vocations = {3,7},level = 1},
["conjure poisoned arrow"] = {price =700,vocations = {3,7},level = 1},
["conjure bolt"] = {price =750,vocations = {3,7},level = 1},
["conjure explosive arrow"] = {price =1000,vocations = {3,7},level = 1},
["conjure power bolt"] = {price =2000,vocations = {3,7},level = 1},
["conjure infernal bolt"] = {price =66666,vocations = {3,7},level = 1},
-- Maiusculas Pally
["Conjure Arrow"] = {price =450,vocations = {3,7},level = 1},
["Conjure Poisoned Arrow"] = {price =700,vocations = {3,7},level = 1},
["Conjure Bolt"] = {price =750,vocations = {3,7},level = 1},
["Conjure Explosive Arrow"] = {price =1000,vocations = {3,7},level = 1},
["Conjure Power Bolt"] = {price =2000,vocations = {3,7},level = 1},
["Conjure Infernal Bolt"] = {price =66666,vocations = {3,7},level = 1},
-- kina
["whirlwind throw"] = {price =1500,vocations = {4,8},level = 1},
["challenge"] = {price =2000,vocations = {4,8},level = 1},
["berserk"] = {price =2000,vocations = {4,8},level = 1},
-- Maiusculas Kina
["Whirlwind Throw"] = {price =1500,vocations = {4,8},level = 1},
["Challenge"] = {price =2000,vocations = {4,8},level = 1},
["Berserk"] = {price =2000,vocations = {4,8},level = 1},
-- druid
["intense healing"] = {price =600,vocations = {2,6},level = 1},
["heal friend"] = {price =800,vocations = {2,6},level = 1},
["ultimate healing"] = {price =1500,vocations = {2,6},level = 1},
["mass healing"] = {price =2200,vocations = {2,6},level = 1},
["paralyze"] = {price =1900,vocations = {2,6},level = 1},
["wrath of nature"] = {price =6000,vocations = {2,6},level = 1},
["heavy magic missile"] = {price =1500,vocations = {1,2,5,6},level = 1},
["intense healing"] = {price =350,vocations = {1,2,3,5,6,7},level = 1},
["magic wall"] = {price =2100,vocations = {1,5},level = 1},
["wild growth"] = {price =4200,vocations = {2,6},level = 1},
["avalanche"] = {price =3000,vocations = {2,6},level = 1},
-- Druid
["Intense Healing"] = {price =600,vocations = {2,6},level = 1},
["Heal Friend"] = {price =800,vocations = {2,6},level = 1},
["Ultimate Healing"] = {price =1500,vocations = {2,6},level = 1},
["Mass Healing"] = {price =2200,vocations = {2,6},level = 1},
["Paralyze"] = {price =1900,vocations = {2,6},level = 1},
["Wrath of Nature"] = {price =6000,vocations = {2,6},level = 1},
["Heavy Magic Missile"] = {price =1500,vocations = {1,2,5,6},level = 1},
["Intense Healing"] = {price =350,vocations = {1,2,3,5,6,7},level = 1},
["Magic Wall"] = {price =2100,vocations = {1,5},level = 1},
["Wild Growth"] = {price =4200,vocations = {2,6},level = 1},
["Avalanche"] = {price =3000,vocations = {2,6},level = 1}
}
if (msgcontains(msg, 'SPELLS') or msgcontains(msg, 'spells'))then
local str = ""
str = str .. "Vendo: "
for name, pos in pairs(t) do
if isInArray(pos.vocations, getPlayerVocation(cid)) then
str = str.." {"..name.."} = "..pos.price.." gold coins /"
end
end
if str == "" then
str = "Eu não tenho nenhuma magia para vender a você."
end
str = str .. "."
npcHandler:say(str, cid)
elseif t[msg] then
if not getPlayerLearnedInstantSpell(cid, msg) then
if getPlayerLevel(cid) >= t[msg].level then
if isInArray(t[msg].vocations, getPlayerVocation(cid)) then
if doPlayerRemoveMoney(cid, t[msg].price) then
doPlayerLearnInstantSpell(cid, msg)
npcHandler:say("Você aprendeu uma nova magia chamada ".. msg .."!", cid)
else
npcHandler:say("você não tem "..t[msg].price.." gold coins.", cid)
end
else
npcHandler:say("você não tem a vocação para comprar está spell.", cid)
end
else
npcHandler:say("você precisa ter level "..t[msg].level.." ou mais para comprar essa magia.", cid)
end
else
npcHandler:say("você já aprendeu essa magia.", cid)
end
end
return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Editado por maikons (veja o histórico de edições)
Link para o post
Compartilhar em outros sites
local spells_t = {
	-- all
	["light healing"] = {price = 170, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["find person"] = {price = 60, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["magic rope"] = {price = 200, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["cure poison"] = {price = 150, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["levitate"] = {price = 500, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["great light"] = {price = 500, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["haste"] = {price = 600, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["food"] = {price = 300, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["magic shield"] = {price = 450, vocations = {1,2,3,5,6,7}, level = 1},

	["light magic missile"] = {price = 500, vocations = {1,2,5,6}, level = 1},
	["poison field"] = {price = 300, vocations = {1,2,5,6}, level = 1},
	["fire field"] = {price = 500, vocations = {1,2,5,6}, level = 1},
	["destroy field"] = {price = 700, vocations = {1,2,5,6}, level = 1},
	["energy field"] = {price = 700, vocations = {1,2,5,6}, level = 1},


	["energy strike"] = {price =800, vocations = {1,2,5,6}, level = 1},
	["poison strike"] = {price =800, vocations = {1,2,5,6}, level = 1},
	["ice strike"] = {price =800, vocations = {1,2,5,6}, level = 1},
	["flame strike"] = {price =800, vocations = {1,2,5,6}, level = 1},
	["death strike"] = {price =800, vocations = {1,2,5,6}, level = 1},

	["fire wave"] = {price =850, vocations = {1,5}, level = 1},
	["ice wave"] = {price =850, vocations = {2,6}, level = 1},
	["strong haste"] = {price = 1300, vocations = {1,2,5,6}, level = 1},
	["creature illusion"] = {price = 1000, vocations = {1,2,5,6}, level = 1},
	["summon creature"] = {price = 2000, vocations = {1,2,5,6}, level = 1},
	["ultimate light"] = {price = 1600, vocations = {1,2,5,6}, level = 1},
	["fire bomb"] = {price = 1500, vocations = {1,2,5,6}, level = 1},
	["soul fire"] = {price = 1800, vocations = {1,2,5,6}, level = 1},
	["energy bomb"] = {price = 2300, vocations = {1,2,5,6}, level = 1},
	["poison wall"] = {price = 1600, vocations = {1,2,5,6}, level = 1},
	["fire wall"] = {price = 2000, vocations = {1,2,5,6}, level = 1},
	["energy wall"] = {price = 2500, vocations = {1,2,5,6}, level = 1},
	["great fireball"] = {price = 1200, vocations = {1,2,5,6}, level = 1},
	["ultimate healing"] = {price = 1000, vocations = {1,2,3,5,6,7}, level = 1},
	["invisible"] = {price = 2000, vocations = {1,2,3,5,6,7}, level = 1},
	["magic wall"] = {price = 2100, vocations = {1,5}, level = 1},
	["mort wave"] = {price = 2500, vocations = {1,5}, level = 1},
	["enchant staff"] = {price = 2000, vocations = {1,5}, level = 1},
	["sudden death"] = {price = 3000, vocations = {1,5}, level = 1},
	["rage of the skies"] = {price = 6000, vocations = {1,5}, level = 1},
	["explosion"] = {price = 1800, vocations = {1,5}, level = 1},

	-- Pally
	["conjure arrow"] = {price = 450, vocations = {3,7}, level = 1},
	["conjure poisoned arrow"] = {price =700, vocations = {3,7}, level = 1},
	["conjure bolt"] = {price =750, vocations = {3,7}, level = 1},
	["conjure explosive arrow"] = {price = 1000, vocations = {3,7}, level = 1},
	["conjure power bolt"] = {price = 2000, vocations = {3,7}, level = 1},
	["conjure infernal bolt"] = {price = 66666, vocations = {3,7}, level = 1},

	-- Kina
	["whirlwind throw"] = {price = 1500, vocations = {4,8}, level = 1},
	["challenge"] = {price = 2000, vocations = {4,8}, level = 1},
	["berserk"] = {price = 2000, vocations = {4,8}, level = 1},

	-- Druid
	["intense healing"] = {price = 600, vocations = {2,6}, level = 1},
	["heal friend"] = {price =800, vocations = {2,6}, level = 1},
	["ultimate healing"] = {price = 1500, vocations = {2,6}, level = 1},
	["mass healing"] = {price = 2200, vocations = {2,6}, level = 1},
	["paralyze"] = {price = 1900, vocations = {2,6}, level = 1},
	["wrath of nature"] = {price = 6000, vocations = {2,6}, level = 1},
	["heavy magic missile"] = {price = 1500, vocations = {1,2,5,6}, level = 1},
	["intense healing"] = {price = 350, vocations = {1,2,3,5,6,7}, level = 1},
	["magic wall"] = {price = 2100, vocations = {1,5}, level = 1},
	["wild growth"] = {price = 4200, vocations = {2,6}, level = 1},
	["avalanche"] = {price = 3000, vocations = {2,6}, level = 1},
}

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:lower(), "spells") then
		local str = ""

		local voc = getPlayerVocation(cid)

		for name, info in pairs(spells_t) do
			if isInArray(info.vocations, voc) and not getPlayerLearnedInstantSpell(cid, name) then
				str = str .." {".. name .."} por ".. info.price .." gold coins, "
			end
		end

		if str == "" then
			str = "Eu não tenho nenhuma magia para vender a você."
		end

		npcHandler:say(str, cid)
	elseif spells_t[msg:lower()] then
		if getPlayerLearnedInstantSpell(cid, msg) then
			npcHandler:say("Você já aprendeu essa magia.", cid)
			return true
		end

		if getPlayerLevel(cid) < spells_t[msg:lower()].level then
			npcHandler:say("Você precisa ter level ".. spells_t[msg:lower()].level.." ou mais para comprar essa magia.", cid)
			return true
		end

		if not isInArray(spells_t[msg:lower()].vocations, getPlayerVocation(cid)) then
			npcHandler:say("Você não tem a vocação para comprar está spell.", cid)
			return true
		end


		if doPlayerRemoveMoney(cid, t[msg].price) then
			doPlayerLearnInstantSpell(cid, msg)
			npcHandler:say("Você aprendeu ".. msg ..".", cid)
		else
			npcHandler:say("você não tem "..t[msg].price.." gold coins.", cid)
		end

	end
	return true
end

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


Não precisava criar um duas tabelas, um com o nome da spell em maiúsculo e em minúsculo. O que fiz foi usar um string.lower(string), para transformar a mensagem em minúsculo,

-"Supra Omnes Lux Lucis"

- Acima de todos brilha a Luz -

5VGnDyBz.png

Link para o post
Compartilhar em outros sites
  • 1 month later...
local spells_t = {
	-- all
	["light healing"] = {price = 170, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["find person"] = {price = 60, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["magic rope"] = {price = 200, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["cure poison"] = {price = 150, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["levitate"] = {price = 500, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["great light"] = {price = 500, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["haste"] = {price = 600, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["food"] = {price = 300, vocations = {1,2,3,4,5,6,7,8}, level = 1},
	["magic shield"] = {price = 450, vocations = {1,2,3,5,6,7}, level = 1},

	["light magic missile"] = {price = 500, vocations = {1,2,5,6}, level = 1},
	["poison field"] = {price = 300, vocations = {1,2,5,6}, level = 1},
	["fire field"] = {price = 500, vocations = {1,2,5,6}, level = 1},
	["destroy field"] = {price = 700, vocations = {1,2,5,6}, level = 1},
	["energy field"] = {price = 700, vocations = {1,2,5,6}, level = 1},


	["energy strike"] = {price =800, vocations = {1,2,5,6}, level = 1},
	["poison strike"] = {price =800, vocations = {1,2,5,6}, level = 1},
	["ice strike"] = {price =800, vocations = {1,2,5,6}, level = 1},
	["flame strike"] = {price =800, vocations = {1,2,5,6}, level = 1},
	["death strike"] = {price =800, vocations = {1,2,5,6}, level = 1},

	["fire wave"] = {price =850, vocations = {1,5}, level = 1},
	["ice wave"] = {price =850, vocations = {2,6}, level = 1},
	["strong haste"] = {price = 1300, vocations = {1,2,5,6}, level = 1},
	["creature illusion"] = {price = 1000, vocations = {1,2,5,6}, level = 1},
	["summon creature"] = {price = 2000, vocations = {1,2,5,6}, level = 1},
	["ultimate light"] = {price = 1600, vocations = {1,2,5,6}, level = 1},
	["fire bomb"] = {price = 1500, vocations = {1,2,5,6}, level = 1},
	["soul fire"] = {price = 1800, vocations = {1,2,5,6}, level = 1},
	["energy bomb"] = {price = 2300, vocations = {1,2,5,6}, level = 1},
	["poison wall"] = {price = 1600, vocations = {1,2,5,6}, level = 1},
	["fire wall"] = {price = 2000, vocations = {1,2,5,6}, level = 1},
	["energy wall"] = {price = 2500, vocations = {1,2,5,6}, level = 1},
	["great fireball"] = {price = 1200, vocations = {1,2,5,6}, level = 1},
	["ultimate healing"] = {price = 1000, vocations = {1,2,3,5,6,7}, level = 1},
	["invisible"] = {price = 2000, vocations = {1,2,3,5,6,7}, level = 1},
	["magic wall"] = {price = 2100, vocations = {1,5}, level = 1},
	["mort wave"] = {price = 2500, vocations = {1,5}, level = 1},
	["enchant staff"] = {price = 2000, vocations = {1,5}, level = 1},
	["sudden death"] = {price = 3000, vocations = {1,5}, level = 1},
	["rage of the skies"] = {price = 6000, vocations = {1,5}, level = 1},
	["explosion"] = {price = 1800, vocations = {1,5}, level = 1},

	-- Pally
	["conjure arrow"] = {price = 450, vocations = {3,7}, level = 1},
	["conjure poisoned arrow"] = {price =700, vocations = {3,7}, level = 1},
	["conjure bolt"] = {price =750, vocations = {3,7}, level = 1},
	["conjure explosive arrow"] = {price = 1000, vocations = {3,7}, level = 1},
	["conjure power bolt"] = {price = 2000, vocations = {3,7}, level = 1},
	["conjure infernal bolt"] = {price = 66666, vocations = {3,7}, level = 1},

	-- Kina
	["whirlwind throw"] = {price = 1500, vocations = {4,8}, level = 1},
	["challenge"] = {price = 2000, vocations = {4,8}, level = 1},
	["berserk"] = {price = 2000, vocations = {4,8}, level = 1},

	-- Druid
	["intense healing"] = {price = 600, vocations = {2,6}, level = 1},
	["heal friend"] = {price =800, vocations = {2,6}, level = 1},
	["ultimate healing"] = {price = 1500, vocations = {2,6}, level = 1},
	["mass healing"] = {price = 2200, vocations = {2,6}, level = 1},
	["paralyze"] = {price = 1900, vocations = {2,6}, level = 1},
	["wrath of nature"] = {price = 6000, vocations = {2,6}, level = 1},
	["heavy magic missile"] = {price = 1500, vocations = {1,2,5,6}, level = 1},
	["intense healing"] = {price = 350, vocations = {1,2,3,5,6,7}, level = 1},
	["magic wall"] = {price = 2100, vocations = {1,5}, level = 1},
	["wild growth"] = {price = 4200, vocations = {2,6}, level = 1},
	["avalanche"] = {price = 3000, vocations = {2,6}, level = 1},
}

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:lower(), "spells") then
		local str = ""

		local voc = getPlayerVocation(cid)

		for name, info in pairs(spells_t) do
			if isInArray(info.vocations, voc) and not getPlayerLearnedInstantSpell(cid, name) then
				str = str .." {".. name .."} por ".. info.price .." gold coins, "
			end
		end

		if str == "" then
			str = "Eu não tenho nenhuma magia para vender a você."
		end

		npcHandler:say(str, cid)
	elseif spells_t[msg:lower()] then
		if getPlayerLearnedInstantSpell(cid, msg) then
			npcHandler:say("Você já aprendeu essa magia.", cid)
			return true
		end

		if getPlayerLevel(cid) < spells_t[msg:lower()].level then
			npcHandler:say("Você precisa ter level ".. spells_t[msg:lower()].level.." ou mais para comprar essa magia.", cid)
			return true
		end

		if not isInArray(spells_t[msg:lower()].vocations, getPlayerVocation(cid)) then
			npcHandler:say("Você não tem a vocação para comprar está spell.", cid)
			return true
		end


		if doPlayerRemoveMoney(cid, t[msg].price) then
			doPlayerLearnInstantSpell(cid, msg)
			npcHandler:say("Você aprendeu ".. msg ..".", cid)
		else
			npcHandler:say("você não tem "..t[msg].price.." gold coins.", cid)
		end

	end
	return true
end

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


Não precisava criar um duas tabelas, um com o nome da spell em maiúsculo e em minúsculo. O que fiz foi usar um string.lower(string), para transformar a mensagem em minúsculo,

 

 

Eu falo: hi, spells aparece as magias, mas qnd eu escolho uma
[Error - NpcScript Interface]
data/npc/scripts/spellseller.lua:onCreatureSay
Description:
data/npc/scripts/spellseller.lua:123: attempt to index global 't' <a nil value>
stack traceback
data/npc/scripts/spellseller.lua:123: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:423: in function 'onCreatureSay'
data/npc/scripts/spellseller.lua:81: in funcion <data/npc/scripts/spellseller.lua:81>
Link para o post
Compartilhar em outros sites

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.

Visitante
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo