Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onLogin(cid)
- registerCreatureEvent(cid, "PlayerDeath")
- -- CONFIG
- local secondsPerHit = 2 -- THE ATTACKSPEED (1 hit per 2 seconds; default)
- local manaGenPerSec = 10 -- MANA USED PER SEC
- 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%)
- local maxSecondsTraining = 60 * 60 * 12 -- (Default 12 hours)
- --END of config
- local accid = getAccountNumberByPlayerName(getCreatureName(cid))
- local name = getCreatureName(cid)
- local checkTraining = db.storeQuery("SELECT * FROM offline_training WHERE `account_id`=".. accid .." AND `name`='".. name .."';")
- local skills = {[8]=MAGIC, [4]=SKILL_DISTANCE,[1]=SKILL_CLUB, [3]=SKILL_AXE,[2]=SKILL_SWORD}
- local skillNames = {[8]="Magic Level", [4]="Distance Fighting",[1]="Club Fighting", [3]="AxeFighting",[2]="Sword Fighting"}
- if checkTraining then
- local skill = result.getDataInt(checkTraining, "type")
- local timeTrained = result.getDataInt(checkTraining, "start_training")
- local secondsTrained = os.time()-timeTrained
- local skillTries = math.floor((secondsTrained/secondsPerHit)*offlineModifier)
- local skillBefore
- local skillAfter
- if timeTrained > maxSecondsTraining then
- timeTrained = maxSecondsTraining
- end
- if skill ~= 8 then
- skillBefore = getPlayerSkillLevel(cid, skills[skill])
- doPlayerAddSkillTry(cid, skills[skill], skillTries)
- skillAfter = getPlayerSkillLevel(cid, skills[skill])
- else
- skillBefore = getPlayerMagLevel(cid)
- doPlayerAddSpentMana(cid, manaGenPerSec*secondsTrained)
- skillAfter = getPlayerMagLevel(cid)
- end
- local skillBeforeShield = getPlayerSkillLevel(cid, 5)
- doPlayerAddSkillTry(cid, 5, skillTries)
- local skillAfterShield = getPlayerSkillLevel(cid, 5)
- doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Your ".. skillNames[skill] .." skill changed from level ".. skillBefore.." to level ".. skillAfter ..".")
- doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Your Shielding skill changed from level ".. skillBeforeShield.." to level ".. skillAfterShield ..". ")
- db.query("DELETE FROM offline_training WHERE `account_id`=".. accid .." AND `name`='".. name .."';")
- end
- return TRUE
- end
- function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
Add Comment
Please, Sign In to add comment