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

TFS 1.X+ How to make changes in atk speed and database?

Togu

Advanced OT User
Joined
Jun 22, 2018
Messages
308
Solutions
1
Reaction score
178
Location
Brazil
This is my project: The Forgotten Tibia

1) How do I change attack speed permanently?

I've seen in the sources that there is no lua function that changes the attack speed of a player, there is no "setAttackSpeed" function. How do I make that? What's the step by step? I know I could study and learn already done source codes like "setCapacity" and "setMaxHealth" but I've tried and seems too difficult for me. I'm not a C++ expert but I want to learn it the right way. Do I have to make a setAttackSpeed function in player.cpp and then call it in luascript.cpp? What's the system execution flow in this case?

2) How do I insert/update values in database?

I know how to get values:
local rows = db.getResult("SELECT `" .. skill .. "` FROM `players` WHERE `id` = " .. player .. ";")
local newSkillValue = rows:getDataInt(skill)

Edit: /\ /\ /\ /\
db.getResult is giving me error:
Code:
attempt to call field 'getResult' (a nil value)

But I don't know how to update them (I cant use a sql query with UPDATE cause this will happen with the character online, then when he logout it will go back to the older value).

I wanna make that so player can remove their skills from database.

(for now I'll try make this with the skillLost function that is called when player dies - I already have a function that update skill percent to 0%)
 
Last edited:
Solution
1) First of all there is no actual "attackSpeed" field in player class. Attack speed is vocation based. You need to change the attackSpeed formula (look for getAttackSpeed function). You can base it off a certain skill level/currently used weapon etc. For the attackSpeed statistic itself you will have to add it to the player class based on some other statistic (for example capacity like you mentioned). It really shouldn't be that hard and if you paste your attempt here then someone will help you for sure.

2) I don't see a point of changing the value in database only, but if you really want to do it this way then look for a function named "savePlayer"/"loadPlayer" and just exclude from the query any fields that you don't want to be...
1) there's no setAttackSpeed function as far as I know, you can just add attackSpeed Attribute to a weapon. But, you can always create a function in cpp to do so.

2) remove player, do the query.
 
1) there's no setAttackSpeed function as far as I know, you can just add attackSpeed Attribute to a weapon. But, you can always create a function in cpp to do so.

2) remove player, do the query.

1.- in the CPP forum theres already this code.
 
1.- in the CPP forum theres already this code.
1) there's no setAttackSpeed function as far as I know, you can just add attackSpeed Attribute to a weapon. But, you can always create a function in cpp to do so.

2) remove player, do the query.
Thanks! I'll try! :)

But I really want to know how to make a cpp function accessible through lua, this will expand my universe of developing a lot. I'll see the cpp forum.

Edit:
Why am I getting this error?
Code:
data/lib/skillpoints.lua:178: attempt to call field 'getResult' (a nil value)
stack traceback:
        [C]: in function 'getResult'
        data/lib/skillpoints.lua:178: in function 'removeSkillLevels'
        data/lib/skillpoints.lua:336: in function 'skillWindowChoice'
       data/creaturescripts/scripts/skillpoints.lua:2: in function <data/creaturescripts/scripts/skillpoints.lua:1>

Lua:
function Player:removeSkillLevels(skill)
    local rows = db.getResult("SELECT `maglevel` FROM `players` WHERE `id` = 3;")
end

When I change it, it works:
Lua:
db.query("SELECT `maglevel` FROM `players` WHERE `id` = 3;")
 
Last edited:
Thanks! I'll try! :)

But I really want to know how to make a cpp function accessible through lua, this will expand my universe of developing a lot. I'll see the cpp forum.

Edit:
Why am I getting this error?
Code:
data/lib/skillpoints.lua:178: attempt to call field 'getResult' (a nil value)
stack traceback:
        [C]: in function 'getResult'
        data/lib/skillpoints.lua:178: in function 'removeSkillLevels'
        data/lib/skillpoints.lua:336: in function 'skillWindowChoice'
       data/creaturescripts/scripts/skillpoints.lua:2: in function <data/creaturescripts/scripts/skillpoints.lua:1>

Lua:
function Player:removeSkillLevels(skill)
    local rows = db.getResult("SELECT `maglevel` FROM `players` WHERE `id` = 3;")
end

When I change it, it works:
Lua:
db.query("SELECT `maglevel` FROM `players` WHERE `id` = 3;")
The post i say about get and set attackspeed allows you to use thrm in lua. You can see there how to do that
 
1) First of all there is no actual "attackSpeed" field in player class. Attack speed is vocation based. You need to change the attackSpeed formula (look for getAttackSpeed function). You can base it off a certain skill level/currently used weapon etc. For the attackSpeed statistic itself you will have to add it to the player class based on some other statistic (for example capacity like you mentioned). It really shouldn't be that hard and if you paste your attempt here then someone will help you for sure.

2) I don't see a point of changing the value in database only, but if you really want to do it this way then look for a function named "savePlayer"/"loadPlayer" and just exclude from the query any fields that you don't want to be saved/loaded.
 
Solution
Does someone know why I'm getting error with db.getResult and why not with db.storeQuery?
attempt to call field 'getResult' (a nil value)

i just need to solve that to make it work
 
You could write a attack speed function in io...cpp file and replace it in players.cpp with the function where it takes data from vocations.xml.

Edit:
Lua:
    local skill_query = db.storeQuery('SELECT `id`, `maglevel` FROM `players` WHERE `id` = 1;')
    if skill_query then
        local magic_level = result.getNumber(skill_query, 'maglevel')

        player:sendCancelMessage("The magic level of this player is ".. magic_level .."")
    end

This is an example because I am not sure what you exactly need, it will give you the result of magic level from players table.

I think add_skill.lua could help you in this case.
otland/forgottenserver
 
Last edited:
Back
Top