Advertisement
Guest User

skillpoints.lua

a guest
Apr 5th, 2015
1,040
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.04 KB | None | 0 0
  1. local function addSkills(player, skillId)
  2.     player:addSkillTries(skillId, math.ceil(player:getVocation():getRequiredSkillTries(skill, player:getSkillLevel(skill) + 1) / configManager.getNumber(configKeys.RATE_SKILL)))
  3.  return false
  4. end
  5.  
  6.  
  7. local skillids = {
  8.     ["shield"] = SKILL_SHIELD,
  9.     ["sword"] = SKILL_SWORD,
  10.     ["axe"] = SKILL_AXE,
  11.     ["club"] = SKILL_CLUB,
  12.     ["fist"] = SKILL_FIST,
  13.     ["dist"] = SKILL_DISTANCE
  14.     }
  15. local attributes = {
  16.     ["health"] =    {reqPoints = 1, increaseBy = 2, name = "Hit Points"},
  17.     ["mana"] =      {reqPoints = 1, increaseBy = 2, name = "Mana Points"},
  18.     ["magic"] =     {reqPoints = 15, increaseBy = 1, name = "Magic Level"},
  19.     ["shielding"] = {reqPoints = 15, increaseBy = 1, name = "Shielding Skill"},
  20.     ["sword"] =     {reqPoints = 15, increaseBy = 1, name = "Sword Skill"},
  21.     ["axe"] =       {reqPoints = 15, increaseBy = 1, name = "Axe Skill"},
  22.     ["club"] =      {reqPoints = 15, increaseBy = 1, name = "Club Skill"},
  23.     ["fist"] =      {reqPoints = 15, increaseBy = 1, name = "Fist Skill"},
  24.     ["distance"] =  {reqPoints = 15, increaseBy = 1, name = "Distance Skill"},
  25.     }
  26.  
  27. function onModalWindow(player, modalWindowId, buttonId, choiceId)
  28. local SKILL_POINTS = 45200 --- Change here the storage value used to save the skill points
  29. local points = player:getStorageValue(SKILL_POINTS)
  30.  
  31. local function sendCancel()
  32.     player:sendTextMessage(MESSAGE_INFO_DESCR, "You do not have the required amount of Skill Points!")
  33. end
  34.  
  35. local function doAddHealth(param, attributes)
  36.     player:setMaxHealth(player:getMaxHealth() + attributes["health"].increaseBy*param)
  37.     player:addHealth(attributes["health"].increaseBy*param)
  38.     player:setStorageValue(SKILL_POINTS, points - attributes["health"].reqPoints*param)
  39.     player:sendTextMessage(MESSAGE_INFO_DESCR, "You have gained " ..attributes["health"].increaseBy.. " " ..attributes["health"].name.. "!")
  40. return true
  41. end
  42.  
  43. local function doAddMana(param, attributes)
  44.     player:setMaxMana(player:getMaxMana() + attributes["mana"].increaseBy*param)
  45.     player:addMana(attributes["mana"].increaseBy*param)
  46.     player:setStorageValue(SKILL_POINTS, points - attributes["mana"].reqPoints*param)
  47.     player:sendTextMessage(MESSAGE_INFO_DESCR, "You have gained " ..attributes["mana"].increaseBy.. " " ..attributes["mana"].name.. "!")
  48. return true
  49. end
  50.  
  51. if (not modalWindowId == 1) or (buttonId == 4) then
  52.     return false
  53. end
  54.  
  55.     if choiceId == 1 then
  56.         if buttonId == 1 then
  57.             if points >= attributes["health"].reqPoints then
  58.                 doAddHealth(1, attributes)
  59.             else
  60.                 sendCancel()
  61.             end
  62.         end
  63.         if buttonId == 2 then
  64.             if points >= attributes["health"].reqPoints*2 then
  65.                 doAddHealth(2, attributes)
  66.             else
  67.                 sendCancel()
  68.             end
  69.         end
  70.         if buttonId == 3 then
  71.             if points >= attributes["health"].reqPoints*5 then
  72.                 doAddHealth(5, attributes)
  73.             else
  74.                 sendCancel()
  75.             end
  76.         end
  77.     end
  78.     if choiceId == 2 then
  79.         if buttonId == 1 then
  80.             if points >= attributes["mana"].reqPoints then
  81.                 doAddMana(1, attributes)
  82.             else
  83.                 sendCancel()
  84.             end
  85.         end
  86.         if buttonId == 2 then
  87.             if points >= attributes["mana"].reqPoints*2 then
  88.                 doAddMana(2, attributes)
  89.             else
  90.                 sendCancel()
  91.             end
  92.         end
  93.         if buttonId == 3 then
  94.             if points >= attributes["mana"].reqPoints*5 then
  95.                 doAddMana(5, attributes)
  96.             else
  97.                 sendCancel()
  98.             end
  99.         end
  100.     end
  101.     if choiceId == 3 then
  102.         if buttonId == 1 then
  103.             if points >= attributes["magic"].reqPoints then
  104.                 player:addManaSpent(math.ceil(player:getVocation():getRequiredManaSpent(player:getBaseMagicLevel() + 1) / configManager.getNumber(configKeys.RATE_MAGIC)))
  105.                 player:setStorageValue(SKILL_POINTS, points - attributes["magic"].reqPoints)
  106.             else
  107.                 sendCancel()
  108.             end
  109.         end
  110.         if buttonId == 2 then
  111.             if points >= attributes["magic"].reqPoints*2 then
  112.                 for i = 1,2 do
  113.                     player:addManaSpent(math.ceil(player:getVocation():getRequiredManaSpent(player:getBaseMagicLevel() + 1) / configManager.getNumber(configKeys.RATE_MAGIC)))
  114.                     player:setStorageValue(SKILL_POINTS, points - attributes["magic"].reqPoints)
  115.                 end
  116.             else
  117.                 sendCancel()
  118.             end
  119.         end
  120.         if buttonId == 3 then
  121.            if points >= attributes["magic"].reqPoints*5 then
  122.                 for i = 1,5 do
  123.                     player:addManaSpent(math.ceil(player:getVocation():getRequiredManaSpent(player:getBaseMagicLevel() + 1) / configManager.getNumber(configKeys.RATE_MAGIC)))
  124.                     player:setStorageValue(SKILL_POINTS, points - attributes["magic"].reqPoints)
  125.                 end
  126.             else
  127.                 sendCancel()
  128.             end
  129.         end
  130.     end
  131.     if choiceId == 4 then
  132.         if buttonId == 1 then
  133.             if points >= attributes["sword"].reqPoints then
  134.                 addSkills(player, skillids["sword"])
  135.             end
  136.         end
  137.         if buttonId == 2 then
  138.             if points >= attributes["sword"].reqPoints*2 then
  139.                 for i = 1,2 do
  140.                     addSkills(player, skillids["sword"])
  141.                 end
  142.             else
  143.                 sendCancel()
  144.             end
  145.         end
  146.         if buttonId == 3 then
  147.             if points >= attributes["sword"].reqPoints*5 then
  148.                 for i = 1,5 do
  149.                     addSkills(player, skillids["sword"])
  150.                 end
  151.             else
  152.                 sendCancel()
  153.             end
  154.         end
  155.     end
  156.     if choiceId == 5 then
  157.         if buttonId == 1 then
  158.             if points >= attributes["axe"].reqPoints then
  159.                 addSkills(player, skillids["axe"])
  160.             end
  161.         else
  162.                 sendCancel()
  163.         end
  164.         if buttonId == 2 then
  165.             if points >= attributes["axe"].reqPoints*2 then
  166.                 for i = 1,2 do
  167.                     addSkills(player, skillids["axe"])
  168.                 end
  169.             else
  170.                 sendCancel()
  171.             end
  172.         end
  173.         if buttonId == 3 then
  174.             if points >= attributes["axe"].reqPoints*5 then
  175.                 for i = 1,5 do
  176.                     addSkills(player, skillids["axe"])
  177.                 end
  178.             else
  179.                 sendCancel()
  180.             end
  181.         end
  182.     end
  183.     if choiceId == 6 then
  184.         if buttonId == 1 then
  185.             if points >= attributes["club"].reqPoints then
  186.                 addSkills(player, skillids["club"])
  187.             end
  188.         else
  189.             sendCancel()
  190.         end
  191.         if buttonId == 2 then
  192.             if points >= attributes["club"].reqPoints*2 then
  193.                 for i = 1,2 do
  194.                     addSkills(player, skillids["club"])
  195.                 end
  196.             else
  197.                 sendCancel()
  198.             end
  199.         end
  200.         if buttonId == 3 then
  201.             if points >= attributes["club"].reqPoints*5 then
  202.                 for i = 1,5 do
  203.                     addSkills(player, skillids["club"])
  204.                 end
  205.             else
  206.                 sendCancel()
  207.             end
  208.         end
  209.     end
  210.     if choiceId == 7 then
  211.         if buttonId == 1 then
  212.             if points >= attributes["shielding"].reqPoints then
  213.                 addSkills(player, skillids["shield"])
  214.             end
  215.         else
  216.             sendCancel()
  217.         end
  218.         if buttonId == 2 then
  219.             if points >= attributes["shielding"].reqPoints*2 then
  220.                 for i = 1,2 do
  221.                     addSkills(player, skillids["shield"])
  222.                 end
  223.             else
  224.                 sendCancel()
  225.             end
  226.         end
  227.         if buttonId == 3 then
  228.             if points >= attributes["shielding"].reqPoints*5 then
  229.                 for i = 1,5 do
  230.                     addSkills(player, skillids["shield"])
  231.                 end
  232.             else
  233.                 sendCancel()
  234.             end
  235.         end
  236.     end
  237.     if choiceId == 8 then
  238.         if buttonId == 1 then
  239.             if points >= attributes["distance"].reqPoints then
  240.                 addSkills(player, skillids["dist"])
  241.             end
  242.         else
  243.             sendCancel()
  244.         end
  245.         if buttonId == 2 then
  246.             if points >= attributes["distance"].reqPoints*2 then
  247.                 for i = 1,2 do
  248.                     addSkills(player, skillids["dist"])
  249.                 end
  250.             else
  251.                 sendCancel()
  252.             end
  253.         end
  254.         if buttonId == 3 then
  255.             if points >= attributes["distance"].reqPoints*5 then
  256.                 for i = 1,5 do
  257.                     addSkills(player, skillids["dist"])
  258.                 end
  259.             else
  260.                 sendCancel()
  261.             end
  262.         end
  263.     end
  264. end
  265.  
  266. local SkillPoints = {
  267.   [1] = 1,
  268.   [2] = 1,
  269.   [3] = 1,
  270.   [4] = 1,
  271.   [5] = 1,
  272.   [6] = 1,
  273.   [7] = 1,
  274.   [8] = 1,
  275.   }
  276. function onAdvance(player, skill, oldlevel, newlevel)
  277.     local cid = player:getId()
  278.     if not (SkillPoints[getPlayerVocation(cid)]) then
  279.         return true
  280.     end
  281.     if (skill == 8) then
  282.         if (getPlayerStorageValue(cid, 14573) < newlevel) then
  283.             if (getPlayerStorageValue(cid, 14574) < 0) then
  284.                     setPlayerStorageValue(cid, 14574, 0)
  285.                 setPlayerStorageValue(cid, 14573, 0)
  286.             end
  287.  
  288.                     setPlayerStorageValue(cid, 14573, newlevel)
  289.                 setPlayerStorageValue(cid, 14574, getPlayerStorageValue(cid, 14574) + (newlevel - oldlevel) * (SkillPoints[getPlayerVocation(cid)]))
  290.             doCreatureSay(cid, '+1 Skill Point!', TALKTYPE_MONSTER_SAY)
  291.         end
  292.     end
  293.  
  294.   return true
  295. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement