Thorn
Spriting since 2013
Hello guys, i use a tfs 1.3 and i took Umar from orts datapack, but this npc is giving me trouble everytime i talk to him...i tried everything i know to make him work, compared to other npcs, tried multiple times multiple variables, but nothing, so im posting here begging for help plz!! this is the error it shows up in console everytime i talk to him
this is the file that is giving error:
and this is the npc
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/Umar.lua:onCreatureSay
data/npc/lib/npc.lua:6: attempt to index local 'message' (a nil value)
stack traceback:
[C]: in function '__index'
data/npc/lib/npc.lua:6: in function 'msgcontains'
data/npc/scripts/Umar.lua:12: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:340: in function 'greet'
data/npc/lib/npcsystem/npchandler.lua:519: in function 'onGreet'
data/npc/lib/npcsystem/modules.lua:322: in function 'callback'
data/npc/lib/npcsystem/keywordhandler.lua:26: in function 'processMessage'
data/npc/lib/npcsystem/keywordhandler.lua:136: in function 'processNodeMessage'
data/npc/lib/npcsystem/keywordhandler.lua:104: in function 'processMessage'
data/npc/lib/npcsystem/npchandler.lua:408: in function 'onCreatureSay'
data/npc/scripts/Umar.lua:7: in function <data/npc/scripts/Umar.lua:7>
this is the file that is giving error:
LUA:
-- Including the Advanced NPC System
dofile('data/npc/lib/npcsystem/npcsystem.lua')
dofile('data/npc/lib/npcsystem/customModules.lua')
function msgcontains(message, keyword)
local message, keyword = message:lower(), keyword:lower()
if message == keyword then
return true
end
return message:find(keyword) and not message:find('(%w+)' .. keyword)
end
function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
local amount = amount or 1
local subType = subType or 0
local item = 0
if isItemStackable(itemid) then
if inBackpacks then
stuff = doCreateItemEx(backpack, 1)
item = doAddContainerItem(stuff, itemid, math.min(100, amount))
else
stuff = doCreateItemEx(itemid, math.min(100, amount))
end
return doPlayerAddItemEx(cid, stuff, ignoreCap) ~= RETURNVALUE_NOERROR and 0 or amount, 0
end
local a = 0
if inBackpacks then
local container, b = doCreateItemEx(backpack, 1), 1
for i = 1, amount do
local item = doAddContainerItem(container, itemid, subType)
if table.contains({(getContainerCapById(backpack) * b), amount}, i) then
if doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR then
b = b - 1
break
end
a = i
if amount > i then
container = doCreateItemEx(backpack, 1)
b = b + 1
end
end
end
return a, b
end
for i = 1, amount do -- normal method for non-stackable items
local item = doCreateItemEx(itemid, subType)
if doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR then
break
end
a = i
end
return a, 0
end
local func = function(cid, text, type, e, pcid)
if isPlayer(pcid) then
doCreatureSay(cid, text, type, false, pcid, getCreaturePosition(cid))
e.done = TRUE
end
end
function doCreatureSayWithDelay(cid, text, type, delay, e, pcid)
if isPlayer(pcid) then
e.done = FALSE
e.event = addEvent(func, delay < 1 and 1000 or delay, cid, text, type, e, pcid)
end
end
function doPlayerTakeItem(cid, itemid, count)
if getPlayerItemCount(cid,itemid) < count then
return false
end
while count > 0 do
local tempcount = 0
if isItemStackable(itemid) then
tempcount = math.min (100, count)
else
tempcount = 1
end
local ret = doPlayerRemoveItem(cid, itemid, tempcount)
if ret ~= false then
count = count - tempcount
else
return false
end
end
if count ~= 0 then
return false
end
return true
end
function doPlayerSellItem(cid, itemid, count, cost)
if doPlayerTakeItem(cid, itemid, count) == true then
if not doPlayerAddMoney(cid, cost) then
error('Could not add money to ' .. getPlayerName(cid) .. '(' .. cost .. 'gp)')
end
return true
end
return false
end
function doPlayerBuyItemContainer(cid, containerid, itemid, count, cost, charges)
if not doPlayerRemoveMoney(cid, cost) then
return false
end
for i = 1, count do
local container = doCreateItemEx(containerid, 1)
for x = 1, getContainerCapById(containerid) do
doAddContainerItem(container, itemid, charges)
end
if doPlayerAddItemEx(cid, container, true) ~= RETURNVALUE_NOERROR then
return false
end
end
return true
end
function getCount(string)
local b, e = string:find("%d+")
return b and e and tonumber(string:sub(b, e)) or -1
end
and this is the npc
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
local function greetCallback(cid, message)
local player = Player(cid)
if not msgcontains(message, 'djanni\'hah') and player:getStorageValue(Storage.DjinnWar.Faction.Marid) ~= 1 then
npcHandler:say('Whoa! A human! This is no place for you, |PLAYERNAME|. Go and play somewhere else.', cid)
return false
end
if player:getStorageValue(Storage.DjinnWar.Faction.Greeting) == -1 then
npcHandler:say({
'Hahahaha! ...',
'|PLAYERNAME|, that almost sounded like the word of greeting. Humans - cute they are!'
}, cid)
return false
end
if player:getStorageValue(Storage.DjinnWar.Faction.Marid) ~= 1 then
npcHandler:setMessage(MESSAGE_GREET, {
'Whoa? You know the word! Amazing, |PLAYERNAME|! ...',
'I should go and tell Fa\'hradin. ...',
'Well. Why are you here anyway, |PLAYERNAME|?'
})
else
npcHandler:setMessage(MESSAGE_GREET, '|PLAYERNAME|! How\'s it going these days? What brings you {here}?')
end
return true
end
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
if msgcontains(msg, 'passage') then
if player:getStorageValue(Storage.DjinnWar.Faction.Marid) ~= 1 then
npcHandler:say({
'If you want to enter our fortress you have to become one of us and fight the Efreet. ...',
'So, are you willing to do so?'
}, cid)
npcHandler.topic[cid] = 1
else
npcHandler:say('You already have the permission to enter Ashta\'daramai.', cid)
end
elseif npcHandler.topic[cid] == 1 then
if msgcontains(msg, 'yes') then
if player:getStorageValue(Storage.DjinnWar.Faction.Efreet) ~= 1 then
npcHandler:say('Are you sure? You pledge loyalty to king Gabel, who is... you know. And you are willing to never ever set foot on Efreets\' territory, unless you want to kill them? Yes?', cid)
npcHandler.topic[cid] = 2
else
npcHandler:say('I don\'t believe you! You better go now.', cid)
npcHandler.topic[cid] = 0
end
elseif msgcontains(msg, 'no') then
npcHandler:say('This isn\'t your war anyway, human.', cid)
npcHandler.topic[cid] = 0
end
elseif npcHandler.topic[cid] == 2 then
if msgcontains(msg, 'yes') then
npcHandler:say({
'Oh. Ok. Welcome then. You may pass. ...',
'And don\'t forget to kill some Efreets, now and then.'
}, cid)
player:setStorageValue(Storage.DjinnWar.Faction.Marid, 1)
player:setStorageValue(Storage.DjinnWar.Faction.Greeting, 0)
elseif msgcontains(msg, 'no') then
npcHandler:say('This isn\'t your war anyway, human.', cid)
end
npcHandler.topic[cid] = 0
end
return true
end
npcHandler:setMessage(MESSAGE_FAREWELL, '<salutes>Aaaa -tention!')
npcHandler:setMessage(MESSAGE_WALKAWAY, '<salutes>Aaaa -tention!')
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
local focusModule = FocusModule:new()
focusModule:addGreetMessage('hi')
focusModule:addGreetMessage('hello')
focusModule:addGreetMessage('djanni\'hah')
npcHandler:addModule(focusModule)
Last edited: