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 vocationCount = 4
- local config = {
- ["first"] = { lvl = 20, cost = 20000, id = 1 },
- ["second"] = { lvl = 20, cost = 100000, id = 2 }
- }
- function creatureSayCallback(cid, type, msg)
- if not npcHandler:isFocused(cid) then
- return false
- end
- local player = Player(cid)
- local pname = msg:lower()
- local getPromotion = config[pname]
- if not getPromotion then
- return selfSay("The promotion you ask for does not exist.", cid)
- end
- local vocid = player:getVocation():getId()
- local count = math.floor(vocid / vocationCount)
- local canPromotion = (count - getPromotion.id)
- if canPromotion < -1 then
- return selfSay("You still can not acquire this promotion.", cid)
- elseif canPromotion == 1 then
- return selfSay("You can not degrade your promotion.", cid)
- elseif canPromotion == 0 then
- return selfSay(string.format("You already have the %s promotion.", pname), cid)
- end
- if player:getLevel() < gwetPromotion.lvl then
- return selfSay(string.format("You need level %u+ for the %s promotion.", getPromotion.lvl, pname), cid)
- end
- if not player:removeMoney(getPromotion.cost) then
- return selfSay("You do not have enough money.", cid)
- end
- local newVocation = Vocation(vocid + vocationCount)
- player:setVocation(newVocation)
- selfSay(string.format("You have been successfully promoted to %s.", newVocation:getName()), cid)
- player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
- return true
- end
- npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
- npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement