• 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 Increase critical/dodge skill onAdvance

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
964
Solutions
23
Reaction score
494
Location
Santiago - Chile
Hi again! I need to ask the following script for 1.4 (8.6 nekiro). I have a working dodge/critical script, and based on this, @Xikini already helped me to do a script that increases critical and dodge skill by making quests here Lua - Register 100 chests with different storage for the same reward. (https://otland.net/threads/register-100-chests-with-different-storage-for-the-same-reward.275784/#post-2654544)

I would like to have the same thing, with onAdvance event. I'll post the script that Xikini made here so you don't have to switch from threads:

Lua:
local chests = {
    [27101] = "critical", -- [uniqueId] = "type"
    [27102] = "critical",
    [27103] = "critical",
    [27104] = "dodge",
    [27105] = "dodge",
    [27106] = "dodge"
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local uniqueId = item:getUniqueId()
    local chestSelected = chests[uniqueId]
    if chestSelected then
        if player:getStorageValue(uniqueId) ~= -1 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE,"The chest is empty!")
            return true
        end
 
        -- critical
        if chestSelected == "critical" then
            if player:getCriticalLevel() >= CRITICAL.LEVEL_MAX then
                player:sendTextMessage(MESSAGE_STATUS_WARNING, "Unable to use chest. You have already reached the maximum critical skill.")
                return false
            end
            local newCriticalLevel = player:getCriticalLevel() + 1
            player:setCriticalLevel(newCriticalLevel)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have increased your critical skill to [" .. newCriticalLevel .. "/" .. CRITICAL.LEVEL_MAX .. "].")
            player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
 
        -- dodge
        elseif chestSelected == "dodge" then
            if player:getDodgeLevel() >= DODGE.LEVEL_MAX then
            player:sendTextMessage(MESSAGE_STATUS_WARNING, "Unable to use chest. You have already reached the maximum dodge skill.")
            return false
            end
            local newDodgeLevel = player:getDodgeLevel() + 1
            player:setDodgeLevel(newDodgeLevel)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have increased your dodge skill to [" .. newDodgeLevel .. "/" .. DODGE.LEVEL_MAX .. "].")
            player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
            -- give dodge stuff..
 
        else
            player:sendTextMessage(MESSAGE_STATUS_WARNING, "Error in table. Please contact gamemaster.") -- dodge or critical is mispelled in your table.
            return true
        end
 
        -- gives chest storage, so can't be used again
        player:setStorageValue(uniqueId, 1)
    end
    return true
end

In summary, I need that this get triggered by onAdvance (with dodge too):
Lua:
local newCriticalLevel = player:getCriticalLevel() + 1
player:setCriticalLevel(newCriticalLevel)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have increased your critical skill to [" .. newCriticalLevel .. "/" .. CRITICAL.LEVEL_MAX .. "].")
player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)

With this I also would like to:

a) Increase +1 critical level on level 10, another on level 20, on level 30, and so on.
b) Increase +1 dodge level on level 10, another on level 20, on level 30, and so on.
c) Have onLogin function to automatically fix the critical/dodge level according to player level.
d) Subtract critical/dodge level if the player dies and downgrade his level (---so that the player has the crit / dodge that corresponds to his level, in case the player, for example, downgrade from level 30 to level 29 or from level 40 to 39, etc.).
e) Send onLogin message event if the criti/dodge level has been reduced because of dying (when player logs in after dead).
f) Send onAdvance message event when player level up and raise his crit/dodge skill (on level 10, 20, 30, etc).

For the moment, this are all the situations I can imagine where a player can take advantage of a bug, I think the idea is understood, player must always have the corresponding critical/dodge level based on it's level. For example, if he's level 300, he will have +30 dodge/critical, if he's 240, will have +24 dodge/crit, and so on.

In advance, thanks so much for reading. Hope someone can help me doing this ^^
Regards!
 
Last edited:
Solution
Strictly speaking, I don't think this is a good way to do this.. since you are possibly setting the dodge level 13 times in a row..

But to answer your question about reducing/abbreviating the code..

Loops.
Lua:
for i = 1, 13 do
    if player:getLevel() > i * 10 then
        player:setCriticalLevel(i)
        player:setDodgeLevel(i)
    end
end

For this, you don't even need a loop.

Lua:
local playerLevel = player:getLevel()

if playerLevel >= 10 then
    local skillLevel = math.floor(playerLevel / 10)
    player:setCriticalLevel(skillLevel)
    player:setDodgeLevel(skillLevel)
end
OP
OP
ralke

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
964
Solutions
23
Reaction score
494
Location
Santiago - Chile
Here's the working critical/dodge script

lib/dodgeCritical.lua
creaturescript/dodgeCritical.lua
creaturescript/dodgeMana
creaturescript/login.lua
talkaction/dodge.lua
talkaction/critical.lua
Movie#4361, not sure if his username in otland is MovieBR

First ideas for point a) and b), and c) in login.lua. How I can abreviate this?
Lua:
    --- Automatic dodge/critical
    if player:getLevel() > 10 then
    player:setCriticalLevel(1)
    player:setDodgeLevel(1)
    end
    if player:getLevel() > 20 then
    player:setCriticalLevel(2)
    player:setDodgeLevel(2)
    end
    if player:getLevel() > 30 then
    player:setCriticalLevel(3)
    player:setDodgeLevel(3)
    end
    if player:getLevel() > 40 then
    player:setCriticalLevel(4)
    player:setDodgeLevel(4)
    end
    if player:getLevel() > 50 then
    player:setCriticalLevel(5)
    player:setDodgeLevel(5)
    end
    if player:getLevel() > 60 then
    player:setCriticalLevel(6)
    player:setDodgeLevel(6)
    end
    if player:getLevel() > 70 then
    player:setCriticalLevel(7)
    player:setDodgeLevel(7)
    end
    if player:getLevel() > 80 then
    player:setCriticalLevel(8)
    player:setDodgeLevel(8)
    end
    if player:getLevel() > 90 then
    player:setCriticalLevel(9)
    player:setDodgeLevel(9)
    end
    if player:getLevel() > 100 then
    player:setCriticalLevel(10)
    player:setDodgeLevel(10)
    end
    if player:getLevel() > 110 then
    player:setCriticalLevel(11)
    player:setDodgeLevel(11)
    end
    if player:getLevel() > 120 then
    player:setCriticalLevel(12)
    player:setDodgeLevel(12)
    end
    if player:getLevel() > 130 then
    player:setCriticalLevel(13)
    player:setDodgeLevel(13)
    end
 
Last edited:

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,808
Solutions
432
Reaction score
3,945
Here's the working critical/dodge script

lib/dodgeCritical.lua
creaturescript/dodgeCritical.lua
creaturescript/dodgeMana
creaturescript/login.lua
talkaction/dodge.lua
talkaction/critical.lua
Movie#4361, not sure if his username in otland is MovieBR

First ideas for point a) and b), and c) in login.lua. How I can abreviate this?
Lua:
    --- Automatic dodge/critical
    if player:getLevel() > 10 then
    player:setCriticalLevel(1)
    player:setDodgeLevel(1)
    end
    if player:getLevel() > 20 then
    player:setCriticalLevel(2)
    player:setDodgeLevel(2)
    end
    if player:getLevel() > 30 then
    player:setCriticalLevel(3)
    player:setDodgeLevel(3)
    end
    if player:getLevel() > 40 then
    player:setCriticalLevel(4)
    player:setDodgeLevel(4)
    end
    if player:getLevel() > 50 then
    player:setCriticalLevel(5)
    player:setDodgeLevel(5)
    end
    if player:getLevel() > 60 then
    player:setCriticalLevel(6)
    player:setDodgeLevel(6)
    end
    if player:getLevel() > 70 then
    player:setCriticalLevel(7)
    player:setDodgeLevel(7)
    end
    if player:getLevel() > 80 then
    player:setCriticalLevel(8)
    player:setDodgeLevel(8)
    end
    if player:getLevel() > 90 then
    player:setCriticalLevel(9)
    player:setDodgeLevel(9)
    end
    if player:getLevel() > 100 then
    player:setCriticalLevel(10)
    player:setDodgeLevel(10)
    end
    if player:getLevel() > 110 then
    player:setCriticalLevel(11)
    player:setDodgeLevel(11)
    end
    if player:getLevel() > 120 then
    player:setCriticalLevel(12)
    player:setDodgeLevel(12)
    end
    if player:getLevel() > 130 then
    player:setCriticalLevel(13)
    player:setDodgeLevel(13)
    end
Strictly speaking, I don't think this is a good way to do this.. since you are possibly setting the dodge level 13 times in a row..

But to answer your question about reducing/abbreviating the code..

Loops.
Lua:
for i = 1, 13 do
    if player:getLevel() > i * 10 then
        player:setCriticalLevel(i)
        player:setDodgeLevel(i)
    end
end
 

Boy67

Intermediate OT User
Joined
Jul 4, 2007
Messages
303
Solutions
12
Reaction score
125
Location
England
Strictly speaking, I don't think this is a good way to do this.. since you are possibly setting the dodge level 13 times in a row..

But to answer your question about reducing/abbreviating the code..

Loops.
Lua:
for i = 1, 13 do
    if player:getLevel() > i * 10 then
        player:setCriticalLevel(i)
        player:setDodgeLevel(i)
    end
end

For this, you don't even need a loop.

Lua:
local playerLevel = player:getLevel()

if playerLevel >= 10 then
    local skillLevel = math.floor(playerLevel / 10)
    player:setCriticalLevel(skillLevel)
    player:setDodgeLevel(skillLevel)
end
 
Solution

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,808
Solutions
432
Reaction score
3,945
For this, you don't even need a loop.

Lua:
local playerLevel = player:getLevel()

if playerLevel >= 10 then
    local skillLevel = math.floor(playerLevel / 10)
    player:setCriticalLevel(skillLevel)
    player:setDodgeLevel(skillLevel)
end
Strictly speaking, I don't think this is a good way to do this.. since you are possibly setting the dodge level 13 times in a row..

But to answer your question about reducing/abbreviating the code..
 

Boy67

Intermediate OT User
Joined
Jul 4, 2007
Messages
303
Solutions
12
Reaction score
125
Location
England
I understand what you said, but in this situation a loop isn't necessary. I posted this purely for his benefit. It was not my intention to make you look wrong or bad, because in the majority of cases you are correct :)
 
Top