• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ Remove Magic Level?

Fischturd

Member
Joined
Jan 30, 2023
Messages
26
Reaction score
5
GitHub
Fischturd
Hey everybody, I have a script I am working on to remove club and magic level when using a item

Lua:
                    local decreaseSkillLevels = 15
                    
                    local currentClubSkill = player:getSkillLevel(SKILL_CLUB) or 0
                    local currentMagicLevelSkill = player:getBaseMagicLevel() or 0
                    
                    print("Before - Current Magic Level Skill:", currentMagicLevelSkill)
                    print("Debug -  Player Info:", player:getId(), player:getName(), player:getBaseMagicLevel())
                    
                    -- Decrease Club Skill
                    local decreaseClubLevel = math.min(decreaseSkillLevels, currentClubSkill)
                    player:addSkillLevel(SKILL_CLUB, -decreaseClubLevel)
                    
                    -- Decrease Magic Level
                    local decreaseMagicLevel = math.min(decreaseSkillLevels, currentMagicLevelSkill)
                    player:addSkillLevel(SKILL_MAGLEVEL, -decreaseMagicLevel)
                    
                    local newMagicLevelSkill = math.max(0, currentMagicLevelSkill - decreaseSkillLevels)
                    print("After - New Magic Level Skill:", newMagicLevelSkill)

The club skill downgrades just fine with no issues, but the magic level doesn't....I kind of played around with manaspent and it reduces the levels but it is not going to be the same values across the board?
So... how could we make it decrease by 15 flat value?

Here is the debug log

Before - Current Magic Level Skill: 200
Debug - Player Info: "playerid" Noob 200
Warning: Current skill level is nil.
After - New Magic Level Skill: 185

But it does not decrease the magic level to 185.. it stays at 20



Any help appreciated!
 
Solution
That's the function for removing magic level:
player:removeManaSpent(amount[, notify = true])

There are also useful function to use with this:
vocation:getRequiredManaSpent(magicLevel)
player:getMagicLevel ... getBaseMagicLevel ... getManaSpent etc.

Magic level is not really regarded as a skill, it was always separated from other skills even in database it is in other place. It also doesn't have "tries", it is calculated based on mana spent.


Btw, your way of debugging does NOT make sense. You just substracted constant value from another constant value, ofc it worked in debug log... its just basic substraction. The correct way is to: print("New club level after: ", player:getSkillLevel(SKILL_CLUB)) for example.
print("New magic level...
That's the function for removing magic level:
player:removeManaSpent(amount[, notify = true])

There are also useful function to use with this:
vocation:getRequiredManaSpent(magicLevel)
player:getMagicLevel ... getBaseMagicLevel ... getManaSpent etc.

Magic level is not really regarded as a skill, it was always separated from other skills even in database it is in other place. It also doesn't have "tries", it is calculated based on mana spent.


Btw, your way of debugging does NOT make sense. You just substracted constant value from another constant value, ofc it worked in debug log... its just basic substraction. The correct way is to: print("New club level after: ", player:getSkillLevel(SKILL_CLUB)) for example.
print("New magic level after: ", player:getMagicLevel()).
 
Solution
Back
Top