• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved Santa Claus (TFS 1.0)

Zoriax_

Owner|Antarctica Ots
Joined
Feb 15, 2008
Messages
745
Reaction score
23
Location
Norway
Error

Code:
Lua Script Error: [Npc interface]
data/npc/scripts/santa.lua:onCreatureSay
data/npc/scripts/santa.lua:39: attempt to compare number with table
stack traceback:
        [C]: ?
        data/npc/scripts/santa.lua:39: in function 'callback'
        data/npc/lib/npcsystem/keywordhandler.lua:26: in function 'processMessag
e'
        data/npc/lib/npcsystem/keywordhandler.lua:136: in function 'processNodeM
essage'
        data/npc/lib/npcsystem/keywordhandler.lua:104: in function 'processMessa
ge'
        data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
        data/npc/scripts/santa.lua:21: in function <data/npc/scripts/santa.lua:2
1>


Santa Claus.lua

Code:
local PRESENT_STORAGE = 29884 -- Storage ID
local gifts = {
{10, 6531, 1}, -- 1% to get Santa Hat [10]
{30, 6512, 1}, -- 3% to get Santa Doll [30]
{40, 2112, 1}, -- 4% to get Teddy Bear [40]
{100, 2160, 10}, -- 10% to get 10 Crystal Coins [100]
{150, 2688, 10}, -- 15% to get 10 Candy Canes [150]
{150, 2152, 100}, -- 15% to get 100 Platinum Coins [150]
{200, 2111, 5}, -- 20% to get 10 Snowballs [200]
{250, 2675, 10}, -- 25% to get 10 Orange [250]
{350, 2674, 15}, -- 35% to get 10 Red Apples [350]
{500, 2687, 10} -- 50% to get 10 Cookies [500]
}

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

function SantaNPC(cid, message, keywords, parameters, node)
if(not npcHandler:isFocused(cid)) then
return false
end
if (parameters.present == true) then
if (getPlayerStorageValue(cid, PRESENT_STORAGE) == 1) then
selfSay("Do not try to trick me! You have already recieved your present...", cid)
return true
end

local item = {}
local reward = 0
local count = ""
for i = 1, #gifts do
item = gifts
if (math.random(0,999) < item[1]) then
reward = item[]
subType = item[]
if subType > 1 then
count = subType .. " "
end
break
end
end
doPlayerAddItem(cid, reward, subType)
setPlayerStorageValue(cid, PRESENT_STORAGE, 1)
npcHandler:say('HO-HO-HO! I have ' .. count .. getItemNameById(reward) .. ' for you.', cid)
else
npcHandler:say('Come back when you start behaving.', cid)
end
npcHandler:resetNpc()
return true
end

npcHandler:setMessage(MESSAGE_GREET, "HO-HO-HO, Merry Christmas |PLAYERNAME|. I have presents for the good children.")

local noNode = KeywordNode:new({'no'}, SantaNPC, {present = false})
local yesNode = KeywordNode:new({'yes'}, SantaNPC, {present = true})

