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

RevScripts AccountStorage - Skills add

LeOnArd0

Member
Joined
Jan 24, 2010
Messages
76
Reaction score
14
Hello guys!

I need help with an revscript for TFS 1.5, @Nekiro downgrade.

The idea is to put together a script that follows this line of reasoning:

1- When logging in, check if the player has account_storage X, if not, add it but with a value of 0.
I put this:
Code:
if Player.getAccountStorageValue(1000) == -1 then
    Player.setAccountStorageValue(1000, 0)
end

But i receive this error:
Code:
2023-04-20_16-21-25.023561 Lua Script Error: [CreatureScript Interface]
2023-04-20_16-21-25.023649 data/creaturescripts/scripts/login.lua:onLogin
2023-04-20_16-21-25.023717 data/creaturescripts/scripts/login.lua:42: attempt to call field 'getAccountStorageValue' (a nil value)
2023-04-20_16-21-25.023763 stack traceback:
2023-04-20_16-21-25.023802      [C]: in function 'getAccountStorageValue'
2023-04-20_16-21-25.023860      data/creaturescripts/scripts/login.lua:42: in function <data/creaturescripts/scripts/login.lua:1>

2- After using an item x, check the account_storage (account_id, key, value) and add the value (ex: it was 0 goes to 1).
Code:
if Player.getAccountStorageValue(1000) == 0 then
        player:setStorageValue(1000, 1)

3-After that, a creaturescripts checks if the player has account_storage with value 1 and adds 1 of melee skill to all characters of the account if he is a knight, 1 of ml if he is a druid/sorcerer, 1 of distance if he is a paladin, considering this table:

Account Storage - 1000, 1 - +1 skills
Account Storage - 1000, 3 - +1 skills
Account Storage - 1000, 5 - +1 skills
Account Storage - 1000, 8 - +1 skills
Account Storage - 1000, 12 - +1 skills
Account Storage - 1000, 18 - +1 skills
Account Storage - 1000, 24 - +1 skills
Account Storage - 1000, 30 - +1 skills
Account Storage - 1000, 36 - +1 skills
Account Storage - 1000, 42 - +1 skills

Adding the skill to each storage, when he has the account storage at 42, he will have +10 skill.

I tested this script and it worked, but it adds 1 skill per player key, today it doesn't respect the table above, I would like to adapt it and consider account_storage not player storage.
Code:
function onLogin(player)
    local skillpercent = player:getStorageValue(1000)
    local melee = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
          melee:setParameter(CONDITION_PARAM_SUBID, 1)
          melee:setParameter(CONDITION_PARAM_TICKS, -1)
          melee:setParameter(CONDITION_PARAM_SKILL_MELEE, skillpercent)
          melee:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

    local distance = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
          distance:setParameter(CONDITION_PARAM_SUBID, 1)
          distance:setParameter(CONDITION_PARAM_TICKS, -1)
          distance:setParameter(CONDITION_PARAM_SKILL_DISTANCE, skillpercent)
          distance:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
 
    local magic = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
          magic:setParameter(CONDITION_PARAM_SUBID, 1)
          magic:setParameter(CONDITION_PARAM_TICKS, -1)
          magic:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, skillpercent)
          magic:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
       
        if player:getStorageValue(skillpercent) then
            if player:isKnight() then
               player:addCondition(melee)
            elseif player:isPaladin() then
               player:addCondition(distance)
            elseif player:isDruid() or player:isSorcerer() then
               player:addCondition(magic)
            end
        end
    return true
end

I use this function in lib/core/player.lua
Lua:
function Player.getAccountStorageValue(self, key)
    if type(key) ~= "number" then
        return false
    end
    local query = db.storeQuery("SELECT `value` FROM `account_storage` WHERE `account_id` = ".. self:getAccountId() .." AND `key` = ".. key)
    if not query then
        return false
    end

    local value = result.getDataInt(query, "value")
    result.free(query)
    return value
end

function Player.setAccountStorageValue(self, key, value)
    if type(key) ~= "number" then
        return false
    end
    local query = ""
    if self:getAccountStorageValue(key) then
        query = ("UPDATE `account_storage` SET `value` = %d WHERE `account_id` = %d AND `key` = %d"):format(value, self:getAccountId(), key)
    else
        query = ("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (%d, %d, %d)"):format(self:getAccountId(), key, value)
    end
    return db.query(query)
end

Somebody to give me a light?

@Xikini, if you have a little time xD

Tks
Leo
 
Solution
Test both and tell me which one works:
Lua:
function onLogin(player)
    local accountId = player:getAccountId()
    print("AccocuntId: " .. accountId)
    if Game.getAccountStorageValue(accountId, 37856) == -1 then
        Game.setAccountStorageValue(accountId, 37856, 0)
        Game.saveAccountStorageValues()
    end
    return true
end

Lua:
function onLogin(player)
    local resultId = db.query(string.format("SELECT `account_id` FROM `players` WHERE `id` = %d", player:getGuid()))
    if not resultId then
        error("Failed to get account id for player " .. player:getName())
    end

    local accountId = result.getNumber(resultId, "account_id")
    result.free(resultId)
    print("AccocuntId: " .. accountId)
    if...
Lua:
player:getAccountStorageValue(1000)

For the script, on line 2, you are setting the value of storage of 1000 to the variable "skillpercent"

On line 21, you are then checking getting the value of the key, of "skillpercent", which makes no sense, and is why its not working.

Just change line 21 to:
Lua:
if skillpercent > 0 then
 
Lua:
player:getAccountStorageValue(1000)

For the script, on line 2, you are setting the value of storage of 1000 to the variable "skillpercent"

On line 21, you are then checking getting the value of the key, of "skillpercent", which makes no sense, and is why its not working.

Just change line 21 to:
Lua:
if skillpercent > 0 then

Hum, i change, but i receive this error:

2023-04-20_16-46-23.733735 Lua Script Error: [CreatureScript Interface]
2023-04-20_16-46-23.733784 data/creaturescripts/scripts/pointsskill.lua: onLogin
2023-04-20_16-46-23.733838 data/creaturescripts/scripts/pointsskill.lua:2: attempt to call method 'getAccountStorageValue' (a nil value)
2023-04-20_16-46-23.733896 stack traceback:
2023-04-20_16-46-23.733951 [C]: in function 'getAccountStorageValue'
2023-04-20_16-46-23.733996 data/creaturescripts/scripts/pointsskill.lua:2: in function <data/creaturescripts/scripts/loyalty.lua:1>

I believe this is because I am not defining a key (1000, 1), but as I said, I would like these skills to be delivered in table format. So if I set it to 1, it wouldn't make a lot of sense, would it?
 
Hello guys!

I need help with an revscript for TFS 1.5, @Nekiro downgrade.

The idea is to put together a script that follows this line of reasoning:

1- When logging in, check if the player has account_storage X, if not, add it but with a value of 0.
I put this:
Code:
if Player.getAccountStorageValue(1000) == -1 then
    Player.setAccountStorageValue(1000, 0)
end

But i receive this error:
Code:
2023-04-20_16-21-25.023561 Lua Script Error: [CreatureScript Interface]
2023-04-20_16-21-25.023649 data/creaturescripts/scripts/login.lua:onLogin
2023-04-20_16-21-25.023717 data/creaturescripts/scripts/login.lua:42: attempt to call field 'getAccountStorageValue' (a nil value)
2023-04-20_16-21-25.023763 stack traceback:
2023-04-20_16-21-25.023802      [C]: in function 'getAccountStorageValue'
2023-04-20_16-21-25.023860      data/creaturescripts/scripts/login.lua:42: in function <data/creaturescripts/scripts/login.lua:1>

2- After using an item x, check the account_storage (account_id, key, value) and add the value (ex: it was 0 goes to 1).
Code:
if Player.getAccountStorageValue(1000) == 0 then
        player:setStorageValue(1000, 1)

3-After that, a creaturescripts checks if the player has account_storage with value 1 and adds 1 of melee skill to all characters of the account if he is a knight, 1 of ml if he is a druid/sorcerer, 1 of distance if he is a paladin, considering this table:

Account Storage - 1000, 1 - +1 skills
Account Storage - 1000, 3 - +1 skills
Account Storage - 1000, 5 - +1 skills
Account Storage - 1000, 8 - +1 skills
Account Storage - 1000, 12 - +1 skills
Account Storage - 1000, 18 - +1 skills
Account Storage - 1000, 24 - +1 skills
Account Storage - 1000, 30 - +1 skills
Account Storage - 1000, 36 - +1 skills
Account Storage - 1000, 42 - +1 skills

Adding the skill to each storage, when he has the account storage at 42, he will have +10 skill.

I tested this script and it worked, but it adds 1 skill per player key, today it doesn't respect the table above, I would like to adapt it and consider account_storage not player storage.
Code:
function onLogin(player)
    local skillpercent = player:getStorageValue(1000)
    local melee = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
          melee:setParameter(CONDITION_PARAM_SUBID, 1)
          melee:setParameter(CONDITION_PARAM_TICKS, -1)
          melee:setParameter(CONDITION_PARAM_SKILL_MELEE, skillpercent)
          melee:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

    local distance = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
          distance:setParameter(CONDITION_PARAM_SUBID, 1)
          distance:setParameter(CONDITION_PARAM_TICKS, -1)
          distance:setParameter(CONDITION_PARAM_SKILL_DISTANCE, skillpercent)
          distance:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
 
    local magic = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
          magic:setParameter(CONDITION_PARAM_SUBID, 1)
          magic:setParameter(CONDITION_PARAM_TICKS, -1)
          magic:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, skillpercent)
          magic:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
      
        if player:getStorageValue(skillpercent) then
            if player:isKnight() then
               player:addCondition(melee)
            elseif player:isPaladin() then
               player:addCondition(distance)
            elseif player:isDruid() or player:isSorcerer() then
               player:addCondition(magic)
            end
        end
    return true
end

I use this function in lib/core/player.lua
Lua:
function Player.getAccountStorageValue(self, key)
    if type(key) ~= "number" then
        return false
    end
    local query = db.storeQuery("SELECT `value` FROM `account_storage` WHERE `account_id` = ".. self:getAccountId() .." AND `key` = ".. key)
    if not query then
        return false
    end

    local value = result.getDataInt(query, "value")
    result.free(query)
    return value
end

function Player.setAccountStorageValue(self, key, value)
    if type(key) ~= "number" then
        return false
    end
    local query = ""
    if self:getAccountStorageValue(key) then
        query = ("UPDATE `account_storage` SET `value` = %d WHERE `account_id` = %d AND `key` = %d"):format(value, self:getAccountId(), key)
    else
        query = ("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (%d, %d, %d)"):format(self:getAccountId(), key, value)
    end
    return db.query(query)
end

Somebody to give me a light?

@Xikini, if you have a little time xD

Tks
Leo
If you are using TFS Downgrades or official TFS, these methods already exist.
Lua:
-- GET
local value = Game.getAccountStorageValue(accountId, 1000)

-- SET
Game.setAccountStorageValue(accountId, 1000, 1)

-- Force save
Game.saveAccountStorageValues()

in fact if you use TFS master you can even use this method which is shorter and easier to remember:
Lua:
local value = player.accountStorage[1000]
player.accountStorage[1000] = 1
 
If you are using TFS Downgrades or official TFS, these methods already exist.
Lua:
-- GET
local value = Game.getAccountStorageValue(accountId, 1000)

-- SET
Game.setAccountStorageValue(accountId, 1000, 1)

-- Force save
Game.saveAccountStorageValues()

in fact if you use TFS master you can even use this method which is shorter and easier to remember:
Lua:
local value = player.accountStorage[1000]
player.accountStorage[1000] = 1

Hello @Sarah Wesker, thanks for you response.


Lua:
function onLogin(player)

if Game.getAccountStorageValue(accountId, 37856) == -1 then
    Game.setAccountStorageValue(accountId, 37856, 0)
    Game.saveAccountStorageValues()
end


    return true
end

I tried to do it that way in the login.lua, it didn't return any errors, but it didn't add the storage to the database. :(
 
Hello @Sarah Wesker, thanks for you response.


Lua:
function onLogin(player)

if Game.getAccountStorageValue(accountId, 37856) == -1 then
    Game.setAccountStorageValue(accountId, 37856, 0)
    Game.saveAccountStorageValues()
end


    return true
end

I tried to do it that way in the login.lua, it didn't return any errors, but it didn't add the storage to the database. :(
accountId is currently nil, since you haven't set it as anything.

Surprised it's not erroring lol

use

Lua:
local accountId = player:getAccountId()
 
accountId is currently nil, since you haven't set it as anything.

Surprised it's not erroring lol

use

Lua:
local accountId = player:getAccountId()

Now return this error:

Lua:
2023-04-21_18-33-40.819488 [Error - mysql_real_query] Query: INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES(0, 37856, 0)
2023-04-21_18-33-40.819675 Message: Cannot add or update a child row: a foreign key constraint fails (`database`.`account_storage`, CONSTRAINT `account_storage_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE CASCADE)
 
This smells like a data issue in your database. The first thing I noticed was that you're using accountId = 0.
The error clearly states that it couldn't add or update a value because the reference to the accountId failed.
What you can do is completely empty your table, but don't forget to first shutdown the server.

When you have the table clean, reopen the server and try again, although maybe you should change your account id to 1, and not use 0 in case it is.
Everything should works fine.
 
This smells like a data issue in your database. The first thing I noticed was that you're using accountId = 0.
The error clearly states that it couldn't add or update a value because the reference to the accountId failed.
What you can do is completely empty your table, but don't forget to first shutdown the server.

When you have the table clean, reopen the server and try again, although maybe you should change your account id to 1, and not use 0 in case it is.
Everything should works fine.

I did what you recommended, delete the base and I cried again. It worked, the only problem is that it is returning the account_id as 0. Do you know what could be going on?
799b3fee1df9b8d70d631e5883eb4f84.png
 
If it no longer throws the error, don't worry about the 0.
Probably your account has ID 0 because it was placed manually from the database, or the website you use creates the accounts counting from 0.
 
If it no longer throws the error, don't worry about the 0.
Probably your account has ID 0 because it was placed manually from the database, or the website you use creates the accounts counting from 0.

Yes, the error didn't appear, it entered it in the database, but whatever account I enter, it didn't update the storage, since it recognizes all of them as ID 0, so it kind of won't work, right? Just so you understand, these are the accounts created by MYAAC, ID 1, 2, 4, 5. Whichever one I enter, it is not added to the bank as it considers it to be ID 0. What solution can I take?

---------------

It worked!!!

There was a file conflict and I was messing with the wrong file. 😰

Now I just needed some help with the question of skills for the account according to the table. Could you help me? @Sarah Wesker
 
Last edited:
Test both and tell me which one works:
Lua:
function onLogin(player)
    local accountId = player:getAccountId()
    print("AccocuntId: " .. accountId)
    if Game.getAccountStorageValue(accountId, 37856) == -1 then
        Game.setAccountStorageValue(accountId, 37856, 0)
        Game.saveAccountStorageValues()
    end
    return true
end

Lua:
function onLogin(player)
    local resultId = db.query(string.format("SELECT `account_id` FROM `players` WHERE `id` = %d", player:getGuid()))
    if not resultId then
        error("Failed to get account id for player " .. player:getName())
    end

    local accountId = result.getNumber(resultId, "account_id")
    result.free(resultId)
    print("AccocuntId: " .. accountId)
    if Game.getAccountStorageValue(accountId, 37856) == -1 then
        Game.setAccountStorageValue(accountId, 37856, 0)
        Game.saveAccountStorageValues()
    end
    return true
end

Remember to check the console and tell me what messages you get if there are any.

If you want to increment in intervals somewhere else:
Lua:
local accountId = player:getAccountId()
local skillpercent = Game.getAccountStorageValue(accountId, 37856)
Game.setAccountStorageValue(accountId, 37856, skillpercent + 1)
 
Solution
Test both and tell me which one works:
Lua:
function onLogin(player)
    local accountId = player:getAccountId()
    print("AccocuntId: " .. accountId)
    if Game.getAccountStorageValue(accountId, 37856) == -1 then
        Game.setAccountStorageValue(accountId, 37856, 0)
        Game.saveAccountStorageValues()
    end
    return true
end

Lua:
function onLogin(player)
    local resultId = db.query(string.format("SELECT `account_id` FROM `players` WHERE `id` = %d", player:getGuid()))
    if not resultId then
        error("Failed to get account id for player " .. player:getName())
    end

    local accountId = result.getNumber(resultId, "account_id")
    result.free(resultId)
    print("AccocuntId: " .. accountId)
    if Game.getAccountStorageValue(accountId, 37856) == -1 then
        Game.setAccountStorageValue(accountId, 37856, 0)
        Game.saveAccountStorageValues()
    end
    return true
end

Remember to check the console and tell me what messages you get if there are any.

The first method worked, tksss ❤️

I needed to adapt this script to add the skill as shown in the table below. Today it adds 1 skill to each base value, you know? Example: If the base is 37856, 3 it adds 3 skills to the account but in fact I would like it to add 1.

Lua:
function onLogin(player)
    local accountId = player:getAccountId()
    local skillpercent = Game.getAccountStorageValue(accountId, 37856)
    local melee = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
          melee:setParameter(CONDITION_PARAM_SUBID, 1)
          melee:setParameter(CONDITION_PARAM_TICKS, -1)
          melee:setParameter(CONDITION_PARAM_SKILL_MELEE, skillpercent)
          melee:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

    local distance = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
          distance:setParameter(CONDITION_PARAM_SUBID, 1)
          distance:setParameter(CONDITION_PARAM_TICKS, -1)
          distance:setParameter(CONDITION_PARAM_SKILL_DISTANCE, skillpercent)
          distance:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
 
    local magic = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
          magic:setParameter(CONDITION_PARAM_SUBID, 1)
          magic:setParameter(CONDITION_PARAM_TICKS, -1)
          magic:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, skillpercent)
          magic:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
      
        if skillpercent > 0 then
            if player:isKnight() then
               player:addCondition(melee)
            elseif player:isPaladin() then
               player:addCondition(distance)
            elseif player:isDruid() or player:isSorcerer() then
               player:addCondition(magic)
            end
        end
    return true
end

Account Storage - key: 37856, value: 1 = +1 skills
Account Storage - key: 37856, value: 3 = +1 skills
Account Storage - key: 37856, value: 5 = +1 skills
Account Storage - key: 37856, value: 8 = +1 skills
Account Storage - key: 37856, value: 12 = +1 skills
Account Storage - key: 37856, value: 18 = +1 skills
Account Storage - key: 37856, value: 24 = +1 skills
Account Storage - key: 37856, value: 30 = +1 skills
Account Storage - key: 37856, value: 36 = +1 skills
Account Storage - key: 37856, value: 42 = +1 skills

Have all, total skills: +10.
 
The first method worked, tksss ❤️

I needed to adapt this script to add the skill as shown in the table below. Today it adds 1 skill to each base value, you know? Example: If the base is 37856, 3 it adds 3 skills to the account but in fact I would like it to add 1.

Lua:
function onLogin(player)
    local accountId = player:getAccountId()
    local skillpercent = Game.getAccountStorageValue(accountId, 37856)
    local melee = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
          melee:setParameter(CONDITION_PARAM_SUBID, 1)
          melee:setParameter(CONDITION_PARAM_TICKS, -1)
          melee:setParameter(CONDITION_PARAM_SKILL_MELEE, skillpercent)
          melee:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

    local distance = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
          distance:setParameter(CONDITION_PARAM_SUBID, 1)
          distance:setParameter(CONDITION_PARAM_TICKS, -1)
          distance:setParameter(CONDITION_PARAM_SKILL_DISTANCE, skillpercent)
          distance:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
 
    local magic = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
          magic:setParameter(CONDITION_PARAM_SUBID, 1)
          magic:setParameter(CONDITION_PARAM_TICKS, -1)
          magic:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, skillpercent)
          magic:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
     
        if skillpercent > 0 then
            if player:isKnight() then
               player:addCondition(melee)
            elseif player:isPaladin() then
               player:addCondition(distance)
            elseif player:isDruid() or player:isSorcerer() then
               player:addCondition(magic)
            end
        end
    return true
end



Have all, total skills: +10.

Lua:
local melee = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
    melee:setParameter(CONDITION_PARAM_SUBID, 1)
    melee:setParameter(CONDITION_PARAM_TICKS, -1)
    melee:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local distance = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
    distance:setParameter(CONDITION_PARAM_SUBID, 1)
    distance:setParameter(CONDITION_PARAM_TICKS, -1)
    distance:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local magic = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
    magic:setParameter(CONDITION_PARAM_SUBID, 1)
    magic:setParameter(CONDITION_PARAM_TICKS, -1)
    magic:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
    
local buffBreakpoints = {1, 3, 5, 8, 12, 18, 24, 30, 36, 42}

function onLogin(player)
    local accountId = player:getAccountId()
    local skillpercent = Game.getAccountStorageValue(accountId, 37856)

    if skillpercent < 1 then
        return true
    end
    
    local buffPercent = 0
    for i = 1, #buffBreakpoints do
        if buffBreakpoints[i] <= skillpercent then
            buffPercent = buffPercent + 1
        end
    end
    
    if player:isKnight() then
        melee:setParameter(CONDITION_PARAM_SKILL_MELEE, buffPercent)
        player:addCondition(melee)
        
    elseif player:isPaladin() then
        distance:setParameter(CONDITION_PARAM_SKILL_DISTANCE, buffPercent)
        player:addCondition(distance)
        
    elseif player:isDruid() or player:isSorcerer() then
        magic:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, buffPercent)
        player:addCondition(magic)
        
    end
    return true
end
 
Lua:
local melee = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
    melee:setParameter(CONDITION_PARAM_SUBID, 1)
    melee:setParameter(CONDITION_PARAM_TICKS, -1)
    melee:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local distance = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
    distance:setParameter(CONDITION_PARAM_SUBID, 1)
    distance:setParameter(CONDITION_PARAM_TICKS, -1)
    distance:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local magic = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
    magic:setParameter(CONDITION_PARAM_SUBID, 1)
    magic:setParameter(CONDITION_PARAM_TICKS, -1)
    magic:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
   
local buffBreakpoints = {1, 3, 5, 8, 12, 18, 24, 30, 36, 42}

function onLogin(player)
    local accountId = player:getAccountId()
    local skillpercent = Game.getAccountStorageValue(accountId, 37856)

    if skillpercent < 1 then
        return true
    end
   
    local buffPercent = 0
    for i = 1, #buffBreakpoints do
        if buffBreakpoints[i] <= skillpercent then
            buffPercent = buffPercent + 1
        end
    end
   
    if player:isKnight() then
        melee:setParameter(CONDITION_PARAM_SKILL_MELEE, buffPercent)
        player:addCondition(melee)
       
    elseif player:isPaladin() then
        distance:setParameter(CONDITION_PARAM_SKILL_DISTANCE, buffPercent)
        player:addCondition(distance)
       
    elseif player:isDruid() or player:isSorcerer() then
        magic:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, buffPercent)
        player:addCondition(magic)
       
    end
    return true
end

Dude, it worked perfectly!

Thank you very much, you are beasts.

Thanks @Sarah Wesker for the help too.
 
Back
Top