• 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!

NPC [TFS 1.X] Santa Claus - Christmas Is Coming

S

Shadow_

Guest
Hey guys,
I got santa NPC in 1.X couldn't find it here before, so I decided to share it with the community for this Christmas celebrations to be in your server ^^.

Santa.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Santa Claus" script="santa.lua" walkinterval="0" speed="100" walkradius="0" floorchange="0">
    <health max="100" now="100"/>
    <look type="634" head="0" body="94" legs="94" feet="0" addons="3" mount="644"/>
    <parameters>
        <parameter key="message_greet" value="Merry Christmas |PLAYERNAME|. I'm Santa Claus. I got {present}s for good children."/>
    </parameters>
</npc>
santa.lua
Lua:
local random_items = {
{chance = 5, itemid = 2112}, -- 0.5% to get teddy bear
{chance = 20, itemid = 6512}, -- 2% to get santa doll
{chance = 40, itemid = 2114}, -- 4% to get piggy bank
{chance = 40, itemid = 15515, count = 50}, 
{chance = 80, itemid = 2111, count = 5}, 
{chance = 80, itemid = 2688, count = 8}, 
{chance = 80, itemid = 2110, count = 1}, 
{chance = 400, itemid = 2688, count = 15}, 
{chance = 100, itemid = 6527, count = 1}, 
{chance = 100, itemid = 24115, count = 1}, 
{chance = 100, itemid = 21401, count = 1},
{chance = 100, itemid = 11259, count = 1},
{chance = 300, itemid = 15515, count = 20},
{chance = 200, itemid = 26439, count = 4},
{chance = 200, itemid = 26443, count = 2},
{chance = 200, itemid = 26442, count = 4},
{chance = 200, itemid = 26441, count = 4},
{chance = 200, itemid = 26440, count = 4},
{chance = 50, itemid = 9653, count = 1},
{chance = 150, itemid = 18423, count = 5}, 
{chance = 150, itemid = 18422, count = 5}, 
{chance = 150, itemid = 26144, count = 5}, 
{chance = 100, itemid = 26147, count = 1}, 
{chance = 100, itemid = 26148, count = 1}, 
{chance = 100, itemid = 26149, count = 1}, 
{chance = 250, itemid = 18413, count = 20},
{chance = 250, itemid = 18414, count = 20},
{chance = 250, itemid = 18415, count = 20},
}
local PRESENT_TIMER = 54164

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 voices = {
{ text = 'HO HO HO! MERRY CHRISTMAS', yell = true },
{ text = 'Hi there young ones, have you been good this year?' }
}

local PRESENT_STORAGE = 88888

function santaNPC(cid, message, keywords, present, node)
    if not npcHandler:isFocused(cid) then
        return false
    end
    if not present then
        npcHandler:say('Come back when you start behaving good.', cid)
        return true
    end
    local player = Player(cid)
    local item, reward = nil, {}
    for i = 1, #random_items do
        item = random_items
        if math.random(1000) < item[i].chance then
            reward.itemid  = item[i].itemid
            reward.subType = item[i].count or 1
            break
        end
    end
    if player:getStorageValue(PRESENT_STORAGE) <= os.time() then
        player:addItem(reward.itemid, reward.subType)
        npcHandler:say("HO HO HO! You were good like a little dwarf this year!", cid)
        npcHandler:resetNpc()
        player:setStorageValue(PRESENT_STORAGE, os.time() + (24 * 60 * 60)) -- sets the next time for 1 day later than current time
        return true
     else
     npcHandler:say('You\'ve already received a present, come back tomorrow', cid)
    end
end

npcHandler:setMessage(MESSAGE_GREET, "Merry Christmas |PLAYERNAME|. I'm Santa Claus. I got {present}s for good children.")
local node = keywordHandler:addKeyword({'present'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Were you good this year?'})
node:addChildKeywordNode(KeywordNode:new({'yes'}, santaNPC, true))
node:addChildKeywordNode(KeywordNode:new({'no'}, santaNPC, false))
npcHandler:addModule(FocusModule:new())
This NPC should give each player 1 reward from the array in the top of the lua file.
Cheers
 
Last edited by a moderator:
It could be a little bit more advanced in my opinion like lets say what if all "chance" are the same 50%? It will glitch up isnt it? Could have level requirement. But thats just my opinion, but thanks for release!
 
It could be a little bit more advanced in my opinion like lets say what if all "chance" are the same 50%? It will glitch up isnt it? Could have level requirement. But thats just my opinion, but thanks for release!
Thanks for the feedback, if it didn't glitch when 10 things same chance entered the loop we got only 1 output, so if 1k entered the loop the output stills one.
Lua:
    for i = 1, #random_items do
        item = random_items
        if math.random(1000) < item[i].chance then
            reward.itemid  = item[i].itemid
            reward.subType = item[i].count or 1
            break
        end
break is used to leave the for loop or any loop the code is inside when the if condition is true, so it still 1 item.
 
Thanks for the feedback, if it didn't glitch when 10 things same chance entered the loop we got only 1 output, so if 1k entered the loop the output stills one.
Lua:
    for i = 1, #random_items do
        item = random_items
        if math.random(1000) < item[i].chance then
            reward.itemid  = item[i].itemid
            reward.subType = item[i].count or 1
            break
        end
break is used to leave the for loop or any loop the code is inside when the if condition is true, so it still 1 item.
Weird because i added like 15items with same chance and it always gives one and same item. And if i understand right (24 * 60 * 60) after 1 day you can take this reward again?
 
Last edited:
Weird because i added like 15items with same chance and it always gives one and same item. And if i understand right (24 * 60 * 60) after 1 day you can take this reward again?
yes it is daily it can be 1 time only by changing those to 2 and same for the if statement
 
working for 1.3 tfs?
yes
Post automatically merged:

New Version with level requirement [If any moderator can update the main post it would be appreciated, if so please change this comment to New Version with level requirement main post updated]
Lua:
local random_items = {
{chance = 5, itemid = 2112, level = 10}, -- 0.5% to get teddy bear
{chance = 20, itemid = 6512, level = 10}, -- 2% to get santa doll
{chance = 40, itemid = 2114, level = 10}, -- 4% to get piggy bank
{chance = 40, itemid = 15515, count = 50, level = 10},
{chance = 80, itemid = 2111, count = 5, level = 10},
{chance = 80, itemid = 2688, count = 8, level = 10},
{chance = 80, itemid = 2110, count = 1, level = 10},
{chance = 400, itemid = 2688, count = 15, level = 10},
{chance = 100, itemid = 6527, count = 1, level = 10},
{chance = 100, itemid = 24115, count = 1, level = 10},
{chance = 100, itemid = 21401, count = 1, level = 10},
{chance = 100, itemid = 11259, count = 1, level = 10},
{chance = 300, itemid = 15515, count = 20, level = 10},
{chance = 200, itemid = 26439, count = 4, level = 10},
{chance = 200, itemid = 26443, count = 2, level = 10},
{chance = 200, itemid = 26442, count = 4, level = 10},
{chance = 200, itemid = 26441, count = 4, level = 10},
{chance = 200, itemid = 26440, count = 4, level = 10},
{chance = 50, itemid = 9653, count = 1, level = 10},
{chance = 150, itemid = 18423, count = 5, level = 10},
{chance = 150, itemid = 18422, count = 5, level = 10},
{chance = 150, itemid = 26144, count = 5, level = 10},
{chance = 100, itemid = 26147, count = 1, level = 10},
{chance = 100, itemid = 26148, count = 1, level = 10},
{chance = 100, itemid = 26149, count = 1, level = 10},
{chance = 250, itemid = 18413, count = 20, level = 10},
{chance = 250, itemid = 18414, count = 20, level = 10},
{chance = 250, itemid = 18415, count = 20, level = 10},
}

local lib = {}
local PRESENT_TIMER = 54164

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 voices = {
{ text = 'HO HO HO! MERRY CHRISTMAS', yell = true },
{ text = 'Hi there young ones, have you been good this year?' }
}

local PRESENT_STORAGE = 88888

function santaNPC(cid, message, keywords, present, node)
    if not npcHandler:isFocused(cid) then
        return false
    end
    if not present then
        npcHandler:say('Come back when you start behaving good.', cid)
        return true
    end
    local player = Player(cid)
    local item, reward = nil, {}
    for i = 1, #random_items do
        item = random_items
        if player:getLevel() >= item[i].level then
            table.insert(lib, i)
        end
        for j = 1, #lib do
            if math.random(1000) < item[lib[j]].chance then
                reward.itemid  = item[lib[j]].itemid
                reward.subType = item[lib[j]].count or 1
                break
            else
                npcHandler:say("There is no rewards for you!", cid)
                npcHandler:resetNpc()
            end
        end
        end
        if player:getStorageValue(PRESENT_STORAGE) <= os.time() then
            player:addItem(reward.itemid, reward.subType)
            npcHandler:say("HO HO HO! You were good like a little dwarf this year!", cid)
            npcHandler:resetNpc()
            player:setStorageValue(PRESENT_STORAGE, os.time() + (24 * 60 * 60)) -- sets the next time for 1 day later than current time
            return true
        else
            npcHandler:say('You\'ve already received a present, come back tomorrow', cid)
        end
    end

npcHandler:setMessage(MESSAGE_GREET, "Merry Christmas |PLAYERNAME|. I'm Santa Claus. I got {present}s for good children.")
local node = keywordHandler:addKeyword({'present'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Were you good this year?'})
node:addChildKeywordNode(KeywordNode:new({'yes'}, santaNPC, true))
node:addChildKeywordNode(KeywordNode:new({'no'}, santaNPC, false))
npcHandler:addModule(FocusModule:new())
 
Last edited by a moderator:
Back
Top