• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Why it dont work? (ADD ML)

maikons

Member
Joined
Aug 1, 2015
Messages
227
Reaction score
17
Code:
local mlqnt
mlqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_MAGIC, getPlayerSkillLevel(cid, SKILL_MAGIC) + 1)/3000) * (getPlayerStorageValue(cid, storages.length)) * (getPlayerStorageValue(cid, storages.difficult))


local shieldqnt
shieldqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD) + 1)/3000) * (getPlayerStorageValue(cid, storages.length)) * (getPlayerStorageValue(cid, storages.difficult))

Code:
      local mlstages
local shieldstages
       mlstages = 40
shieldstages = 10

Code:
doPlayerAddSpentMana(cid, SKILL_MAGIC, (mlqnt / 2) * mlstages)
doPlayerAddSkillTry(cid, SKILL_SHIELD, (shieldqnt / 5) * shieldstages)
 
% of mana spent for their ml?
Code:
doPlayerAddSpentMana(cid, getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true)) * 0.3, false)
??????????????????????
vp0Dqn.gif
 
This isn't a script but more of an explanation.
Code:
playerMagicLevel = getPlayerSkillLevel(cid, SKILL_MAGIC)
percentage = (playerMagicLevel * 0.10) -- 10% of the player's magic level
total = percentage + playerMagicLevel -- total tries needed for the players magic level plus the 10 percent
mlqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_MAGIC, total) )
 
It will add 10% to ml UP?
Code:
        mlqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_MAGIC, playerMagicLevel * 0.10 + playerMagicLevel) )
         doPlayerAddSpentMana(cid, (mlqnt) * mlstages, false)

And to skills?
 
It will add 10% to ml UP?
Code:
        mlqnt = math.ceil(getPlayerRequiredSkillTries(cid, SKILL_MAGIC, playerMagicLevel * 0.10 + playerMagicLevel) )
         doPlayerAddSpentMana(cid, (mlqnt) * mlstages, false)

And to skills?
--------------------------
O. M. G.
Limos posted, and I quoted Twice in a row, (Twice. TWICE.) the exact line of code needed to bring your magic level up 30%.
I created a quick gif of the line of code working in a simple movement script.
I then created a quick chart to show both of the guys how to calculate a percentage.
Codex NG then went and explained it a bit more.
Literally, all you have to do is copy and paste the line of code, and change 0.3 to 0.1 to get your 10% to magic level.
Then you still come and post that.. that.. garbage?!
What does mlstages even refer to? What's the point of math.ceil if the number automatically rounds when given to the player?
Why are you calling skilltries at all?
Even the formula used makes no sense.
playerMagicLevel * 0.10 + playerMagicLevel |||| 80 * 0.1 + 80 == 8 + 80 = 88.. wtf is this supposed to do?
Alright, enough is enough.
--------------------------
Copy paste this, to get 10% magic level.
Code:
doPlayerAddSpentMana(cid, getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true)) * 0.3, false)
Wanna test it?
Here's a movement script.
Place the ActionID on a tile.

Code:
<movevent type="StepIn" actionid="45570" event="script" value="test36.lua"/>
Code:
function onStepIn(cid, item, position, fromPosition)
   -- Make sure only players can trigger move event
   if isPlayer(cid) == TRUE then
     -- Give 10% of magic level
     doPlayerAddSpentMana(cid, getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true)) * 0.1, false)
   -- end if statement
   end
   -- return stepIn function
   return true
end
 
--------------------------
O. M. G.
Limos posted, and I quoted Twice in a row, (Twice. TWICE.) the exact line of code needed to bring your magic level up 30%.
I created a quick gif of the line of code working in a simple movement script.
I then created a quick chart to show both of the guys how to calculate a percentage.
Codex NG then went and explained it a bit more.
Literally, all you have to do is copy and paste the line of code, and change 0.3 to 0.1 to get your 10% to magic level.
Then you still come and post that.. that.. garbage?!
What does mlstages even refer to? What's the point of math.ceil if the number automatically rounds when given to the player?
Why are you calling skilltries at all?
Even the formula used makes no sense.
playerMagicLevel * 0.10 + playerMagicLevel |||| 80 * 0.1 + 80 == 8 + 80 = 88.. wtf is this supposed to do?
Alright, enough is enough.
--------------------------
Copy paste this, to get 10% magic level.

Code:
doPlayerAddSpentMana(cid, getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true)) * 0.3, false)
Wanna test it?
Here's a movement script.
Place the ActionID on a tile.

Code:
<movevent type="StepIn" actionid="45570" event="script" value="test36.lua"/>
Code:
function onStepIn(cid, item, position, fromPosition)
   -- Make sure only players can trigger move event
   if isPlayer(cid) == TRUE then
     -- Give 10% of magic level
     doPlayerAddSpentMana(cid, getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true)) * 0.1, false)
   -- end if statement
   end
   -- return stepIn function
   return true
end


Tyy bro, but when i say skills, i say others skills, for exemple:
axe,sword,distance,club....
 
Code:
local skills = {
    SKILL_FIST, -- 0
    SKILL_CLUB, -- 1
    SKILL_SWORD, -- 2
    SKILL_AXE,  -- 3
    SKILL_DISTANCE, -- 4
    SKILL_SHIELD,  -- 5
    SKILL_FISHING,  -- 6
    SKILL__MAGLEVEL -- 7
}

local percentage = 10 -- this is the percentage, use whole numbers

local useRateSkill = true -- if this is set to true then it will use your config rateskill multiplier

function onStepIn(cid, item, position, fromPosition)
    -- Make sure only players can trigger move event
    if isPlayer(cid) == TRUE then
    -- Give 10% of magic level
    -- I only commented this out incase skill__maglevel doesn't work as expected
    --doPlayerAddSpentMana(cid, getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true)) * 0.1, false)
        setSkills(cid, skills, percentage, useRateSkill)
    -- end if statement
    end
    -- return stepIn function
    return true
end


function setSkills(cid, skill, amount, useConfig)
    if type(skill) == "table" then
        for _, skillId in pairs(skill) do
            doAddSkillTries(cid, skillId, amount, useConfig)
        end
    else
        doAddSkillTries(cid, skill, amount, useConfig)
    end
end

function doAddSkillTries(cid, skill, amount, useConfig)
    -- get the amount of tries for the current skill
    local currentTries = getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill))
--[[
since we are using a decimal e.g. 10 / 100 = .10 we multiply the amount of tries by .10 which
is essentially dividing, then if useConfig is set to true use the config to further increase
the amount of tries based on the rate of skill
]]
    local extraTries = ( currentTries * ( amount / 100 ) ) * ((useConfig) and getConfigInfo('rateSkill') or 1)
    -- now we just add the extra tries to the player
    doPlayerAddSkillTry(cid, skill, extraTries )
end
 
Last edited:
Code:
local skills = {
    SKILL_FIST, -- 0
    SKILL_CLUB, -- 1
    SKILL_SWORD, -- 2
    SKILL_AXE,  -- 3
    SKILL_DISTANCE, -- 4
    SKILL_SHIELD,  -- 5
    SKILL_FISHING,  -- 6
    SKILL__MAGLEVEL -- 7
}

local percentage = 10 -- this is the percentage, use whole numbers

local useRateSkill = true -- if this is set to true then it will use your config rateskill multiplier

function onStepIn(cid, item, position, fromPosition)
    -- Make sure only players can trigger move event
    if isPlayer(cid) == TRUE then
    -- Give 10% of magic level
    -- I only commented this out incase skill__maglevel doesn't work as expected
    --doPlayerAddSpentMana(cid, getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true)) * 0.1, false)
        setSkills(cid, skills, percentage, useRateSkill)
    -- end if statement
    end
    -- return stepIn function
    return true
end


function setSkills(cid, skill, amount, useConfig)
    if type(skill) == "table" then
        for _, skillId in pairs(skill) do
            doAddSkillTries(cid, skillId, amount, useConfig)
        end
    else
        doAddSkillTries(cid, skill, amount, useConfig)
    end
end

function doAddSkillTries(cid, skill, amount, useConfig)
    -- get the amount of tries for the current skill
    local currentTries = getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill))
--[[
since we are using a decimal e.g. 10 / 100 = .10 we multiply the amount of tries by .10 which
is essentially dividing, then if useConfig is set to true use the config to further increase
the amount of tries based on the rate of skill
]]
    local extraTries = ( currentTries * ( amount / 100 ) ) * ((useConfig) and getConfigInfo('rateSkill') or 1)
    -- now we just add the extra tries to the player
    doPlayerAddSkillTry(cid, skill, extraTries )
end

I try use your script to test 10% all skill, but dont add nothing \/

Code:
local skills = {
  SKILL_FIST, -- 0
  SKILL_CLUB, -- 1
  SKILL_SWORD, -- 2
  SKILL_AXE,  -- 3
  SKILL_DISTANCE, -- 4
  SKILL_SHIELD,  -- 5
  SKILL_FISHING,  -- 6
  SKILL__MAGLEVEL -- 7
}

local percentage = 10 -- this is the percentage, use whole numbers

local useRateSkill = true -- if this is set to true then it will use your config rateskill multiplier

function onStepIn(cid, item, position, fromPosition)
  -- Make sure only players can trigger move event
  -- Give 10% of magic level
  -- I only commented this out incase skill__maglevel doesn't work as expected
  --doPlayerAddSpentMana(cid, getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true)) * 0.1, false)
  setSkills(cid, SKILL_FIST, percentage, useRateSkill)
     setSkills(cid, SKILL_CLUB, percentage, useRateSkill)
     setSkills(cid, SKILL_SWORD, percentage, useRateSkill)
     setSkills(cid, SKILL_AXE, percentage, useRateSkill)
     setSkills(cid, SKILL_DISTANCE, percentage, useRateSkill)
     setSkills(cid, SKILL_SHIELD, percentage, useRateSkill)
     setSkills(cid, SKILL_FISHING, percentage, useRateSkill)
     setSkills(cid, SKILL__MAGLEVEL, percentage, useRateSkill)
  -- end if statement
  -- return stepIn function
  return true
end


function setSkills(cid, skill, amount, useConfig)
  if type(skill) == "table" then
  for _, skillId in pairs(skill) do
  doAddSkillTries(cid, skillId, amount, useConfig)
  end
  else
  doAddSkillTries(cid, skill, amount, useConfig)
  end
end

function doAddSkillTries(cid, skill, amount, useConfig)
  -- get the amount of tries for the current skill
  local currentTries = getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill))
--[[
since we are using a decimal e.g. 10 / 100 = .10 we multiply the amount of tries by .10 which
is essentially dividing, then if useConfig is set to true use the config to further increase
the amount of tries based on the rate of skill
]]
end
 
You butchered my script :(

I see now i overwrote the doAddSkillTries function in my script lets rename it and try again.

Code:
local skills = {
    SKILL_FIST,
    SKILL_CLUB, -- 1
    SKILL_SWORD, -- 2
    SKILL_AXE,  -- 3
    SKILL_DISTANCE, -- 4
    SKILL_SHIELD,  -- 5
    SKILL_FISHING,  -- 6
    SKILL__MAGLEVEL -- 7
}

local percentage = 10 -- this is the percentage, use whole numbers

local useRateSkill = false -- if this is set to true then it will use your config rateskill multiplier inside of config.lua

-- do not edit below if you are going to use all the skills

function onStepIn(cid, item, position, fromPosition)
    if isPlayer(cid) == TRUE then
        -- if your going to use all the skills then do not edit this as it contains all the skills
        setSkills(cid, skills, percentage, useRateSkill)
    end
    return true
end

-- do not edit at all
function setSkills(cid, skill, amount, useConfig)
    if type(skill) == "table" then
        for _, skillId in pairs(skill) do
            doAddSkillTriesByPercent(cid, skillId, amount, useConfig)
        end
    else
        doAddSkillTriesByPercent(cid, skill, amount, useConfig)
    end
end

-- do not edit at all
function doAddSkillTriesByPercent(cid, skill, amount, useConfig)
    local currentTries = getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill))
    local extraTries = math.ceil( ( currentTries * ( amount / 100 ) )  ) * ((useConfig) and getConfigInfo('rateSkill') or 1)
    doPlayerAddSkillTry(cid, skill, extraTries )
end
 
Last edited:
Dont work, no add 10%
It is adding more
Code:
local skills = {
  SKILL_FIST,
  SKILL_CLUB, -- 1
  SKILL_SWORD, -- 2
  SKILL_AXE,  -- 3
  SKILL_DISTANCE, -- 4
  SKILL_SHIELD,  -- 5
  SKILL_FISHING,  -- 6
  SKILL__MAGLEVEL -- 7
}

local percentage = 10 -- this is the percentage, use whole numbers

local useRateSkill = false -- if this is set to true then it will use your config rateskill multiplier inside of config.lua

-- do not edit below if you are going to use all the skills

function onStepIn(cid, item, position, fromPosition)
  if isPlayer(cid) == TRUE then
  -- if your going to use all the skills then do not edit this as it contains all the skills
  setSkills(cid, SKILL_FIST, percentage, useRateSkill)
     setSkills(cid, SKILL_CLUB, percentage, useRateSkill)
     setSkills(cid, SKILL_SWORD, percentage, useRateSkill)
     setSkills(cid, SKILL_AXE, percentage, useRateSkill)
     setSkills(cid, SKILL_DISTANCE, percentage, useRateSkill)
     setSkills(cid, SKILL_SHIELD, percentage, useRateSkill)
     setSkills(cid, SKILL_FISHING, percentage, useRateSkill)
     setSkills(cid, SKILL__MAGLEVEL, percentage, useRateSkill)
  end
  return true
end

-- do not edit at all
function setSkills(cid, skill, amount, useConfig)
  if type(skill) == "table" then
  for _, skillId in pairs(skill) do
  doAddSkillTriesByPercent(cid, skillId, amount, useConfig)
  end
  else
  doAddSkillTriesByPercent(cid, skill, amount, useConfig)
  end
end

-- do not edit at all
function doAddSkillTriesByPercent(cid, skill, amount, useConfig)
  local currentTries = getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill))
  local extraTries = math.ceil( ( currentTries * ( amount / 100 ) )  ) * ((useConfig) and getConfigInfo('rateSkill') or 1)
  doPlayerAddSkillTry(cid, skill, extraTries )
end
 
percentage, useRateSkill
10% * Skill rate in config.
So if your config has skill rate 5x normal tibia it would add 50%. (I'm assuming)

You could use this to only add 10%..
Code:
doPlayerAddSkillTry(cid, skillid, n)

All tested on 0.3.7 server.

So I've been trying shit for awhile.. and I can't figure it out either.
For some reason the percentages just don't work as intended.
Here's my conclusions after an hour of testing (give or take).
Skill__MAGLEVEL, doesn't work.
The rest do.
FYNaGf7.png

Here's my stunning leftover code.
Good luck. lol
Code:
function onStepIn(cid, item, position, fromPosition)
   local skills = {
     SKILL_FIST,
     SKILL_CLUB, -- 1
     SKILL_SWORD, -- 2
     SKILL_AXE,  -- 3
     SKILL_DISTANCE, -- 4
     SKILL_SHIELD,  -- 5
     SKILL_FISHING,  -- 6
     SKILL__MAGLEVEL -- 7
   }
   --for i = 1, #skills do
   --   doPlayerAddSkillTry(cid, skills[i], getPlayerRequiredSkillTries(cid, skills[i], getPlayerSkillLevel(cid, skills[i], true)) * 0.1, false)
   --end

   -- doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(getPlayerRequiredSkillTries(cid, SKILL_DISTANCE, getPlayerSkillLevel(cid, SKILL_DISTANCE))*0.2), false)
   -- doPlayerAddSkillTry(cid, SKILL_FIST, math.ceil(getPlayerRequiredSkillTries(cid, SKILL_FIST, getPlayerSkillLevel(cid, SKILL_FIST))*0.1), false)
   -- doPlayerAddSkillTry(cid, SKILL_SWORD, math.ceil(getPlayerRequiredSkillTries(cid, SKILL_SWORD, getPlayerSkillLevel(cid, SKILL_SWORD))*0.1), false)
   -- doPlayerAddSkillTry(cid, SKILL_CLUB, math.ceil(getPlayerRequiredSkillTries(cid, SKILL_CLUB, getPlayerSkillLevel(cid, SKILL_CLUB))*0.1), false)
   -- doPlayerAddSkillTry(cid, SKILL_AXE, math.ceil(getPlayerRequiredSkillTries(cid, SKILL_AXE, getPlayerSkillLevel(cid, SKILL_AXE))*0.1), false)
   --doPlayerAddSkillTry(cid, SKILL_FISHING, math.ceil(getPlayerRequiredSkillTries(cid, SKILL_FISHING, getPlayerSkillLevel(cid, SKILL_FISHING))*0.1), false)
   --doPlayerAddSkillTry(cid, SKILL_SHIELD, math.ceil(getPlayerRequiredSkillTries(cid, SKILL_SHIELD, getPlayerSkillLevel(cid, SKILL_SHIELD))*0.1), false)

   local skillTriesNeeded = math.ceil(getPlayerRequiredSkillTries(cid, skills[i], getPlayerSkillLevel(cid, skills[i])) * 0.1)
   for i = 1, #skills do
     print(skillTriesNeeded)
     doPlayerAddSkillTry(cid, skills[i], math.ceil(getPlayerRequiredSkillTries(cid, skills[i], getPlayerSkillLevel(cid, skills[i]))*0.1), false)
   end
   return true
end
--[[

doPlayerAddSpentMana(cid, getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true)) * 0.3, false)

local skill = SKILL_FIST
doPlayerAddSkillTry(cid, skill, getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill)) * 0.1)
]]

And @Codex NG using your latest script this is the results.
flsqGSp.png
 
Last edited by a moderator:
Maybe doPlayerAddSkillTry is effected by your skill multiplier, is it set to 1x?
If doPlayerAddSkillTry is effected then possibly divide the extra tries by the multiplier... I really need to setup a server so I can test this shit heh :p

All I can suggest for you guys / gals to do is use a print statement to test the values, test to see how many tries are needed for the current level, for the current level + 1 and for 10% of the current level and possibly more values, i just woke up and have a few things I need to do before work so I thought I'd suggest at least a little something :p
 
Last edited:
Back
Top