peteralto
Member
- Joined
- Nov 1, 2020
- Messages
- 93
- Solutions
- 1
- Reaction score
- 19
I tried to use/adapt the code from an NPC from the Canary base, but in TFS 1.3+ it is giving the following errors:
Script.lua
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/Maeryn.lua:onCreatureSay
data/npc/scripts/Maeryn.lua:25: attempt to call method 'getId' (a nil value)
stack traceback:
[C]: in function 'getId'
data/npc/scripts/Maeryn.lua:25: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:358: in function 'greet'
data/npc/lib/npcsystem/npchandler.lua:557: in function 'onGreet'
data/npc/lib/npcsystem/modules.lua:335: in function 'callback'
data/npc/lib/npcsystem/keywordhandler.lua:31: in function 'processMessage'
data/npc/lib/npcsystem/keywordhandler.lua:186: in function 'processNodeMessage'
data/npc/lib/npcsystem/keywordhandler.lua:154: in function 'processMessage'
data/npc/lib/npcsystem/npchandler.lua:432: in function 'onCreatureSay'
data/npc/scripts/Maeryn.lua:7: in function <data/npc/scripts/Maeryn.lua:7>
Lua Script Error: [Npc interface]
data/npc/scripts/Maeryn.lua:onCreatureSay
data/npc/scripts/Maeryn.lua:32: attempt to index local 'player' (a nil value)
stack traceback:
[C]: in function '__index'
data/npc/scripts/Maeryn.lua:32: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:435: in function 'onCreatureSay'
data/npc/scripts/Maeryn.lua:7: in function <data/npc/scripts/Maeryn.lua:7>
Script.lua
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 vocations = {
['sorcerer'] = 0,
['druid'] = 1,
['paladin'] = 2,
['knight'] = {
['club'] = 3,
['axe'] = 4,
['sword'] = 5,
}
}
local knightChoice = {}
local function greetCallback(npc, creature)
local playerId = creature:getId()
knightChoice[playerId] = nil
return true
end
local function creatureSayCallback(npc, creature, type, message)
local player = Player(creature)
local playerId = player:getId()
if MsgContains(message, 'helmet') then
npcHandler:say("You brought the wolven helmet, as i see. Do you want to change something?", npc, creature)
npcHandler:setTopic(playerId, 1)
elseif MsgContains(message, 'yes') then
if npcHandler:getTopic(playerId) == 1 then
npcHandler:say("So, which profession would you give preference to when enchanting the helmet: {knight}, {sorcerer}, {druid} or {paladin}?", npc, creature)
npcHandler:setTopic(playerId, 2)
end
elseif isInArray({'knight', 'sorcerer', 'druid', 'paladin'}, message:lower()) and npcHandler:getTopic(playerId) == 2 then
local helmet = message:lower()
if not vocations[helmet] then
return false
end
if message:lower() == 'knight' then
npcHandler:say("And what would be your preferred weapon? {Club}, {axe} or {sword}", npc, creature)
knightChoice[playerId] = helmet
npcHandler:setTopic(playerId, 3)
end
if npcHandler:getTopic(playerId) == 2 then
player:setStorageValue(Storage.Grimvale.WereHelmetEnchant, vocations[helmet])
npcHandler:say("So this is your choice. If you want to change it, you will have to come to me again.", npc, creature)
npcHandler:setTopic(playerId, 0)
end
elseif isInArray({'axe', 'club', 'sword'}, message:lower()) and npcHandler:getTopic(playerId) == 3 then
local weapontype = message:lower()
if not vocations[knightChoice[playerId]][weapontype] then
return false
else
player:setStorageValue(Storage.Grimvale.WereHelmetEnchant, vocations[knightChoice[playerId]][weapontype])
npcHandler:say("So this is your choice. If you want to change it, you will have to come to me again.", npc, creature)
knightChoice[playerId] = nil
npcHandler:setTopic(playerId, 0)
end
end
end
npcHandler:setMessage(MESSAGE_GREET, "Greetings, visitor. I wonder what may lead you to this dangerous place.")
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())