• 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!

Lua Custom Skill Leveling

noshirtstan

New Member
Joined
Aug 2, 2020
Messages
68
Reaction score
2
Hey folks, I'm having an issue with custom skills.

So when the player, uses the item for the skill it should level the players skill. But it doesn't seem to be working that way at all.

Here is what I have so far. TFS 1.3

Lua:
function Player.isGatheringJob(self, storage)
   if self:getStorageValue(storage) >= 1 then
     return true
   end
end
craftingGatheringJobConfig = {
   [50605] = {
     skillName = "Mining",
     storage = 501,
     message = "Gathering allows you to procure the items required for crafting.\n\n"
   },
   [50602] = {
     skillName = "Skinning",
     storage = 502,
     message = "Gathering allows you to procure ~"
   },
   [50603] = {
     skillName = "Foraging",
     storage = 503,
     message = "Gathering allows you to procure ~"
   },
   [50604] = {
     skillName = "Logging",
     storage = 504,
     message = "Gathering allows you to procure ~"
   },
   maxSkill = 350,
   baseRecipeStorage = 50600,
   extraData = {},
}

--[CustomSkill]-- By: Athern
function Player.getCustomSkill(self, storage)
    return self:getStorageValue(storage)
end
function Player.addCustomSkill(self, skillName, storage)
    local skillStorage = math.max(10, self:getStorageValue(storage))
    local skillTries =  math.max(0, self:getStorageValue(storage + 1))
    self:setStorageValue(storage, skillStorage + 1)
    self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You advanced to " .. string.lower(skillName) .. " level "..self:getCustomSkill(storage)..".")
    self:setStorageValue(storage + 1, 0)
end
function Player.addCustomSkillTry(self, skillName, storage)
    local skillStorage = math.max(10, self:getStorageValue(storage))
    local skillTries =  math.max(0, self:getStorageValue(storage + 1))
    self:setStorageValue(storage + 1, skillTries + 1)
    if skillTries > math.floor(20 * math.pow(1.1, (skillStorage - 11)) / 10) then
        self:addCustomSkill(skillName, storage)
    end
end
function Player.getCustomSkillPercent(self, storage)
    local skillStorage = math.max(10, self:getStorageValue(storage))
    local skillTries =  math.max(0, self:getStorageValue(storage + 1))
    local triesNeeded = math.floor(20 * math.pow(1.1, (skillStorage - 11)) / 10)
    local percent = math.floor(100 * (1 - skillTries / triesNeeded))
    if percent > 1 and percent <= 100 then
        return percent
    else
        percent = 1
        return percent
    end
end
--[/CustomSkill]--

Any thoughts?
Post automatically merged:

This is how I am calling the funtion:

Lua:
function onUse(player, item, fromPosition, itemEx, toPosition)
    if item.itemid == 26405 and isInArray({50605, 50602, 50603, 50604}, item.actionid) then
        if player:getCondition(player, CONDITION_COOLDOWN, 160) then
            player:sendCancelMessage("You are already gathering!")
            return true
        end
       
        if not player:isGatheringJob(item.actionid) then
            player:sendCancelMessage("You must learn "..craftingGatheringJobConfig[item.actionid].skillName.." before using this.")
            return true
        end
       
        if player:isGatheringJob(item.actionid) then
       
            if player:getStorageValue(205000) > os.time() then
                player:sendCancelMessage("You must wait before mining this again!")
                return true
           
            end
            if player:getItemCount(2553) >= 1 then -- check for pick
            mathCheck = math.floor(math.random() * 100) + 1
            if mathCheck >= 50 then
                player:addItem(26410, math.floor(math.random() * 3) + 1)
            elseif mathCheck <= 49 then
                player:addItem(26409, math.floor(math.random() * 3)+ 1)
            end
            else
                player:sendCancelMessage("You need a pick to use this!")
                return true
                end
            end
            player:setStorageValue(205000, os.time() + 1)
            mathCheck2 = math.floor(math.random() * 100) + 1
            if mathCheck2 >= 35 then
                player:sendCancelMessage("You successfully mined the ore!")
                    skillGain = 1
                    for i = 1, skillGain do
                    player:addCustomSkillTry(craftingGatheringJobConfig.skillName)
                    end
                return true
            elseif mathCheck2 <= 34 then
                item:transform(26404)
                item:decay(26405)
                player:sendCancelMessage("You've exhausted this vein")
            end

This is the error I am getting:

1598717444639.png
 
Last edited:
Back
Top