Nothxbye
Banned User
- Joined
- Jan 22, 2012
- Messages
- 1,124
- Reaction score
- 174
Today i made script for spell learn and im not so good with "table" configurations so i wanna ask if someone who knows his stuff to check srcipt because i have some errors. Also will be awesome if someone check the whole script because i think its not written as it should be i mean "locals" ect.
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local spells = {}
local t = {}
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(npcHandler.focus ~= cid) then
return 0
end
local spells = {
["find person"] = {price = 80},
["light healing"] = {price = 170}
}
for i, v in pairs(spells) do
if (string.find(msg, i)) then
local t = spells[i]
npcHandler:say("Do you want to buy the spell "..i.." for "..t.price.." gold?", cid)
talkState[talkUser] = 1
elseif (msgcontains(msg, "yes")) and (talkState[talkUser] == 1) then
if (getPlayerLearnedInstantSpell(cid,i) ~= TRUE) then
if (doPlayerRemoveMoney(cid,t.price) == TRUE) then
npcHandler:say("Here you are "..i.." "..t.price..". Look in your spellbook for the pronunciation of this spell.",cid)
doSendMagicEffect(getCreaturePosition(cid),12)
--playerLearnInstantSpell(cid,i)
else
npcHandler:say("You need more money.",cid)
talkState[talkUser] = 0
end
else
npcHandler:say("You already know how to cast this spell.",cid)
talkState[talkUser] = 0
end
end
end
return 1
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Code:
[31/03/2012 19:48:18] Lua Script Error: [Npc interface]
[31/03/2012 19:48:18] data/npc/scripts/abran.lua:onCreatureSay
[31/03/2012 19:48:18] data/npc/scripts/abran.lua:31: attempt to concatenate field 'price' (a nil value)
[31/03/2012 19:48:18] stack traceback:
[31/03/2012 19:48:18] data/npc/scripts/abran.lua:31: in function 'callback'
[31/03/2012 19:48:18] ./data/npc/lib/npcsystem/npchandler.lua:337: in function 'onCreatureSay'
[31/03/2012 19:48:18] data/npc/scripts/abran.lua:10: in function <data/npc/scripts/abran.lua:10>