Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. -- config, in percent of normal training with 2 trainers and player vocation mana regeneration [by food]
  2. OfflineTraining_rates = {
  3. [SKILL_CLUB] = 100,
  4. [SKILL_SWORD] = 100,
  5. [SKILL_AXE] = 100,
  6. [SKILL_DISTANCE] = 100,
  7. [SKILL_SHIELD] = 100,
  8. [SKILL__MAGLEVEL] = 100
  9. }
  10. -- function that you should edit to make it add other skill etc.
  11. function OfflineTraining_canStartTraining(cid) -- return bool
  12. return getCreatureStorage(cid, 62669) > 0
  13. end
  14. function OfflineTraining_onStartTraining(cid)
  15. -- maybe someone will need
  16. -- to save your time, this: doPlayerPopupFYI(cid, "You started offline training.")
  17. -- NOT WORK :(
  18. end
  19. function OfflineTraining_onEndTraining(cid)
  20. doCreatureSetStorage(cid, 62669, 0)
  21. end
  22. function OfflineTraining_addTrainedSkills(cid, trainTime) -- time in minutes!
  23. local timeInSeconds = trainTime * 60
  24. local vocInfo = getVocationInfo(getPlayerVocation(cid))
  25. if(getCreatureStorage(cid, 62669) == SKILL_SWORD) then
  26. doPlayerAddSkillTry(cid, SKILL_SWORD, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_SWORD] / 100, true)
  27. elseif(getCreatureStorage(cid, 62669) == SKILL_AXE) then
  28. doPlayerAddSkillTry(cid, SKILL_AXE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_AXE] / 100, true)
  29. elseif(getCreatureStorage(cid, 62669) == SKILL__MAGLEVEL) then
  30. doPlayerAddSpentMana(cid, ((timeInSeconds / vocInfo["manaGainTicks"]) * vocInfo["manaGain"]) * OfflineTraining_rates[SKILL__MAGLEVEL] / 100, true)
  31. elseif(getCreatureStorage(cid, 62669) == SKILL_CLUB) then
  32. doPlayerAddSkillTry(cid, SKILL_CLUB, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_CLUB] / 100, true)
  33. elseif(getCreatureStorage(cid, 62669) == SKILL_DISTANCE) then
  34. doPlayerAddSkillTry(cid, SKILL_DISTANCE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_DISTANCE] / 100, true)
  35. end
  36. doPlayerAddSkillTry(cid, SKILL_SHIELD, timeInSeconds * OfflineTraining_rates[SKILL_SHIELD] / 100, true)
  37. end
  38.  
  39. -- 4 functions to show right values on 'bar' in Tibia 9.6
  40. function OfflineTraining_getTime(cid)
  41. return getCreatureStorage(cid, 62666)
  42. end
  43. function OfflineTraining_setTime(cid, newTime)
  44. -- set values only between 0 - 720 [12 hours]
  45. doCreatureSetStorage(cid, 62666, math.max(0, math.min(newTime, 720)))
  46. -- now code to force server to send 'PlayerStats' (including Offline Time)
  47. -- we must change any stat: hp,mana,stamina,cap,soul,exp,level
  48. doPlayerAddSoul(cid, 1)
  49. doPlayerAddSoul(cid, -1)
  50. end
  51. function OfflineTraining_addTime(cid, addTime)
  52. OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) + addTime)
  53. end
  54. function OfflineTraining_removeTime(cid, removeTime)
  55. OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) - removeTime)
  56. end
  57.  
  58. -- functions for library to add skills/mlvl
  59. function OfflineTraining_initialize(cid)
  60. if(OfflineTraining_getTime(cid) == -1) then
  61. OfflineTraining_setTime(cid, 720)
  62. OfflineTraining_setLogoutTime(cid) -- block problem with first login 'add time'
  63. end
  64. end
  65. function OfflineTraining_isTraining(cid)
  66. return (getCreatureStorage(cid, 62667) > 0)
  67. end
  68. function OfflineTraining_turnOnTraining(cid)
  69. doCreatureSetStorage(cid, 62667, 1)
  70. end
  71. function OfflineTraining_turnOffTraining(cid)
  72. doCreatureSetStorage(cid, 62667, 0)
  73. end
  74. function OfflineTraining_getOfflineTime(cid)
  75. return math.floor((os.time() - getCreatureStorage(cid, 62668)) / 60)
  76. end
  77. function OfflineTraining_setLogoutTime(cid)
  78. return doCreatureSetStorage(cid, 62668, os.time())
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement