nefinoo
Carnage.flv
Can you help me to make this npc have a condition that can only be traded (in this case say spells will open the shop module) when you complete a mission and get the following Storage.Trader.Merlin, i am using tfs 1.3
Lua:
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
npcHandler:setMessage(MESSAGE_GREET, "Hello, |PLAYERNAME|. Are you looking to buy some {spells}?")
local PremiumSpells = false
local AllSpells = false
-- 1,5 Sorcerer
-- 2,6 Druid
-- 3,7 Paladin
-- 4,8 Knight
local spells = {
[2312] = { buy = 500000, spell = "Ultra Thunderstorm", name = "Conjure Ultra Thunderstorm", vocations = {1,5}, level = 300, premium = 1},
[2300] = { buy = 500000, spell = "Ultra Holy Missile", name = "Conjure Ultra Holy Missile", vocations = {3,7}, level = 300, premium = 1},
[2314] = { buy = 500000, spell = "Ultra Explosion", name = "Conjure Ultra Explosion", vocations = {1,2,5,6}, level = 300, premium = 1},
[2275] = { buy = 500000, spell = "Ultra Avalanche", name = "Conjure Ultra Avalanche", vocations = {2,6}, level = 300, premium = 1},
[2264] = { buy = 500000, spell = "Ultra Stone Shower", name = "Conjure Ultra Stone Shower", vocations = {2,6}, level = 300, premium = 1},
[2294] = { buy = 500000, spell = "Ultra Magic Wall", name = "Conjure Ultra Magic Wall", vocations = {1,5}, level = 300, premium = 1},
[2270] = { buy = 500000, spell = "Ultra Wild Growth", name = "Conjure Ultra Wild Growth", vocations = {2,6}, level = 300, premium = 1},
[2281] = { buy = 500000, spell = "Ultra Paralyze", name = "Conjure Ultra Paralyze", vocations = {2,6}, level = 300, premium = 1},
[2306] = { buy = 500000, spell = "Ultra Great Fireball", name = "Conjure Ultra Great Fireball", vocations = {1,5}, level = 300, premium = 1},
[2263] = { buy = 500000, spell = "Ultra Sudden Death", name = "Conjure Ultra Sudden Death", vocations = {1,5}, level = 300, premium = 1}
}
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local shopWindow = {}
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local function onBuy(cid, item, subType, amount, ignoreCap, inBackpacks)
local npc = Npc()
npc:say("You have choosen the spell: " .. spells[item].spell .. " which costs " .. spells[item].buy .. " gold.", TALKTYPE_PRIVATE_NP)
local player = Player(cid)
if player:hasLearnedSpell(spells[item].spell) then
npc:say("You already know this spell.", TALKTYPE_PRIVATE_NP)
return false
end
if player:getLevel() < spells[item].level then
npc:say("You need to obtain a level of " .. spells[item].level .. " or higher to be able to learn this spell.", TALKTYPE_PRIVATE_NP)
return false
end
if not isInArray(spells[item].vocations, player:getVocation():getBase():getId()) then
npc:say("This spell is not for your vocation.", TALKTYPE_PRIVATE_NP)
return false
end
if PremiumSpells and (spells[item].premium == 1) and not player:isPremium() then
npc:say("You need to be premium in order to obtain this spell.", TALKTYPE_PRIVATE_NP)
return false
end
if player:getMoney() < spells[item].buy then
npc:say("You don't have enough money.", TALKTYPE_PRIVATE_NP)
return false
end
player:removeMoney(spells[item].buy)
player:learnSpell(spells[item].spell)
player:getPosition():sendMagicEffect(12)
npc:say("You have learned " .. spells[item].spell .. ".", TALKTYPE_PRIVATE_NP)
return true
end
local player = Player(cid)
if msgcontains(msg, "spells") then
npcHandler:say("Here are the spells that you can learn from me.", cid)
for var, item in pairs(spells) do
if not AllSpells then
if not player:hasLearnedSpell(item.spell) then
if player:getLevel() >= item.level then
if isInArray(item.vocations, player:getVocation():getId()) then
if PremiumSpells then
if (item.premium == 1) and player:isPremium() then
if Player(cid):getStorageValue(Storage.TravellingTrader.Mission07) ~= 1 then
npcHandler:say('Sorry, but you do not belong to my exclusive customers. I have to make sure that I can trust in the quality of your wares.', cid)
return false
end
table.insert(shopWindow, {id = var, subType = 0, buy = item.buy, sell = 0, name = item.name})
end
else
table.insert(shopWindow, {id = var, subType = 0, buy = item.buy, sell = 0, name = item.name})
end
end
end
end
else
table.insert(shopWindow, {id = var, subType = 0, buy = item.buy, sell = 0, name = item.name})
end
end
openShopWindow(cid, shopWindow, onBuy, onSell)
end
return true
end
npcHandler:setMessage(MESSAGE_FAREWELL, "Bye!")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye, have a nice day!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())