I want santa claus to only give presents to level 50 or higher.
(This is because the presents are expensive items so players don't abuse it by making level 8 characters.)
Current script:
(This is because the presents are expensive items so players don't abuse it by making level 8 characters.)
Current script:
Code:
random_items = {
{100,2498,1}, -- 10 % chance to get royal helmet
{100,2645,1}, -- 10 % chance to get steel boots
{100,2195,1}, -- 10 % chance to get boots of haste
{100,2520,1}, -- 10 % chance to get demon shield
{100,2656,1}, -- 10 % chance to get blue robe
{100,2475,1}, -- 10 % chance to get warrior helmet
{100,2476,1}, -- 10 % chance to get knight armor
{100,2477,1}, -- 10 % chance to get knight legs
{1000,2519,1} -- 10 % chance to get crown armor
}
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())