D
Deleted member 49793
Guest
Basicly the npc wont spawn (i tested with other scripts so the npc is fine its the script) I cant see the loading errors however as im with znote hosting my server so... if anyone could scan through this and see if theres any obvious errors, thanks
Code:
local ItemList = {
-- ["Item Name"] = {Required = {Item=itemid, Count=count}, RewardType = (1 = exp, 2 = item}, Reward = (Normal number if experience, {itemid, count} if using item reward.
["Fire Shard"] = {Required = {Item=9141Count=10}, RewardType = 1, Reward = 10000},
["Water Shard"] = {Required = {Item=7289, Count=10}, RewardType = 1, Reward = 40000},
["Earth Shard"] = {Required = {Item=11389, Count=10}, RewardType = 1, Reward = 100000},
["Glowing Shard"] = {Required = {Item=11390, Count=1}, RewardType = 1, Reward = 80000},
["Ice Shard"] = {Required = {Item=11391, Count=1}, RewardType = 1, Reward = 200000},
["Magma Shard"] = {Required = {Item=11392, Count=1}, RewardType = 1, Reward = 500000},
}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}
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
elseif msgcontains(msg, 'items') or msgcontains(msg, 'trade') then
local str,c = "I can exchange your ",0
for k, v in pairs(ItemList) do
if c~=0 then str = str .. ", " end
if getPlayerItemCount(cid, v.Required.Item) >= v.Required.Count then
str = str .. "{"..k.."}"
else
str = str .. k
end
c=c+1
end
str = str .. " for experience and items."
npcHandler:say(str, cid)
elseif Topic[cid] then
if msgcontains(msg, 'yes') then
local Reward = ItemList[Topic[cid]]
if getPlayerItemCount(cid, Reward.Required.Item) < Reward.Required.Count then
npcHandler:say("Sorry, you can't do this.", cid)
Topic[cid] = nil
return true
end
if Reward.RewardType == 1 then
doPlayerRemoveItem(cid, Reward.Required.Item, Reward.Required.Count)
doPlayerAddExperience(cid, Reward.Reward)
npcHandler:say("Thank you! I have blessed you with " .. Reward.Reward .. " experience!", cid)
else
local tmpItem = doCreateItemEx(Reward.Reward[1], Reward.Reward[2])
doPlayerRemoveItem(cid, Reward.Required.Item, Reward.Required.Count)
if doPlayerAddItemEx(cid, tmpItem, true) then
npcHandler:say("Thank you! I have rewarded you with " .. Reward.Reward[2] .. "x " .. getItemInfo(Reward.Reward[1]).name .. ".", cid)
else
npcHandler:say("You can not carry your reward! Make some room and come back!", cid)
end
end
Topic[cid] = nil
else
npcHandler:say("Maybe another time.", cid)
return true
end
end
for k,v in pairs(ItemList) do
if msgcontains(msg, k) then
if getPlayerItemCount(cid, v.Required.Item) >= v.Required.Count then
npcHandler:say("Do you want to exchange " .. v.Required.Count .. "x " .. getItemInfo(v.Required.Item).name .. " for " .. (v.RewardType == 1 and v.Reward .. " experience" or v.Reward[2] .. "x " .. getItemInfo(v.Reward[1]).name) .. "?", cid)
Topic[cid] = k
break
else
npcHandler:say("You do not have enough " .. getItemInfo(v.Required.Item).name .. " to give me. If you bring me " .. v.Required.Count-getPlayerItemCount(cid, v.Required.Item) .. " more I will reward you with " .. (v.RewardType == 1 and v.Reward .. " experience" or v.Reward[2] .. "x " .. getItemInfo(v.Reward[1]).name) .. ".", cid)
break
end
end
end
return true
end
function greetCallback(cid)
Topic[cid] = nil
return true
end
npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. You can redeem {items} for experience points through me.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:addModule(FocusModule:new())