<?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>
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())
Yeah, by Gesior ..Code:<?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>
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())
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Santa Claus" nameDescription="Santa Claus, the grandfather of Christmas" walkinterval="2000" floorchange="0" skull="green">
<health now="100" max="100"/>
<look type="153" head="0" body="94" legs="94" feet="95" addons="3"/>
<voices>
<voice text="Merry christmas!" interval2="50"/>
<voice text="Ho, ho, ho!" interval2="50"/>
<voice text="Jingle bells, jingle bells" interval2="50"/>
</voices>
<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, |NAME|."/>
</interact>
<interact keywords="present">
<keywords>gift</keywords>
<response>
<action name="script">
<![CDATA[
if(getPlayerVocation(cid) == 0 and getPlayerLevel(cid) < 10) then
selfSay("Sorry, you are yet too young to obtain a present.", cid)
elseif(getPlayerStorageValue(cid, 8002) <= 0) then
selfSay("You have been adorable this year, {right}?", cid)
_state.topic = 1
else
selfSay("What? How rude! Next please...", cid)
selfSay("What? How rude! Next please...")
_state.isidle = true
end
]]>
</action>
</response>
</interact>
<interact keywords="right" topic="1">
<response>
<action name="script">
<![CDATA[
local presents, present = {
{100, 2111, 50}, --10% chance to get 50 snowballs
{200, 2688, 25}, --20% chance to get 25 candy canes
{400, 2688, 25}, --20% chance to get 10 candy canes
{600, 2674, 15}, --60% chance to get 15 red apples
{800, 2675, 10}, --80% chance to get 10 oranges
{1000, 2687, 30} --100% chance to get 30 cookies
}, doCreateItemEx(11256, 1)
local random = math.random(1, 1000)
for i = 1, table.maxn(presents) do
local tmp = presents[i]
if(random <= tmp[1]) then
doAddContainerItem(present, tmp[2], tmp[3])
break
end
end
doAddContainerItem(present, 6574, 1)
doAddContainerItem(present, 6512, 1)
doAddContainerItem(present, 6571, 1)
doAddContainerItem(present, 6570, 1)
if(getCreatureStorage(cid, 8002) > 0) then
selfSay("Sorry, you have already received a present! Next please...", cid)
selfSay("Sorry, you have already received a present! Next please...")
doRemoveItem(present, 1)
_state.isidle = true
elseif(doPlayerAddItemEx(cid, present, false) == RETURNVALUE_NOERROR) then
selfSay("Then here you are, my young friend. Remember about your family, they're all you've got!", cid)
doCreatureSetStorage(cid, 8002, 1)
_state.topic = 0
else
selfSay("Uhm, sorry, I didn't hear you... Could you repeat, please?", cid)
end
]]>
</action>
</response>
</interact>
<interact keywords="|*|" topic="1">
<response>
<action name="script">
<![CDATA[
selfSay("I give presents only to adorable kids, sorry!", cid)
_state.topic = 0
]]>
</action>
</response>
</interact>
</interaction>
</npc>
Here it goes...
Code:<?xml version="1.0" encoding="UTF-8"?> <npc name="Santa Claus" nameDescription="Santa Claus, the grandfather of Christmas" walkinterval="2000" floorchange="0" skull="green"> <health now="100" max="100"/> <look type="153" head="0" body="94" legs="94" feet="95" addons="3"/> <voices> <voice text="Merry christmas!" interval2="50"/> <voice text="Ho, ho, ho!" interval2="50"/> <voice text="Jingle bells, jingle bells" interval2="50"/> </voices> <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, |NAME|."/> </interact> <interact keywords="present"> <keywords>gift</keywords> <response> <action name="script"> <![CDATA[ if(getPlayerVocation(cid) == 0 and getPlayerLevel(cid) < 10) then selfSay("Sorry, you are yet too young to obtain a present.", cid) elseif(getPlayerStorageValue(cid, 8002) <= 0) then selfSay("You have been adorable this year, {right}?", cid) _state.topic = 1 else selfSay("What? How rude! Next please...", cid) selfSay("What? How rude! Next please...") _state.isidle = true end ]]> </action> </response> </interact> <interact keywords="right" topic="1"> <response> <action name="script"> <![CDATA[ local presents, present = { {100, 2111, 50}, --10% chance to get 50 snowballs {200, 2688, 25}, --20% chance to get 25 candy canes {400, 2688, 25}, --20% chance to get 10 candy canes {600, 2674, 15}, --60% chance to get 15 red apples {800, 2675, 10}, --80% chance to get 10 oranges {1000, 2687, 30} --100% chance to get 30 cookies }, doCreateItemEx(11256, 1) local random = math.random(1, 1000) for i = 1, table.maxn(presents) do local tmp = presents[i] if(random <= tmp[1]) then doAddContainerItem(present, tmp[2], tmp[3]) break end end doAddContainerItem(present, 6574, 1) doAddContainerItem(present, 6512, 1) doAddContainerItem(present, 6571, 1) doAddContainerItem(present, 6570, 1) if(getCreatureStorage(cid, 8002) > 0) then selfSay("Sorry, you have already received a present! Next please...", cid) selfSay("Sorry, you have already received a present! Next please...") doRemoveItem(present, 1) _state.isidle = true elseif(doPlayerAddItemEx(cid, present, false) == RETURNVALUE_NOERROR) then selfSay("Then here you are, my young friend. Remember about your family, they're all you've got!", cid) doCreatureSetStorage(cid, 8002, 1) _state.topic = 0 else selfSay("Uhm, sorry, I didn't hear you... Could you repeat, please?", cid) end ]]> </action> </response> </interact> <interact keywords="|*|" topic="1"> <response> <action name="script"> <![CDATA[ selfSay("I give presents only to adorable kids, sorry!", cid) _state.topic = 0 ]]> </action> </response> </interact> </interaction> </npc>
My own version, 8.54+ :thumbup:
not a mod, it's just a npc scripted in xml.
yes rox pwnz all o/