NPC Santa Claus

Gesior.pl

Mega Noob&LOL 2012
Joined
Sep 18, 2007
Messages
2,031
Best answers
19
Reaction score
1,087
Location
PLand
Santa Claus NPC. Give items like on RL tibia. Player say hi, present (or prezent or anything with 'pre'), yes
txt said:
21:33 GOD Gesior [150]: hi
21:33 Santa Claus: Merry Christmas GOD Gesior. I'm Santa Claus. I got presents for good children.
21:33 GOD Gesior [150]: prezent
21:33 Santa Claus: Were you good this year?
21:33 GOD Gesior [150]: yes
21:33 Santa Claus: HO HO HO! You were good like a little dwarf this year! I got 15 red apple for you.
21:33 Santa Claus: Bye!
XML code:
PHP:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Santa Claus" script="data/npc/scripts/santa.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="251" head="94" body="94" legs="113" feet="114" addons="0"/>
	<parameters />
</npc>
LUA code:
PHP:
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())
 

Doonrak

Banned User
Joined
Mar 2, 2008
Messages
512
Best answers
0
Reaction score
0
Could you add a minimum level + premium requirement? Thanks in advance.
 

jo3bingham

Veteran OT User
Joined
Mar 3, 2008
Messages
1,003
Best answers
8
Reaction score
454
Could you add a minimum level + premium requirement? Thanks in advance.
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
[B]minLevelReq = 20[/B]


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
[B]    if (getPlayerLevel(cid) >= minLevelReq and isPremium(cid) == TRUE) then[/B]
        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
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())
There you go.

Jo3
 

Inteligentny

Im not.
Joined
Aug 2, 2008
Messages
485
Best answers
0
Reaction score
0
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
[B]minLevelReq = 20[/B]


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
[B]    if (getPlayerLevel(cid) >= minLevelReq and isPremium(cid) == TRUE) then[/B]
        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
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())
There you go.

Jo3
sorry but its not working
 

jo3bingham

Veteran OT User
Joined
Mar 3, 2008
Messages
1,003
Best answers
8
Reaction score
454
sorry but its not working
Try putting
Code:
if (getPlayerLevel(cid) >= minLevelReq and isPremium(cid) == TRUE) then
as two seperate if statements.
Code:
if (getPlayerLevel(cid) >= minLevelReq) then
    if (isPremium(cid) == TRUE) then
If it still doesn't work check your LUA_FUNCTIONS file in the doc folder to make sure you have those two functions, if not find the functions that do the same thing.

Jo3
 

elf

Sing, sing blue silver
Joined
Dec 11, 2007
Messages
3,665
Best answers
1
Reaction score
116
Location
Cracow, Poland
Will presents be by Gesior?
Code:
<?xml version="1.0"?>
<npc name="Santa Claus" walkinterval="2000" floorchange="0">
	<health now="1000" max="1000"/>
	<look type="160" head="0" body="94" legs="94" feet="95" addons="3"/>

	<interaction range="3" idletime="0" defaultpublic="0">
		<interact event="onPlayerLeave" focus="0">
			<response text="Merry christmas!"/>
		</interact>

		<interact keywords="hi" focus="1">
			<keywords>hello</keywords>
			<response text="Ho, ho, ho. Hello there, |NAME|!"/>
		</interact>

		<interact keywords="bye" focus="0">
			<keywords>farewell</keywords>
			<response text="Merry christmas!"/>
		</interact>

		<interact keywords="present">
			<keywords>gift</keywords>
			<response>
				<action name="script">
					<![CDATA[
						if(getPlayerStorageValue(cid, 7021) <= 0) then
							selfSay("Have you been naughty this year?", cid)
							_state.topic = 1
						else
							selfSay("Sorry, you have already received a present! Next please...", cid)
							_state.isidle = true
						end
					]]>
				</action>
			</response>
		</interact>

		<interact keywords="yes" topic="1">
			<response>
				<action name="script">
					<![CDATA[
						local presents = {
							{5, 2112, 1}, --0.5% chance to get teddy bear
							{20, 6512, 1}, --2% chance to get santa doll
							{40, 2114, 1}, --4% chance to get piggy bank
							{80, 2111, 5}, --8% chance to get 5 snowballs
							{80, 2688, 8}, --8% chance to get 8 candy canes
							{80, 2110, 1}, --8% chance to get doll
							{400, 2674, 15}, --40% chance to get 15 red apples
							{450, 2675, 10}, --45% chance to get 10 oranges
							{1000, 2687, 8} --100% chance to get 8 cookies
						}

						local random = math.random(0, 999)
						for i = 1, table.maxn(presents) do
							local tmp = presents[i]
							if(random <= tmp[1]) then
								selfSay("Then here you are, my young friend.", cid)
								if(doPlayerAddItem(cid, tmp[2], tmp[3], FALSE) == RETURNVALUE_NOERROR) then
									setPlayerStorageValue(cid, 7021, 1)
								end

								selfSay("Then here you are, my young friend.", cid)
								_state.topic = 0
								break
							end
						end
					]]>
				</action>
			</response>
		</interact>

		<interact keywords="no" topic="1">
			<response>
				<action name="script">
					<![CDATA[
						selfSay("I give presents only to naughty kids, sorry!", cid)
						_state.topic = 0
					]]>
				</action>
			</response>
		</interact>
	</interaction>
</npc>
pr0tek _/
 
Last edited:

hiperkarma

High-level newbie
Joined
May 4, 2008
Messages
3,411
Best answers
0
Reaction score
156
Location
Mars
lol -.-
he never asks if you were good or bad, he eats your cookies, wanks on them and leave a facking note as billy you don't get anything because you stole your grandmas underwear
 
OP
Gesior.pl

Gesior.pl

Mega Noob&LOL 2012
Joined
Sep 18, 2007
Messages
2,031
Best answers
19
Reaction score
1,087
Location
PLand
Will presents be by Gesior?
Code:
						local presents = {
							{5, 2112, 1}, --0.5% chance to get teddy bear
							{20, 6512, 1}, --2% chance to get santa doll
							{40, 2114, 1}, --4% chance to get piggy bank
							{80, 2111, 5}, --8% chance to get 5 snowballs
							{80, 2688, 8}, --8% chance to get 8 candy canes
							{80, 2110, 1}, --8% chance to get doll
							{400, 2674, 15}, --40% chance to get 15 red apples
							{450, 2675, 10}, --45% chance to get 10 oranges
							{1000, 2687, 8} --100% chance to get 8 cookies
						}

						local random = math.random(0, 999)
						for i = 1, table.maxn(presents) do
							local tmp = presents[i]
							if(random <= tmp[1]) then
								selfSay("Then here you are, my young friend.", cid)
								if(doPlayerAddItem(cid, tmp[2], tmp[3], FALSE) == RETURNVALUE_NOERROR) then
									setPlayerStorageValue(cid, 7021, 1)
								end

								selfSay("Then here you are, my young friend.", cid)
								_state.topic = 0
								break
							end
						end
pr0tek _/
If random = 41 - 80 I always get 5 snow balls? How can I get doll or candy canes?
 

bolero

MikeHere
Joined
Apr 13, 2009
Messages
1,146
Best answers
0
Reaction score
12
Location
Venezuela
[21/12/2009 17:31:32] luaDoCreateNpc(). Npc name(santa claus) not found
[21/12/2009 17:31:36] Raker has logged in.
[21/12/2009 17:31:41] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/santa.lua
[21/12/2009 17:31:41] data/npc/scripts/santa.lua:1: unexpected symbol near '{'
 
Top