• 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 Compare SKILL sword > SKILL club

luccagomes

New Member
Joined
Jul 30, 2015
Messages
153
Reaction score
1
Code:
         local axeskill = getPlayerSkillLevel(cid, SKILL_AXE)
         local swordskill = getPlayerSkillLevel(cid, SKILL_CLUB)
         local clubskill = getPlayerSkillLevel(cid, SKILL_SWORD)
         if (axeskill > swordskill and axeskill > clubskill) then
           doPlayerAddSkillTry(cid, SKILL_AXE, axeqnt * axestages)
         elseif (swordskill > axeskill and swordskill > clubskill) then
           doPlayerAddSkillTry(cid, SKILL_SWORD, swordqnt * swordstages)
         elseif (clubskill > axeskill and clubskill > swordskill) then
           doPlayerAddSkillTry(cid, SKILL_CLUB, clubqnt * clubstages)
         else -- negando tudo se bugar sei la
           doPlayerAddSkillTry(cid, SKILL_SWORD, swordqnt * swordstages)
         end

i was skill
club : 25
sword : 57

and when i use this part script it add CLUB SKILL
doPlayerAddSkillTry(cid, SKILL_CLUB, clubqnt * clubstages)


why? what i supossedd to do?
 
clubqnt and clubstages are not defined in your code fragment, if they are defined elsewhere please include them in your example.
 
clubqnt and clubstages are not defined in your code fragment, if they are defined elsewhere please include them in your example.

I do not understand why is not working

Code:
local shieldqnt
shieldqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD) + 1)/3000) * (getPlayerStorageValue(cid, storages.length) * 3) * (getPlayerStorageValue(cid, storages.difficult) * 1)
local distanceqnt
distanceqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_DISTANCE, getPlayerSkillLevel(cid, SKILL_DISTANCE) + 1)/3000) * (getPlayerStorageValue(cid, storages.length) * 3) * (getPlayerStorageValue(cid, storages.difficult) * 1)
local axeqnt
axeqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_AXE, getPlayerSkillLevel(cid, SKILL_AXE) + 1)/3000) * (getPlayerStorageValue(cid, storages.length) * 3) * (getPlayerStorageValue(cid, storages.difficult) * 1)
local swordqnt
swordqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_SWORD, getPlayerSkillLevel(cid, SKILL_SWORD) + 1)/3000) * (getPlayerStorageValue(cid, storages.length) * 3) * (getPlayerStorageValue(cid, storages.difficult) * 1)
local clubqnt
clubqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_CLUB, getPlayerSkillLevel(cid, SKILL_CLUB) + 1)/3000) * (getPlayerStorageValue(cid, storages.length) * 3) * (getPlayerStorageValue(cid, storages.difficult) * 1)
 
I do not understand why is not working

Code:
local shieldqnt
shieldqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD) + 1)/3000) * (getPlayerStorageValue(cid, storages.length) * 3) * (getPlayerStorageValue(cid, storages.difficult) * 1)
local distanceqnt
distanceqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_DISTANCE, getPlayerSkillLevel(cid, SKILL_DISTANCE) + 1)/3000) * (getPlayerStorageValue(cid, storages.length) * 3) * (getPlayerStorageValue(cid, storages.difficult) * 1)
local axeqnt
axeqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_AXE, getPlayerSkillLevel(cid, SKILL_AXE) + 1)/3000) * (getPlayerStorageValue(cid, storages.length) * 3) * (getPlayerStorageValue(cid, storages.difficult) * 1)
local swordqnt
swordqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_SWORD, getPlayerSkillLevel(cid, SKILL_SWORD) + 1)/3000) * (getPlayerStorageValue(cid, storages.length) * 3) * (getPlayerStorageValue(cid, storages.difficult) * 1)
local clubqnt
clubqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_CLUB, getPlayerSkillLevel(cid, SKILL_CLUB) + 1)/3000) * (getPlayerStorageValue(cid, storages.length) * 3) * (getPlayerStorageValue(cid, storages.difficult) * 1)
Did you do the math regarding these formula's?
I mean you need to make sure that the outcome of the sum (the end result of your formula) does not exceed the data type's range (the internal variable or function you are passing sum to).

Or did you just make it up and figured it just looked good on paper...

This code is a bit messy and excessive, I would make a function with parameters to clean up the code...
Also a lot of the code makes absolutely no sense, like storages.length.. what storages.length?

Just post the script.
 
If the code becomes excessively large and you are writing or copy and pasting the same code over and over or the same formula with different values, always create a function to simplify the the code.

Makes it a lot easier to trouble shoot errors, plus it saves space.
 
If the code becomes excessively large and you are writing or copy and pasting the same code over and over or the same formula with different values, always create a function to simplify the the code.

Makes it a lot easier to trouble shoot errors, plus it saves space.

Yeah, but im newbie, im just editing this script, i not made
Im training to made more shorts codes
 
Yeah, but im newbie, im just editing this script, i not made
Im training to made more shorts codes
I am not re-writing this whole script...
I'll just share what I re-wrote
This is your code
Code:
local gold
if (( getPlayerStorageValue(cid, storages.difficult) ) == 2) then
    if ((getPlayerStorageValue(cid, storages.length)) == 2 ) then
        gold = 5000
    elseif ((getPlayerStorageValue(cid, storages.length)) == 3 ) then
        gold = 10000
    elseif ((getPlayerStorageValue(cid, storages.length)) == 4 ) then
        gold = 15000
    end
elseif (( getPlayerStorageValue(cid, storages.difficult) ) == 3) then
    if ((getPlayerStorageValue(cid, storages.length)) == 2 ) then
        gold = 10000
    elseif ((getPlayerStorageValue(cid, storages.length)) == 3 ) then
        gold = 20000
    elseif ((getPlayerStorageValue(cid, storages.length)) == 4 ) then
        gold = 30000
    end
elseif (( getPlayerStorageValue(cid, storages.difficult) ) == 4) then
    if ((getPlayerStorageValue(cid, storages.length)) == 2 ) then
        gold = 15000
    elseif ((getPlayerStorageValue(cid, storages.length)) == 3 ) then
        gold = 30000
    elseif ((getPlayerStorageValue(cid, storages.length)) == 4 ) then
        gold = 45000
    end
end
 
 
local experience, stagesexperience
if (getPlayerLevel(cid) >= 1 and getPlayerLevel(cid) <= 15 ) then
    stagesexperience = 4
elseif (getPlayerLevel(cid) >= 16 and getPlayerLevel(cid) <= 30 ) then
    stagesexperience = 3 -- 4 em 4 lvl
elseif (getPlayerLevel(cid) >= 31 and getPlayerLevel(cid) <= 50 ) then
    stagesexperience = 1.5 -- 2 em 2 lvl
elseif (getPlayerLevel(cid) >= 51 and getPlayerLevel(cid) <= 70 ) then
    stagesexperience = 0.5 -- qse 1 lvl
elseif (getPlayerLevel(cid) >= 71 and getPlayerLevel(cid) <= 99 ) then
    stagesexperience = 0.25
elseif (getPlayerLevel(cid) >= 100 and getPlayerLevel(cid) <= 120 ) then
    stagesexperience = 0.10 -- 25% +/- eu acho
elseif (getPlayerLevel(cid) >= 121 ) then
    stagesexperience = 0.05
end
experience = ((getExperienceForLevel(getPlayerLevel(cid) + 1) - getExperienceForLevel(getPlayerLevel(cid))) / 100) * ((getPlayerStorageValue(cid, storages.length) * 3) * (getPlayerStorageValue(cid, storages.difficult) * 3)) * stagesexperience

local buffagain
if ((getPlayerStorageValue(cid, storages.length)) == 2 ) then
    --buffagain = 20 * 60 * 60
    buffagain = 0.1 * 1 * 60
elseif ((getPlayerStorageValue(cid, storages.length)) == 3 ) then
    --buffagain = 40 * 60 * 60
    buffagain = 0.1 * 1 * 60
elseif ((getPlayerStorageValue(cid, storages.length)) == 4 ) then
    --buffagain = 60 * 60 * 60
    buffagain = 0.1 * 1 * 60
end

This is my code
Code:
local gold, buffagain = 0, 0

local payout = {
    [2] = { payoutLength = { [2] = 5000, [3] = 10000, [4] = 15000 }, buff = 60},
    [3] = { payoutLength = { [2] = 10000, [3] = 20000, [4] = 30000 }, buff = 60},
    [4] = { payoutLength = { [2] = 15000, [3] = 30000, [4] = 45000 }, buff = 60}
}

local difficulty = getPlayerStorageValue(cid, storages.difficult)
local length = getPlayerStorageValue(cid, storages.length)

if payout[difficulty] then
    if payout[difficulty].payoutLength[length] then
        gold = payout[difficulty].payoutLength[length]
        buffagain = payout[difficulty].buff
    end
end

local level = getPlayerLevel(cid)

local t = {
    [1] = {min = 1, max = 15, multiplier = 4},
    [2] = {min = 16, max = 30, multiplier =  3},
    [3] = {min = 31, max = 50, multiplier = 1.5},
    [4] = {min = 51, max = 70, multiplier = 0.5},
    [5] = {min = 71, max = 99, multiplier = 0.25},
    [6] = {min = 100, max = 120, multiplier = 0.10},
    [7] = {min = 121, max = 99999999, multiplier = 0.05}
}

local function isWithinLevelRange(t, level)
    local var = 1
    for i = 1, #t do
        if level >= t[i].min and level <= t[i].max then
            var = t[i].multiplier
        end
    end
    return var
end

local stagesexperience = isWithinLevelRange(t, level)

local function newExperience(level, extraLevel, divideBy, times)
    local expSum = (getExperienceForLevel(level + extraLevel) - getExperienceForLevel(level)) / divideBy
    local storageSum = getPlayerStorageValue(cid, storages.length) * times
    storageSum = storageSum * (getPlayerStorageValue(cid, storages.difficult) * times)
    return expSum * storageSum * stagesexperience
end

local experience = newExperience(level, 1, 100, 3)
 
I am not re-writing this whole script...
I'll just share what I re-wrote
This is your code
Code:
local gold
if (( getPlayerStorageValue(cid, storages.difficult) ) == 2) then
    if ((getPlayerStorageValue(cid, storages.length)) == 2 ) then
        gold = 5000
    elseif ((getPlayerStorageValue(cid, storages.length)) == 3 ) then
        gold = 10000
    elseif ((getPlayerStorageValue(cid, storages.length)) == 4 ) then
        gold = 15000
    end
elseif (( getPlayerStorageValue(cid, storages.difficult) ) == 3) then
    if ((getPlayerStorageValue(cid, storages.length)) == 2 ) then
        gold = 10000
    elseif ((getPlayerStorageValue(cid, storages.length)) == 3 ) then
        gold = 20000
    elseif ((getPlayerStorageValue(cid, storages.length)) == 4 ) then
        gold = 30000
    end
elseif (( getPlayerStorageValue(cid, storages.difficult) ) == 4) then
    if ((getPlayerStorageValue(cid, storages.length)) == 2 ) then
        gold = 15000
    elseif ((getPlayerStorageValue(cid, storages.length)) == 3 ) then
        gold = 30000
    elseif ((getPlayerStorageValue(cid, storages.length)) == 4 ) then
        gold = 45000
    end
end


local experience, stagesexperience
if (getPlayerLevel(cid) >= 1 and getPlayerLevel(cid) <= 15 ) then
    stagesexperience = 4
elseif (getPlayerLevel(cid) >= 16 and getPlayerLevel(cid) <= 30 ) then
    stagesexperience = 3 -- 4 em 4 lvl
elseif (getPlayerLevel(cid) >= 31 and getPlayerLevel(cid) <= 50 ) then
    stagesexperience = 1.5 -- 2 em 2 lvl
elseif (getPlayerLevel(cid) >= 51 and getPlayerLevel(cid) <= 70 ) then
    stagesexperience = 0.5 -- qse 1 lvl
elseif (getPlayerLevel(cid) >= 71 and getPlayerLevel(cid) <= 99 ) then
    stagesexperience = 0.25
elseif (getPlayerLevel(cid) >= 100 and getPlayerLevel(cid) <= 120 ) then
    stagesexperience = 0.10 -- 25% +/- eu acho
elseif (getPlayerLevel(cid) >= 121 ) then
    stagesexperience = 0.05
end
experience = ((getExperienceForLevel(getPlayerLevel(cid) + 1) - getExperienceForLevel(getPlayerLevel(cid))) / 100) * ((getPlayerStorageValue(cid, storages.length) * 3) * (getPlayerStorageValue(cid, storages.difficult) * 3)) * stagesexperience

local buffagain
if ((getPlayerStorageValue(cid, storages.length)) == 2 ) then
    --buffagain = 20 * 60 * 60
    buffagain = 0.1 * 1 * 60
elseif ((getPlayerStorageValue(cid, storages.length)) == 3 ) then
    --buffagain = 40 * 60 * 60
    buffagain = 0.1 * 1 * 60
elseif ((getPlayerStorageValue(cid, storages.length)) == 4 ) then
    --buffagain = 60 * 60 * 60
    buffagain = 0.1 * 1 * 60
end

This is my code
Code:
local gold, buffagain = 0, 0

local payout = {
    [2] = { payoutLength = { [2] = 5000, [3] = 10000, [4] = 15000 }, buff = 60},
    [3] = { payoutLength = { [2] = 10000, [3] = 20000, [4] = 30000 }, buff = 60},
    [4] = { payoutLength = { [2] = 15000, [3] = 30000, [4] = 45000 }, buff = 60}
}

local difficulty = getPlayerStorageValue(cid, storages.difficult)
local length = getPlayerStorageValue(cid, storages.length)

if payout[difficulty] then
    if payout[difficulty].payoutLength[length] then
        gold = payout[difficulty].payoutLength[length]
        buffagain = payout[difficulty].buff
    end
end

local level = getPlayerLevel(cid)

local t = {
    [1] = {min = 1, max = 15, multiplier = 4},
    [2] = {min = 16, max = 30, multiplier =  3},
    [3] = {min = 31, max = 50, multiplier = 1.5},
    [4] = {min = 51, max = 70, multiplier = 0.5},
    [5] = {min = 71, max = 99, multiplier = 0.25},
    [6] = {min = 100, max = 120, multiplier = 0.10},
    [7] = {min = 121, max = 99999999, multiplier = 0.05}
}

local function isWithinLevelRange(t, level)
    local var = 1
    for i = 1, #t do
        if level >= t[i].min and level <= t[i].max then
            var = t[i].multiplier
        end
    end
    return var
end

local stagesexperience = isWithinLevelRange(t, level)

local function newExperience(level, extraLevel, divideBy, times)
    local expSum = (getExperienceForLevel(level + extraLevel) - getExperienceForLevel(level)) / divideBy
    local storageSum = getPlayerStorageValue(cid, storages.length) * times
    storageSum = storageSum * (getPlayerStorageValue(cid, storages.difficult) * times)
    return expSum * storageSum * stagesexperience
end

local experience = newExperience(level, 1, 100, 3)

Arrays are confusing to me...
Im studyng.. Ty, i will try re-write

Did u found why its buging and adding club skills?
 
I thought they were called arrays too once.

Tables are similar to arrays or at the very least an associative array.
Here are a few examples on how you can store and access values in a table.

Assign value by property
Code:
local x = 4
local myTable = {}
myTable.legs = x
Is the same thing as
Code:
local myTable = {
    legs = 4
}
To access the property legs of myTable we would state
Code:
print(myTable.legs)

Assign by index
Code:
local myTable = {}
myTable[1] = {legs = 4}
Is the same thing as
Code:
local myTable = {
    [1] = { legs = 4 }
}
To access the property legs of index 1 we would state
Code:
print(myTable[1].legs)

Assign by string
Code:
local myTable = {}
myTable['x'] = {legs = 4}
Is the same thing as
Code:
local myTable = {
    ['x'] = { legs = 4 }
}
To access the property legs of x we would state
Code:
print(myTable['x'].legs)
 
Last edited:
I thought they were called arrays too once.

Tables are similar to arrays or at the very least an associative array.
Here are a few examples on how you can store and access values in a table.

Assign value by property
Code:
local x = 4
local myTable = {}
myTable.legs = x
Is the same thing as
Code:
local myTable = {
    legs = 4
}
To access the property legs of myTable we would state
Code:
print(myTable.legs)

Assign by index
Code:
local myTable = {}
myTable[1] = {legs = 4}
Is the same thing as
Code:
local myTable = {
    [1] = { legs = 4 }
}
To access the property legs of index 1 we would state
Code:
print(myTable[1].legs)

Assign by string
Code:
local myTable = {}
myTable['x'] = {legs = 4}
Is the same thing as
Code:
local myTable = {
    ['x'] = { legs = 4 }
}
To access the property legs of x we would state
Code:
print(myTable['x'].legs)

So table is like a object in java? I not know so much, but to acess methods need...
table.x

i need practice and search, its nice, ty

did u found wtf this script is adding club skills? i will sleep and see it tomorrow again, cause i dont know why its happen
 
Back
Top