local node = keywordHandler:addKeyword({'present'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Have you been well behaved and good this year?...'})
node:addChildKeywordNode(yesNode)
node:addChildKeywordNode(noNode)

npcHandler:addModule(FocusModule:new())


 
Change
Code:
item = gifts
to
Code:
item = gifts[i]

Change getItemNameById to getItemName
 
Still got error :/


Code:
Lua Script Error: [Npc interface]
data/npc/scripts/santa.lua:onCreatureSay
data/npc/scripts/santa.lua:39: attempt to compare number with table
stack traceback:
        [C]: ?
        data/npc/scripts/santa.lua:39: in function 'callback'
        data/npc/lib/npcsystem/keywordhandler.lua:26: in function 'processMessag
e'
        data/npc/lib/npcsystem/keywordhandler.lua:136: in function 'processNodeM
essage'
        data/npc/lib/npcsystem/keywordhandler.lua:111: in function 'processMessa
ge'
        data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
        data/npc/scripts/santa.lua:21: in function <data/npc/scripts/santa.lua:2
1>
 
Code:
local PRESENT_STORAGE = 29884 -- Storage ID
local gifts = {
    {10, 6531, 1}, -- 1% to get Santa Hat [10]
    {30, 6512, 1}, -- 3% to get Santa Doll [30]
    {40, 2112, 1}, -- 4% to get Teddy Bear [40]
    {100, 2160, 10}, -- 10% to get 10 Crystal Coins [100]
    {150, 2688, 10}, -- 15% to get 10 Candy Canes [150]
    {150, 2152, 100}, -- 15% to get 100 Platinum Coins [150]
    {200, 2111, 5}, -- 20% to get 10 Snowballs [200]
    {250, 2675, 10}, -- 25% to get 10 Orange [250]
    {350, 2674, 15}, -- 35% to get 10 Red Apples [350]
    {500, 2687, 10} -- 50% to get 10 Cookies [500]
}

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

function SantaNPC(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

    if parameters.present then
        if (getPlayerStorageValue(cid, PRESENT_STORAGE) == 1) then
            selfSay("Do not try to trick me! You have already recieved your present...", cid)
            return true
        end

        local item = {}
        local reward = 0
        local count = 1
        for i = 1, #gifts do
            item = gifts[i]
            if (math.random(0, 999) < item[1]) then
                reward = item[2]
                subType = item[3]
                if subType > 1 then
                    count = subType
                end
                break
            end
        end

        doPlayerAddItem(cid, reward, subType)
        setPlayerStorageValue(cid, PRESENT_STORAGE, 1)
        npcHandler:say('HO-HO-HO! I have ' .. count .. ' ' .. getItemName(reward) .. ' for you.', cid)
    else
        npcHandler:say('Come back when you start behaving.', cid)
    end
    npcHandler:resetNpc()
    return true
end

npcHandler:setMessage(MESSAGE_GREET, "HO-HO-HO, Merry Christmas |PLAYERNAME|. I have presents for the good children.")

local noNode = KeywordNode:new({'no'}, SantaNPC, {present = false})
local yesNode = KeywordNode:new({'yes'}, SantaNPC, {present = true})

local node = keywordHandler:addKeyword({'present'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Have you been well behaved and good this year?...'})
node:addChildKeywordNode(yesNode)
node:addChildKeywordNode(noNode)

npcHandler:addModule(FocusModule:new())
 
Code:
local PRESENT_STORAGE = 29884 -- Storage ID
local gifts = {
    {10, 6531, 1}, -- 1% to get Santa Hat [10]
    {30, 6512, 1}, -- 3% to get Santa Doll [30]
    {40, 2112, 1}, -- 4% to get Teddy Bear [40]
    {100, 2160, 10}, -- 10% to get 10 Crystal Coins [100]
    {150, 2688, 10}, -- 15% to get 10 Candy Canes [150]
    {150, 2152, 100}, -- 15% to get 100 Platinum Coins [150]
    {200, 2111, 5}, -- 20% to get 10 Snowballs [200]
    {250, 2675, 10}, -- 25% to get 10 Orange [250]
    {350, 2674, 15}, -- 35% to get 10 Red Apples [350]
    {500, 2687, 10} -- 50% to get 10 Cookies [500]
}

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

function SantaNPC(cid, message, keywords, parameters, node)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if parameters.present then
        local player = Player(cid)
        if player:getStorageValue(PRESENT_STORAGE) == 1 then
            selfSay("Do not try to trick me! You have already recieved your present...", cid)
            return true
        end

        local item
        for i = 1, #gifts do
            item = gifts[i]
            if math.random(0, 999) < item[1] then
                local itemId, count = item[2], item[3]
                player:addItem(itemId, count)
                player:setStorageValue(PRESENT_STORAGE, 1)
                npcHandler:say('HO-HO-HO! I have ' .. count .. ' ' .. ItemType(itemId):getName() .. ' for you.', cid)
                break
            end
        end
    else
        npcHandler:say('Come back when you start behaving.', cid)
    end
    npcHandler:resetNpc()
    return true
end

npcHandler:setMessage(MESSAGE_GREET, "HO-HO-HO, Merry Christmas |PLAYERNAME|. I have presents for the good children.")

local noNode = KeywordNode:new({'no'}, SantaNPC, {present = false})
local yesNode = KeywordNode:new({'yes'}, SantaNPC, {present = true})

local node = keywordHandler:addKeyword({'present'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Have you been well behaved and good this year?...'})
node:addChildKeywordNode(yesNode)
node:addChildKeywordNode(noNode)

npcHandler:addModule(FocusModule:new())
Don't forget to reload NPCs
 
Try this, I tested it and it was working for me.
Code:
local PRESENT_STORAGE = 29884 -- Storage ID
local gifts = {
{10, 6531, 1}, -- 1% to get Santa Hat [10]
{30, 6512, 1}, -- 3% to get Santa Doll [30]
{40, 2112, 1}, -- 4% to get Teddy Bear [40]
{100, 2160, 10}, -- 10% to get 10 Crystal Coins [100]
{150, 2688, 10}, -- 15% to get 10 Candy Canes [150]
{150, 2152, 100}, -- 15% to get 100 Platinum Coins [150]
{200, 2111, 5}, -- 20% to get 10 Snowballs [200]
{250, 2675, 10}, -- 25% to get 10 Orange [250]
{350, 2674, 15}, -- 35% to get 10 Red Apples [350]
{500, 2687, 10} -- 50% to get 10 Cookies [500]
}

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

function SantaNPC(cid, message, keywords, parameters, node)
    local player = Player(cid)
    if(not npcHandler:isFocused(cid)) then
    return false
    end
   
    if (parameters.present == true) then
        if (player:getStorageValue(PRESENT_STORAGE) == 1) then
        selfSay("Do not try to trick me! You have already recieved your present...", cid)
        return true
        end

        for i = 1, #gifts do
            if (math.random(0,999) < gifts[i][1]) then
            reward = gifts[i][2]
            subType = gifts[i][3]
            break
            end
        end
        player:addItem(reward, subType)
        player:setStorageValue(PRESENT_STORAGE, 1)
        npcHandler:say('HO-HO-HO! I have ' .. subType ..' '.. ItemType(reward):getName() .. ' for you.', cid)
    else
        npcHandler:say('Come back when you start behaving.', cid)
    end
npcHandler:resetNpc()
return true
end

npcHandler:setMessage(MESSAGE_GREET, "HO-HO-HO, Merry Christmas |PLAYERNAME|. I have presents for the good children.")

local noNode = KeywordNode:new({'no'}, SantaNPC, {present = false})
local yesNode = KeywordNode:new({'yes'}, SantaNPC, {present = true})

local node = keywordHandler:addKeyword({'present'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Have you been well behaved and good this year?...'})
node:addChildKeywordNode(yesNode)
node:addChildKeywordNode(noNode)

npcHandler:addModule(FocusModule:new())
 
I still get this error

Code:
Lua Script Error: [Npc interface]
data/npc/scripts/santa.lua:onCreatureSay
data/npc/scripts/santa.lua:39: attempt to compare number with table
stack traceback:
        [C]: ?
        data/npc/scripts/santa.lua:39: in function 'callback'
        data/npc/lib/npcsystem/keywordhandler.lua:26: in function 'processMessag
e'
        data/npc/lib/npcsystem/keywordhandler.lua:136: in function 'processNodeM
essage'
        data/npc/lib/npcsystem/keywordhandler.lua:104: in function 'processMessa
ge'
        data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
        data/npc/scripts/santa.lua:21: in function <data/npc/scripts/santa.lua:2
1>
 
Are you sure you're editing the right script?

Because line 39 from Ninjas script and line 39 from my script were different but you got an error of the same description on the same line.
 
Back
Top