Guest User

Untitled

a guest
Nov 17th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. function onLogin(cid)
  2. registerCreatureEvent(cid, "PlayerDeath")
  3.  
  4. -- CONFIG
  5. local secondsPerHit = 2 -- THE ATTACKSPEED (1 hit per 2 seconds; default)
  6. local manaGenPerSec = 10 -- MANA USED PER SEC
  7. local offlineModifier = 0.5 -- FROM 0-1 (or higher if you wish). How fast you are skillin on offline training compared to normal (0.5 = 50%)
  8. local maxSecondsTraining = 60 * 60 * 12 -- (Default 12 hours)
  9. --END of config
  10.  
  11. local accid = getAccountNumberByPlayerName(getCreatureName(cid))
  12. local name = getCreatureName(cid)
  13. local checkTraining = db.storeQuery("SELECT * FROM offline_training WHERE `account_id`=".. accid .." AND `name`='".. name .."';")
  14. local skills = {[8]=MAGIC, [4]=SKILL_DISTANCE,[1]=SKILL_CLUB, [3]=SKILL_AXE,[2]=SKILL_SWORD}
  15. local skillNames = {[8]="Magic Level", [4]="Distance Fighting",[1]="Club Fighting", [3]="AxeFighting",[2]="Sword Fighting"}
  16.  
  17. if checkTraining then
  18.  
  19. local skill = result.getDataInt(checkTraining, "type")
  20. local timeTrained = result.getDataInt(checkTraining, "start_training")
  21. local secondsTrained = os.time()-timeTrained
  22. local skillTries = math.floor((secondsTrained/secondsPerHit)*offlineModifier)
  23. local skillBefore
  24. local skillAfter
  25.  
  26. if timeTrained > maxSecondsTraining then
  27. timeTrained = maxSecondsTraining
  28. end
  29.  
  30. if skill ~= 8 then
  31. skillBefore = getPlayerSkillLevel(cid, skills[skill])
  32. doPlayerAddSkillTry(cid, skills[skill], skillTries)
  33. skillAfter = getPlayerSkillLevel(cid, skills[skill])
  34. else
  35. skillBefore = getPlayerMagLevel(cid)
  36. doPlayerAddSpentMana(cid, manaGenPerSec*secondsTrained)
  37. skillAfter = getPlayerMagLevel(cid)
  38. end
  39.  
  40.  
  41. local skillBeforeShield = getPlayerSkillLevel(cid, 5)
  42. doPlayerAddSkillTry(cid, 5, skillTries)
  43. local skillAfterShield = getPlayerSkillLevel(cid, 5)
  44.  
  45.  
  46.  
  47. doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Your ".. skillNames[skill] .." skill changed from level ".. skillBefore.." to level ".. skillAfter ..".")
  48. doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Your Shielding skill changed from level ".. skillBeforeShield.." to level ".. skillAfterShield ..". ")
  49.  
  50. db.query("DELETE FROM offline_training WHERE `account_id`=".. accid .." AND `name`='".. name .."';")
  51.  
  52. end
  53.  
  54. return TRUE
  55. end
  56.  
  57. function round(num, idp)
  58. local mult = 10^(idp or 0)
  59. return math.floor(num * mult + 0.5) / mult
  60. end
Add Comment
Please, Sign In to add comment