Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4.  
  5. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  6. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  7. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  8. function onThink() npcHandler:onThink() end
  9.  
  10. local vocationCount = 4
  11. local config = {
  12. ["first"] = { lvl = 20, cost = 20000, id = 1 },
  13. ["second"] = { lvl = 20, cost = 100000, id = 2 }
  14. }
  15.  
  16. function creatureSayCallback(cid, type, msg)
  17. if not npcHandler:isFocused(cid) then
  18. return false
  19. end
  20. local player = Player(cid)
  21. local pname = msg:lower()
  22. local getPromotion = config[pname]
  23. if not getPromotion then
  24. return selfSay("The promotion you ask for does not exist.", cid)
  25. end
  26. local vocid = player:getVocation():getId()
  27. local count = math.floor(vocid / vocationCount)
  28. local canPromotion = (count - getPromotion.id)
  29. if canPromotion < -1 then
  30. return selfSay("You still can not acquire this promotion.", cid)
  31. elseif canPromotion == 1 then
  32. return selfSay("You can not degrade your promotion.", cid)
  33. elseif canPromotion == 0 then
  34. return selfSay(string.format("You already have the %s promotion.", pname), cid)
  35. end
  36. if player:getLevel() < gwetPromotion.lvl then
  37. return selfSay(string.format("You need level %u+ for the %s promotion.", getPromotion.lvl, pname), cid)
  38. end
  39. if not player:removeMoney(getPromotion.cost) then
  40. return selfSay("You do not have enough money.", cid)
  41. end
  42. local newVocation = Vocation(vocid + vocationCount)
  43. player:setVocation(newVocation)
  44. selfSay(string.format("You have been successfully promoted to %s.", newVocation:getName()), cid)
  45. player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
  46. return true
  47. end
  48.  
  49. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  50. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement