• 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 Santa Claus

Fortera Global

Intermediate OT User
Joined
Nov 20, 2015
Messages
1,180
Solutions
2
Reaction score
117
Hello, npc Santa Claus tfs 1.2 please any have?

I got this script but dont is for tfs 1.2

Code:
random_items = {
{5,2112,1}, --  0.5% to get teddy bear
{20,6512,1}, -- 2% to get santa doll
{40,2114,1}, -- 4% to get piggy bank
{80,2111,5}, -- 8% to get 5 snowballs
{80,2688,8}, -- 8% to get 8 candy canes
{80,2110,1}, -- 8% to get doll
{400,2674,15}, -- 40% to get 15 red apples
{450,2675,10}, -- 45% to get 10 oranges
{1000,2687,8} -- 100% to get 8 cookies
}
PRESENT_STORAGE = 54163 -- storage ID



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
            local item = {}
            local reward = 0
            local count = ""
            for i = 1, #random_items do
                item = random_items[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! You were good like a little dwarf this year! I got ' .. count .. getItemNameById(reward) .. ' for you.', cid)
        else
            npcHandler:say('I gave you a present already.', cid)
        end
    else
        npcHandler:say('Come back when you start behaving good.', cid)
    end
    npcHandler:resetNpc()
    return true
end
 
npcHandler:setMessage(MESSAGE_GREET, "Merry Christmas |PLAYERNAME|. I'm Santa Claus. I got presents for good children.")

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

local node = keywordHandler:addKeyword({'pre'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Were you good this year?'})
    node:addChildKeywordNode(yesNode)
    node:addChildKeywordNode(noNode)
npcHandler:addModule(FocusModule:new())
 
Last edited by a moderator:
Code:
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 = 80, itemid = 2111, count = 5},   -- 8% to get 5 snowballs
    {chance = 80, itemid = 2688, count = 8},   -- 8% to get 8 candy canes
    {chance = 80, itemid = 2110, count = 1},   -- 8% to get doll
    {chance = 400, itemid = 2674, count = 15}, -- 40% to get 15 red apples
    {chance = 450, itemid = 2675, count = 10}, -- 45% to get 10 oranges
    {chance = 1000, itemid = 2687, count = 8}  -- 100% to get 8 cookies
}

local PRESENT_STORAGE = 54163 -- storage ID

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, 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
    if getPlayerStorageValue(cid, PRESENT_STORAGE) == 1 then
        npcHandler:say('I gave you a present already.', cid)
        return false
    end
    local item, reward = nil, {}
    for i = 1, #random_items do
        item = random_items[i]
        if math.random(0, 1000) <= item.chance then
            reward.itemid  = item.itemid
            reward.subType = item.count or 1
            break
        end
    end
    player:addItem(reward.itemid, reward.subType)
    player:setStorageValue(PRESENT_STORAGE, 1)
    npcHandler:say(string.format('HO HO HO! You were good like a little dwarf this year! I got %d %s for you.', count, ItemType(reward):getName()) cid)
    npcHandler:resetNpc()
    return true
end

npcHandler:setMessage(MESSAGE_GREET, "Merry Christmas |PLAYERNAME|. I'm Santa Claus. I got presents for good children.")

local node = keywordHandler:addKeyword({'pre'}, 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())
i dont fully understand npcs but see if this works
 
Code:
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 = 80, itemid = 2111, count = 5},   -- 8% to get 5 snowballs
    {chance = 80, itemid = 2688, count = 8},   -- 8% to get 8 candy canes
    {chance = 80, itemid = 2110, count = 1},   -- 8% to get doll
    {chance = 400, itemid = 2674, count = 15}, -- 40% to get 15 red apples
    {chance = 450, itemid = 2675, count = 10}, -- 45% to get 10 oranges
    {chance = 1000, itemid = 2687, count = 8}  -- 100% to get 8 cookies
}

local PRESENT_STORAGE = 54163 -- storage ID

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, 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
    if getPlayerStorageValue(cid, PRESENT_STORAGE) == 1 then
        npcHandler:say('I gave you a present already.', cid)
        return false
    end
    local item, reward = nil, {}
    for i = 1, #random_items do
        item = random_items[i]
        if math.random(0, 1000) <= item.chance then
            reward.itemid  = item.itemid
            reward.subType = item.count or 1
            break
        end
    end
    player:addItem(reward.itemid, reward.subType)
    player:setStorageValue(PRESENT_STORAGE, 1)
    npcHandler:say(string.format('HO HO HO! You were good like a little dwarf this year! I got %d %s for you.', count, ItemType(reward):getName()) cid)
    npcHandler:resetNpc()
    return true
end

npcHandler:setMessage(MESSAGE_GREET, "Merry Christmas |PLAYERNAME|. I'm Santa Claus. I got presents for good children.")

local node = keywordHandler:addKeyword({'pre'}, 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())
i dont fully understand npcs but see if this works
Thanks,
I have one error when say, present, yes:

LcxZ6i0.png
 
above:
Code:
local item, reward = nil, {}
add:
Code:
local player = Player(cid)

Thanks, he give me present but dont say nothing and appears this error on screen:

isE6d7D.png


line 49:
npcHandler:say(string.format('HO HO HO! You were good like a little dwarf this year! I got %d %s for you.', count, ItemType(reward):getName()) (cid))
 
Thanks, he give me present but dont say nothing and appears this error on screen:

isE6d7D.png


line 49:
npcHandler:say(string.format('HO HO HO! You were good like a little dwarf this year! I got %d %s for you.', count, ItemType(reward):getName()) (cid))
npcHandler:say(string.format('HO HO HO! You were good like a little dwarf this year! I got %d %s for you.', reward.subType, ItemType(reward.itemid):getName()) (cid))
 
Thanks, the same, he dont say nothing, he give me the item and got error on screen:

http://prntscr.com/datdxl
Code:
npcHandler:say(string.format('HO HO HO! You were good like a little dwarf this year! I got %d %s for you.', reward.subType, ItemType(reward.itemid):getName()), cid))
comma was missing between cid :|
 
Back
Top