Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- local talkState = {}
- -- config
- local stats = {'melee', 'distance', 'shield', 'ml', 'invisible', 'regeneration', 'manashield', 'haste'}
- local config = {
- max_incr = 2,
- skillsupgrade = {
- ['melee'] = {price = 5000, seconds = 600, amount = 10, subid = 62, renew = 24 * 60 * 60, storage = 77700, buymsg = {'Your Melee Skill has increased for ', ' minutes!'}, failmsg = 'You must be a knight to receive this increment.', canbuy = function(cid) return isKnight(cid) end},
- ['distance'] = {price = 5000, seconds = 600, amount = 10, subid = 63, renew = 24 * 60 * 60, storage = 77701, buymsg = {'Your Distance Skill has increased for ', ' minutes!'}, failmsg = 'You must be a paladin to receive this increment.', canbuy = function(cid) return isPaladin(cid) end},
- ['shield'] = {price = 5000, seconds = 600, amount = 10, subid = 64, renew = 24 * 60 * 60, storage = 77702, buymsg = {'Your Shielding Skill has increased for ', ' minutes!'}, failmsg = 'You must be a paladin or a knight to receive this increment.', canbuy = function(cid) return isKnight(cid) or isPaladin(cid) end},
- ['ml'] = {price = 5000, seconds = 600, amount = 10, subid = 65, renew = 24 * 60 * 60, storage = 77703, buymsg = {'Your Magic Level has increased for ', ' minutes!'}, failmsg = 'You must be a druid or a sorcerer to receive this increment.', canbuy = function(cid) return isDruid(cid) or isSorcerer(cid) end},
- ['invisible'] = {price = 5000, seconds = 600, subid = 66, renew = 24 * 60 * 60, storage = 77704, buymsg = {'You received Invisibility for ', ' minutes!'}, failmsg = 'You must be a druid or a sorcerer to receive this increment.', canbuy = function(cid) return isDruid(cid) or isSorcerer(cid) end},
- ['haste'] = {price = 5000, seconds = 600, formula = {1.0, -86, 1.0, -86}, renew = 24 * 60 * 60, storage = 77705, buymsg = {'Your speed has increased for ', ' minutes!'}, failmsg = 'Unable to add stat.', canbuy = function(cid) return true end},
- ['regeneration'] = {price = 5000, seconds = 600, gain = 20, ticks = 2000, renew = 24 * 60 * 60, storage = 77706, buymsg = {'Your regeneration has increased for ', ' minutes!'}, failmsg = 'Unable to add stat.', canbuy = function(cid) return true end},
- ['manashield'] = {price = 5000, seconds = 600, renew = 24 * 60 * 60, storage = 77707, buymsg = 'You received a Magic Shield for ', ' minutes!', failmsg = 'Knights cannot receive this increment.', canbuy = function(cid) return not isKnight(cid) end},
- },
- }
- -- end of config
- local su = config.skillsupgrade
- for i = 1, #stats do
- local bm = su[stats[i]].buymsg
- bm = {bm[1] .. math.floor(su[stats[i]].seconds/10), bm[2]}
- end
- local active_incr = {}
- local ml = createConditionObject(CONDITION_ATTRIBUTES)
- setConditionParam(ml, CONDITION_PARAM_SUBID, su['ml'].subid)
- setConditionParam(ml, CONDITION_PARAM_BUFF_SPELL, 1)
- setConditionParam(ml, CONDITION_PARAM_TICKS, su['ml'].seconds * 1000)
- setConditionParam(ml, CONDITION_PARAM_STAT_MAGICPOINTS, su['ml'].amount)
- local me = createConditionObject(CONDITION_ATTRIBUTES)
- setConditionParam(me, CONDITION_PARAM_SUBID, su['melee'].subid)
- setConditionParam(me, CONDITION_PARAM_BUFF_SPELL, 1)
- setConditionParam(me, CONDITION_PARAM_TICKS, su['melee'].seconds * 1000)
- setConditionParam(me, CONDITION_PARAM_SKILL_MELEE, su['melee'].amount)
- local sh = createConditionObject(CONDITION_ATTRIBUTES)
- setConditionParam(sh, CONDITION_PARAM_SUBID, su['shield'].subid)
- setConditionParam(sh, CONDITION_PARAM_BUFF_SPELL, 1)
- setConditionParam(sh, CONDITION_PARAM_TICKS, su['shield'].seconds * 1000)
- setConditionParam(sh, CONDITION_PARAM_SKILL_SHIELD, su['shield'].amount)
- local ds = createConditionObject(CONDITION_ATTRIBUTES)
- setConditionParam(ds, CONDITION_PARAM_SUBID, su['distance'].subid)
- setConditionParam(ds, CONDITION_PARAM_BUFF_SPELL, 1)
- setConditionParam(ds, CONDITION_PARAM_TICKS, su['distance'].seconds * 1000)
- setConditionParam(ds, CONDITION_PARAM_SKILL_DISTANCE, su['distance'].amount)
- local iv = createConditionObject(CONDITION_INVISIBLE)
- setConditionParam(iv, CONDITION_PARAM_TICKS, su['invisible'].seconds * 1000)
- local ms = createConditionObject(CONDITION_MANASHIELD)
- setConditionParam(ms, CONDITION_PARAM_TICKS, su['manashield'].seconds * 1000)
- local hp = createConditionObject(CONDITION_REGENERATION)
- setConditionParam(hp, CONDITION_PARAM_SUBID, su['regeneration'].subid)
- setConditionParam(hp, CONDITION_PARAM_BUFF_SPELL, 1)
- setConditionParam(hp, CONDITION_PARAM_TICKS, su['regeneration'].seconds * 1000)
- setConditionParam(hp, CONDITION_PARAM_HEALTHGAIN, su['regeneration'].gain)
- setConditionParam(hp, CONDITION_PARAM_HEALTHTICKS, su['regeneration'].ticks)
- local hs = createConditionObject(CONDITION_HASTE)
- setConditionParam(hs, CONDITION_PARAM_TICKS, su['haste'].seconds * 1000)
- setConditionFormula(hs, su['haste'].formula[1], su['haste'].formula[2], su['haste'].formula[3], su['haste'].formula[4])
- local stat_t = {me, ds, sh, ml, iv, hp, ms, hs}
- for i = 1, #stats do
- su[stats[i]].condition = stat_t[i]
- end
- function creatureSayCallback(cid, type, msg)
- cid = Player(cid):getId() or cid -- compat for all tfs
- if(not npcHandler:isFocused(cid)) then return false end
- if not talkState[cid] then talkState[cid] = 0 end
- if talkState[cid] ~= 0 then
- if msgcontains(msg, "yes") then
- if stats[talkState[cid]] then
- if su[stats[talkState[cid]]] then
- if su[stats[talkState[cid]]].canbuy(cid) then
- if getPlayerMoney(cid) >= su[stats[talkState[cid]]].price then
- if not active_incr[cid] then active_incr[cid] = {} end
- if active_incr[cid][stats[talkState[cid]]] then
- if active_incr[cid][stats[talkState[cid]]] < os.time() then
- local pstr = getPlayerStorageValue(cid, su[stats[talkState[cid]]].storage)
- if pstr < os.time() then
- local a_incr = 0
- for i = 1, #stats do
- if active_incr[cid][stats[i]] then
- if active_incr[cid][stats[i]] > os.time() then
- a_incr = a_incr + 1
- end
- end
- end
- if a_incr < max then
- if doPlayerRemoveMoney(cid, su[stats[talkState[cid]]].price) then
- doAddCondition(cid, su[stats[talkState[cid]]].condition)
- setPlayerStorageValue(cid, su[stats[talkState[cid]]].storage, os.time() + su[stats[talkState[cid]]].renew)
- npcHandler:say(su[stats[talkState[cid]]].buymsg[1] .. su[stats[talkState[cid]]].buymsg[2], cid)
- talkState[cid] = 0
- return true
- end
- else
- npcHandler:say("You may use only " .. (config.max_incr == 1 and "one" or config.max_incr) .. " increments at once.", cid)
- end
- else
- npcHandler:say('You have to wait ' .. math.ceil(((pstr - os.time()) / 60) / 60) .. ' hours before you can get it again.', cid)
- end
- else
- npcHandler:say('You already use this one.', cid)
- end
- end
- else
- npcHandler:say('You don\'t have enough money.', cid)
- end
- else
- npcHandler:say(su[stats[talkState[cid]]].failmsg, cid)
- end
- end
- end
- else
- npcHandler:say("Come back when you change your mind.", cid)
- end
- talkState[cid] = 0
- return true
- end
- if msgcontains(msg, "help") or msgcontains(msg, "skill") or msgcontains(msg, "stat") or msgcontains(msg, "buff") or msgcontains(msg, "increment") then
- local skils = ""
- local nst = {}
- for i = 1, #stats do
- if su[stats[i]].canbuy(cid) then
- table.insert(nst, stats[i])
- end
- end
- if #nst == 0 then
- npcHandler:say("I don't have anything for you.", cid)
- return true
- end
- if #nst > 1 then
- local last = nst[#nst]
- table.remove(nst, #nst)
- skills = table.concat(nst, "}, {")
- skills = "{" .. skills .. "}" .. " and " .. "{" .. last .. "}"
- else
- skills = "{" .. nst[1] .. "}"
- end
- npcHandler:say("I can increase your " .. skills .. (#stats > 1 and (", you may use " .. (config.max_incr == 1 and "one" or config.max_incr) .. " of them at once.") or "."), cid)
- return true
- end
- for i = 1, #stats do
- if msgcontains(msg, stats[i]) and su[stats[i]] then
- if su[stats[i]].canbuy(cid) then
- npcHandler:say("Do you want to increase your " .. stats[i] .. " for " .. math.floor(su[stats[i]].seconds/10) .. " minutes for " .. su[stats[i]].price .. " gold?", cid)
- talkState[cid] = i
- return true
- else
- npcHandler:say(su[stats[i]].failmsg, cid)
- return true
- end
- end
- end
- end
- npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
- npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement