• 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 dont work in TFS 1.0

stringdeveloper

New Member
Joined
Mar 25, 2014
Messages
25
Reaction score
2
Hello i have a server 10.53 and my tfs 1.0 dont read my Santa Claus script, somebody can help me please? Here is the code:

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[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 .. 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())
And here is the error:
Lua Script Error: [Npc interface]
data/npc/scripts/Santa Claus.lua:eek:nCreatureSay
data/npc/scripts/Santa Claus.lua:39: attempt to compare number with table
stack traceback:
[C]: ?
data/npc/scripts/Santa Claus.lua:39: in function 'callback'
data/npc/lib/npcsystem/keywordhandler.lua:26: in function 'processMessage'
data/npc/lib/npcsystem/keywordhandler.lua:135: in function 'processNodeMessage'
data/npc/lib/npcsystem/keywordhandler.lua:103: in function 'processMessage'
data/npc/lib/npcsystem/npchandler.lua:402: in function 'onCreatureSay'
data/npc/scripts/Santa Claus.lua:21: in function <data/npc/scripts/Santa Claus.lua:21>
 
Here is where your error occurs:
Code:
if (math.random(0,999) < item[1]) then

According to the code, item is a table, specifically a copy of the gifts table.
The gifts table contains another table in each index.

So, in the error line, you're trying to compare a number (math.random(0,999)) with a table inside another table (item).
That's why it says this in the console: "data/npc/scripts/Santa Claus.lua:39: attempt to compare number with table"

I'm assuming you want the first index of the tables inside item table to get the chance.
You are also looping through gifts from beginning to end. Remember, gifts is a table that contains a bunch of tables (two-dimensional array).
So, at each index of gifts, you want to get the item chance, which is the first index of that table.
Code:
if (math.random(0,999) < item[i][1]) then
 
Thanks for you help Evan, i change it but now i get a diferent error:
Lua Script Error: [Npc interface]
data/npc/scripts/Santa Claus.lua:eek:nCreatureSay
data/npc/scripts/Santa Claus.lua:42: attempt to compare number with table
stack traceback:
[C]: ?
data/npc/scripts/Santa Claus.lua:42: in function 'callback'
data/npc/lib/npcsystem/keywordhandler.lua:26: in function 'processMessage'
data/npc/lib/npcsystem/keywordhandler.lua:135: in function 'processNodeMessage'
data/npc/lib/npcsystem/keywordhandler.lua:103: in function 'processMessage'
data/npc/lib/npcsystem/npchandler.lua:402: in function 'onCreatureSay'
data/npc/scripts/Santa Claus.lua:21: in function <data/npc/scripts/Santa Claus.lua:21>
 
Code:
reward = item[i][2]
subType = item[i][3]
Thanks for help, but now i get this error:
Lua Script Error: [Npc interface]
data/npc/scripts/Santa Claus.lua:eek:nCreatureSay
data/npc/scripts/Santa Claus.lua:50: attempt to call global 'getItemNameById' (a nil value)
stack traceback:
[C]: in function 'getItemNameById'
data/npc/scripts/Santa Claus.lua:50: in function 'callback'
data/npc/lib/npcsystem/keywordhandler.lua:26: in function 'processMessage'
data/npc/lib/npcsystem/keywordhandler.lua:135: in function 'processNodeMessage'
data/npc/lib/npcsystem/keywordhandler.lua:103: in function 'processMessage'
data/npc/lib/npcsystem/npchandler.lua:402: in function 'onCreatureSay'
data/npc/scripts/Santa Claus.lua:21: in function <data/npc/scripts/Santa Claus.lua:21>
 
I changed to
Code:
npcHandler:say('HO-HO-HO! I have '.. count .. getItemName(reward) ..' for you.', cid)
and now work 100%, Thanks Limos and Evan for help, love u global moderators <3!
 
I get this error

data/npc/scripts/santa.lua:39: in function 'callback'
data/npc/lib/npcsystem/keywordhandler.lua:26: in function 'processMessag
 
PHP:
Lua Script Error: [Npc interface]
data/npc/scripts/santa.lua:onCreatureSay
data/npc/scripts/santa.lua:20: attempt to call global 'getPlayerStorageValue' (a
 nil value)
stack traceback:
        [C]: in function 'getPlayerStorageValue'
        data/npc/scripts/santa.lua:20: in function 'callback'
        data/npc/lib/npcsystem/keywordhandler.lua:31: in function 'processMessag
e'
        data/npc/lib/npcsystem/keywordhandler.lua:186: in function 'processNodeM
essage'
        data/npc/lib/npcsystem/keywordhandler.lua:154: in function 'processMessa
ge'
        data/npc/lib/npcsystem/npchandler.lua:419: in function 'onCreatureSay'
        data/npc/scripts/santa.lua:12: in function <data/npc/scripts/santa.lua:1
2>[php]

there it is
 
PHP:
Lua Script Error: [Npc interface]
data/npc/scripts/santa.lua:onCreatureSay
data/npc/scripts/santa.lua:20: attempt to call global 'getPlayerStorageValue' (a
nil value)
stack traceback:
        [C]: in function 'getPlayerStorageValue'
        data/npc/scripts/santa.lua:20: in function 'callback'
        data/npc/lib/npcsystem/keywordhandler.lua:31: in function 'processMessag
e'
        data/npc/lib/npcsystem/keywordhandler.lua:186: in function 'processNodeM
essage'
        data/npc/lib/npcsystem/keywordhandler.lua:154: in function 'processMessa
ge'
        data/npc/lib/npcsystem/npchandler.lua:419: in function 'onCreatureSay'
        data/npc/scripts/santa.lua:12: in function <data/npc/scripts/santa.lua:1
2>[php]

there it is

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())
 
Back
Top