local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local presents = {
[{1, 10}] = {2160, 10}, -- 10% 10 crystal coins
[{11, 25}] = {2152, 100}, -- 15% 100 platinum coins
[{26, 40}] = {2111, 10}, -- 15% 10 snowballs
[{41, 55}] = {2687, 10}, -- 15% 10 cookies
[{56, 70}] = 2110, -- 15% doll
[{71, 85}] = 2114, -- 15% piggy bank
[{86, 100}] = 1294, -- 15% small stone
[{101,105}] = 6507, -- 5% red christmas bundle
[{106,110}] = 6508, -- 5% blue christmas bundle
[{111,115}] = 6509, -- 5% green christmas bundle
[{116,116}] = 2156, -- 1% red gem
[{117,117}] = 10521, -- 1% moon backpack
}
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 creatureSayCallback(cid, _type, msg)
if (msgcontains(msg, 'hello') or msgcontains(msg, 'hi')) and not npcHandler:isFocused(cid) then
npcHandler:say('Merry Christmas, little '..getCreatureName(cid)..'!', cid)
npcHandler:addFocus(cid)
elseif not npcHandler:isFocused(cid) then
return false
elseif msgcontains(msg, 'present') then
if getPlayerStorageValue(cid, 65054) == -1 then
local rand = math.random(117)
for k, v in pairs(presents) do
if rand >= k[1] and rand <= k[2] then
doPlayerAddItem(cid, type(v)=='table' and v[1] or v, type(v)=='table' and v[2] or 1)
npcHandler:say('Here is your present! Enjoy!', cid)
setPlayerStorageValue(cid, 65054, 1)
break
end
end
else
npcHandler:say('You already got your present! Don\'t be greedy!', cid)
end
npcHandler:releaseFocus(cid)
elseif msgcontains(msg, 'bye') or msgcontains(msg, 'farewell') then
npcHandler:say('Farewell, '..getCreatureName(cid)..'!', cid)
npcHandler:releaseFocus(cid)
elseif msgcontains(msg, 'job') then
npcHandler:say('Ho ho ho! You don\'t know Santa Claus? Never mind. You may ask me for a {present}.', cid)
elseif msgcontains(msg, 'name') then
npcHandler:say('Sorry, I don\'t have time to chat. Please ask for your present.', cid)
end
return true
end
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Good bye, little |PLAYERNAME|!')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)