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

Solved help fix part of code

shivaria

Active Member
Joined
Sep 2, 2009
Messages
158
Reaction score
36
SOLVED: When using Shield Skills, always "getEffectiveSkillLevel" and not "getSkillLevel"
Wish I knew about this before! lol

I am using a hammer on an item(9966) while its on an anvil. The code works and removes the item, creates the item, but ignores my code and goes straight to where i wrote fail22.
TFS 1.1 (10.77)

Code:
local config = {
exhaustOnUse = 500 -- miliseconds
}

local exhaust = Condition(CONDITION_EXHAUST_WEAPON)
exhaust:setParameter(CONDITION_PARAM_TICKS, config.exhaustOnUse)

local lootCommon = {7386, 15454, 2425, 2435, 2532, 15410, 15409, 21692, 2474}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local forgingLevel = player:getSkillLevel(cid, SKILL_SHIELD)
        -- --------------------- --
           if player:getCondition(CONDITION_EXHAUST_WEAPON) then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_YOUAREEXHAUSTED))
        return true
    end
    player:addCondition(exhaust)
-------------------- start area clear path ----------------------------------
if target.itemid == 9966 then

    if toPosition.x == 65535 or getTileItemById(toPosition, 2555).uid == 0 then
    player:say("Must be forged at an Anvil", TALKTYPE_MONSTER_SAY)
    return true
    end
    toPosition:sendMagicEffect(6)
        if forgingLevel < 3 then
            if math.random(5) == 1 then
            target:remove(1)
            player:say("Fail", TALKTYPE_MONSTER_SAY)
            return true 
            else
            player:say("Miss!", TALKTYPE_MONSTER_SAY) 
            player:addSkillTries(SKILL_SHIELD, 1) 
            return true 
            end
        elseif forgingLevel < 6 then ---------- LEVELS ----------------
            if math.random(10) == 1 then
            target:remove(1)
            player:addItem(lootCommon[math.random(#lootCommon)], 1)
            toPosition:sendMagicEffect(7)
            player:say("Success!", TALKTYPE_MONSTER_SAY)
            player:addSkillTries(SKILL_SHIELD, 7)
            return true 
            else
            player:say("Fail22 KEEPS GOING HERE EVEN WITH SHIELD LEVEL 1,2,3,4 etc", TALKTYPE_MONSTER_SAY) 
            player:addSkillTries(SKILL_SHIELD, 1) 
            target:remove(1)
            return true 
            end     
        elseif forgingLevel < 9 then ---------- LEVELS ----------------
            if math.random(8) == 1 then
            player:addItem(lootCommon[math.random(#lootCommon)], 1)
            toPosition:sendMagicEffect(7)
            player:say("Success!", TALKTYPE_MONSTER_SAY)
            player:addSkillTries(SKILL_SHIELD, 7) 
            return true 
            else
            player:say("Fail", TALKTYPE_MONSTER_SAY) 
            player:addSkillTries(SKILL_SHIELD, 1) 
            target:transform(0)
            return true 
            end             
        elseif forgingLevel < 12 then ---------- LEVELS ----------------
            if math.random(6) == 1 then
            player:addItem(lootCommon[math.random(#lootCommon)], 1)
            toPosition:sendMagicEffect(7)
            player:say("Success!", TALKTYPE_MONSTER_SAY)
            player:addSkillTries(SKILL_SHIELD, 7)
            return true 
            else
            player:say("Fail", TALKTYPE_MONSTER_SAY) 
            player:addSkillTries(SKILL_SHIELD, 1) 
            target:transform(0)
            return true 
            end     
        elseif forgingLevel < 15 then ---------- LEVELS ----------------
            if math.random(4) == 1 then
            player:addItem(lootCommon[math.random(#lootCommon)], 1)
            toPosition:sendMagicEffect(7)
            player:say("Success!", TALKTYPE_MONSTER_SAY)
            player:addSkillTries(SKILL_SHIELD, 7)
            return true 
            else
            player:say("Fail", TALKTYPE_MONSTER_SAY) 
            player:addSkillTries(SKILL_SHIELD, 1) 
            target:transform(0)
            return true 
            end         
        elseif forgingLevel < 18 then ---------- LEVELS ----------------
            if math.random(3) == 1 then
            player:addItem(lootCommon[math.random(#lootCommon)], 1)
            toPosition:sendMagicEffect(7)
            player:say("Success!", TALKTYPE_MONSTER_SAY)
            player:addSkillTries(SKILL_SHIELD, 7)
            return true 
            else
            player:say("Fail", TALKTYPE_MONSTER_SAY) 
            player:addSkillTries(SKILL_SHIELD, 1) 
            target:transform(0)
            return true 
            end         
        elseif forgingLevel < 20 then ---------- LEVELS ----------------
            if math.random(2) == 1 then
            player:addItem(lootCommon[math.random(#lootCommon)], 1)
            toPosition:sendMagicEffect(7)
            player:say("Success!", TALKTYPE_MONSTER_SAY)
            player:addSkillTries(SKILL_SHIELD, 7)
            return true 
            else
            player:say("Fail", TALKTYPE_MONSTER_SAY) 
            player:addSkillTries(SKILL_SHIELD, 1) 
            target:transform(0)
            return true 
            end 
        elseif forgingLevel < 255 then ---------- LEVELS ----------------
            if math.random(1) == 1 then
            player:addItem(lootCommon[math.random(#lootCommon)], 1)
            toPosition:sendMagicEffect(7)
            player:say("Perfect!", TALKTYPE_MONSTER_SAY)
            player:addSkillTries(SKILL_SHIELD, 7)
            return true             
            end
    end
    else
    return false
end
end
 
Last edited:
Code:
local config = {
exhaustOnUse = 500 -- miliseconds
}

local exhaust = Condition(CONDITION_EXHAUST_WEAPON)
exhaust:setParameter(CONDITION_PARAM_TICKS, config.exhaustOnUse)

local lootCommon = {7386, 15454, 2425, 2435, 2532, 15410, 15409, 21692, 2474}

function equalsRandomNumber(num)
    return math.floor(math.random(1, num)) == 1
end

function returnMinMax(min, max, value)
    return min <= value and max >= value
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local forgingLevel = player:getSkillLevel(cid, SKILL_SHIELD)
        -- --------------------- --
           if player:getCondition(CONDITION_EXHAUST_WEAPON) then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_YOUAREEXHAUSTED))
        return true
    end
    player:addCondition(exhaust)
-------------------- start area clear path ----------------------------------
    if target.itemid == 9966 then

        if toPosition.x == 65535 or getTileItemById(toPosition, 2555).uid == 0 then
            player:say("Must be forged at an Anvil", TALKTYPE_MONSTER_SAY)
            return true
        end
        toPosition:sendMagicEffect(6)
        if returnMinMax(1, 3, forgingLevel) then
            if equalsRandomNumber(5) then
                target:remove(1)
                player:say("Fail", TALKTYPE_MONSTER_SAY)
                return true 
            else
                player:say("Miss!", TALKTYPE_MONSTER_SAY) 
                player:addSkillTries(SKILL_SHIELD, 1) 
                return true 
            end
        elseif returnMinMax(4, 6, forgingLevel) then ---------- LEVELS ----------------
            if equalsRandomNumber(10) then
                target:remove(1)
                player:addItem(lootCommon[math.random(#lootCommon)], 1)
                toPosition:sendMagicEffect(7)
                player:say("Success!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 7)
                return true 
            else
                player:say("Fail22 KEEPS GOING HERE EVEN WITH SHIELD LEVEL 1,2,3,4 etc", TALKTYPE_MONSTER_SAY) 
                player:addSkillTries(SKILL_SHIELD, 1) 
                target:remove(1)
                return true 
            end
        elseif returnMinMax(7, 9, forgingLevel) then ---------- LEVELS ----------------
            if equalsRandomNumber(8) then
                player:addItem(lootCommon[math.random(#lootCommon)], 1)
                toPosition:sendMagicEffect(7)
                player:say("Success!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 7) 
                return true 
            else
                player:say("Fail", TALKTYPE_MONSTER_SAY) 
                player:addSkillTries(SKILL_SHIELD, 1) 
                target:transform(0)
                return true 
            end
        elseif returnMinMax(10, 12, forgingLevel) then ---------- LEVELS ----------------
            if equalsRandomNumber(6) then
                player:addItem(lootCommon[math.random(#lootCommon)], 1)
                toPosition:sendMagicEffect(7)
                player:say("Success!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 7)
                return true 
            else
                player:say("Fail", TALKTYPE_MONSTER_SAY) 
                player:addSkillTries(SKILL_SHIELD, 1) 
                target:transform(0)
                return true 
            end 
        elseif returnMinMax(13, 15, forgingLevel) then ---------- LEVELS ----------------
            if equalsRandomNumber(4) then
                player:addItem(lootCommon[math.random(#lootCommon)], 1)
                toPosition:sendMagicEffect(7)
                player:say("Success!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 7)
                return true 
            else
                player:say("Fail", TALKTYPE_MONSTER_SAY) 
                player:addSkillTries(SKILL_SHIELD, 1) 
                target:transform(0)
                return true 
            end
        elseif returnMinMax(16, 18, forgingLevel) then ---------- LEVELS ----------------
            if equalsRandomNumber(3) then
                player:addItem(lootCommon[math.random(#lootCommon)], 1)
                toPosition:sendMagicEffect(7)
                player:say("Success!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 7)
                return true 
            else
                player:say("Fail", TALKTYPE_MONSTER_SAY) 
                player:addSkillTries(SKILL_SHIELD, 1) 
                target:transform(0)
                return true 
            end
        elseif returnMinMax(19, 20, forgingLevel) then ---------- LEVELS ----------------
            if equalsRandomNumber(2) then
                player:addItem(lootCommon[math.random(#lootCommon)], 1)
                toPosition:sendMagicEffect(7)
                player:say("Success!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 7)
                return true 
            else
                player:say("Fail", TALKTYPE_MONSTER_SAY) 
                player:addSkillTries(SKILL_SHIELD, 1) 
                target:transform(0)
                return true 
            end 
        elseif returnMinMax(21, 255, forgingLevel) then ---------- LEVELS ----------------
            if equalsRandomNumber(1) then
                player:addItem(lootCommon[math.random(#lootCommon)], 1)
                toPosition:sendMagicEffect(7)
                player:say("Perfect!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 7)
                return true             
            end
        end
    else
        return false
    end
end
 
Last edited:
Code:
local config = {
exhaustOnUse = 500 -- miliseconds
}

local exhaust = Condition(CONDITION_EXHAUST_WEAPON)
exhaust:setParameter(CONDITION_PARAM_TICKS, config.exhaustOnUse)

local lootCommon = {7386, 15454, 2425, 2435, 2532, 15410, 15409, 21692, 2474}

function equalsRandomNumber(num)
    return math.floor(math.random(1, num)) == 1
end

function returnMinMax(min, max, value)
    return min <= value and max >= value
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local forgingLevel = player:getSkillLevel(cid, SKILL_SHIELD)
        -- --------------------- --
           if player:getCondition(CONDITION_EXHAUST_WEAPON) then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_YOUAREEXHAUSTED))
        return true
    end
    player:addCondition(exhaust)
-------------------- start area clear path ----------------------------------
    if target.itemid == 9966 then

        if toPosition.x == 65535 or getTileItemById(toPosition, 2555).uid == 0 then
            player:say("Must be forged at an Anvil", TALKTYPE_MONSTER_SAY)
            return true
        end
        toPosition:sendMagicEffect(6)
        if returnMinMax(1, 3, forgingLevel) then
            if equalsRandomNumber(5) then
                target:remove(1)
                player:say("Fail", TALKTYPE_MONSTER_SAY)
                return true
            else
                player:say("Miss!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 1)
                return true
            end
        elseif returnMinMax(4, 6, forgingLevel) then ---------- LEVELS ----------------
            if equalsRandomNumber(10) then
                target:remove(1)
                player:addItem(lootCommon[math.random(#lootCommon)], 1)
                toPosition:sendMagicEffect(7)
                player:say("Success!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 7)
                return true
            else
                player:say("Fail22 KEEPS GOING HERE EVEN WITH SHIELD LEVEL 1,2,3,4 etc", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 1)
                target:remove(1)
                return true
            end
        elseif returnMinMax(7, 9, forgingLevel) then ---------- LEVELS ----------------
            if equalsRandomNumber(8) then
                player:addItem(lootCommon[math.random(#lootCommon)], 1)
                toPosition:sendMagicEffect(7)
                player:say("Success!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 7)
                return true
            else
                player:say("Fail", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 1)
                target:transform(0)
                return true
            end
        elseif returnMinMax(10, 12, forgingLevel) then ---------- LEVELS ----------------
            if equalsRandomNumber(6) then
                player:addItem(lootCommon[math.random(#lootCommon)], 1)
                toPosition:sendMagicEffect(7)
                player:say("Success!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 7)
                return true
            else
                player:say("Fail", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 1)
                target:transform(0)
                return true
            end
        elseif returnMinMax(13, 15, forgingLevel) then ---------- LEVELS ----------------
            if equalsRandomNumber(4) then
                player:addItem(lootCommon[math.random(#lootCommon)], 1)
                toPosition:sendMagicEffect(7)
                player:say("Success!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 7)
                return true
            else
                player:say("Fail", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 1)
                target:transform(0)
                return true
            end
        elseif returnMinMax(16, 18, forgingLevel) then ---------- LEVELS ----------------
            if equalsRandomNumber(3) then
                player:addItem(lootCommon[math.random(#lootCommon)], 1)
                toPosition:sendMagicEffect(7)
                player:say("Success!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 7)
                return true
            else
                player:say("Fail", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 1)
                target:transform(0)
                return true
            end
        elseif returnMinMax(19, 20, forgingLevel) then ---------- LEVELS ----------------
            if equalsRandomNumber(2) then
                player:addItem(lootCommon[math.random(#lootCommon)], 1)
                toPosition:sendMagicEffect(7)
                player:say("Success!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 7)
                return true
            else
                player:say("Fail", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 1)
                target:transform(0)
                return true
            end
        elseif returnMinMax(21, 255, forgingLevel) then ---------- LEVELS ----------------
            if equalsRandomNumber(1) then
                player:addItem(lootCommon[math.random(#lootCommon)], 1)
                toPosition:sendMagicEffect(7)
                player:say("Perfect!", TALKTYPE_MONSTER_SAY)
                player:addSkillTries(SKILL_SHIELD, 7)
                return true           
            end
        end
    else
        return false
    end
end
I tested it and its really awesome but when I reach level 4 shield skill, it still thinks im levels 1-3 and says "miss"

I also tried using this:
Code:
local config = {
    db_table = 'players',
    db_pointsColumn = 'skill_shielding',
    db_idColumn = 'id',
}
local forgingLevel = db.storeQuery("SELECT `"..config.db_pointsColumn.."` FROM `"..config.db_table.."` WHERE `"..config.db_idColumn.."` = "..player:getAccountId())
and it works without errors, but doesnt return an accurate shield level either.
 
Last edited:
Code:
local forgingLevel = db.storeQuery("SELECT `"..config.db_pointsColumn.."` FROM `"..config.db_table.."` WHERE `"..config.db_idColumn.."` = "..player:getAccountId())

Do you really want to get the player shielding skill by passing his account id?

Try this:
Code:
local forgingLevel = db.storeQuery("SELECT `"..config.db_pointsColumn.."` FROM `"..config.db_table.."` WHERE `"..config.db_idColumn.."` = "..player:getGuid())
 
Back
Top