• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

Lua Function [TFS 1.2/1.3] player:setAttackSpeed(ms) | player:getAttackSpeed()

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,640
Solutions
559
Reaction score
3,916
player.h
above
C++:
uint32_t inventoryWeight;
add
C++:
uint32_t attackSpeed = 0;

replace getAttackSpeed() with this
C++:
        uint32_t getAttackSpeed() const {
            if (attackSpeed > 0) {
                return attackSpeed;
            }
            return vocation->getAttackSpeed();
        }

add this above getAttackSpeed()
C++:
        void setAttackSpeed(uint32_t speed) {
            attackSpeed = speed;
        }

luascript.h
below
C++:
static int luaPlayerGetFightMode(lua_State* L);
add
C++:
        static int luaPlayerSetAttackSpeed(lua_State* L);
        static int luaPlayerGetAttackSpeed(lua_State* L);

luascript.cpp

below
C++:
registerMethod("Player", "getFightMode", LuaScriptInterface::luaPlayerGetFightMode);
add
C++:
    registerMethod("Player", "getAttackSpeed", LuaScriptInterface::luaPlayerGetAttackSpeed);
    registerMethod("Player", "setAttackSpeed", LuaScriptInterface::luaPlayerSetAttackSpeed);

below
C++:
int LuaScriptInterface::luaPlayerHasSecureMode(lua_State* L)
{
    // player:hasSecureMode()
    Player* player = getUserdata<Player>(L, 1);
    if (player) {
        pushBoolean(L, player->secureMode);
    } else {
        lua_pushnil(L);
    }
    return 1;
}
add
C++:
int LuaScriptInterface::luaPlayerSetAttackSpeed(lua_State* L)
{
    // player:setAttackSpeed(ms)
    Player* player = getUserdata<Player>(L, 1);
    uint32_t ms = getNumber<uint32_t>(L, 2);
    if (player) {
        player->setAttackSpeed(ms);
        pushBoolean(L, true);
    } else {
        lua_pushnil(L);
    }
    return 1;
}

int LuaScriptInterface::luaPlayerGetAttackSpeed(lua_State* L)
{
    // player:getAttackSpeed()
    Player* player = getUserdata<Player>(L, 1);
    if (player) {
        lua_pushnumber(L, player->getAttackSpeed());
    } else {
        lua_pushnil(L);
    }
    return 1;
}

note: if you're using 1.2 and you don't want the player to be interrupted while using items/walking you need to add this code: Fix #1319 by Mkalo · Pull Request #2109 · otland/forgottenserver · GitHub
 
Last edited by a moderator:

felipek9

New Member
Joined
Sep 4, 2014
Messages
2
Reaction score
0
Can you please explain where exactly?

replace getAttackSpeed() with this
Code:
uint32_t getAttackSpeed() const {
if (attackSpeed > 0) {
return attackSpeed;
}
return vocation->getAttackSpeed();
}

add this above getAttackSpeed()
Code:
void setAttackSpeed(uint32_t speed) {
attackSpeed = speed
}
 
OP
OP
Infernum

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,640
Solutions
559
Reaction score
3,916
inside player.h
there's only 1 of each of those functions, ctrl+f and replace them
 

RazorBlade

Retired Snek
Joined
Nov 7, 2009
Messages
2,015
Solutions
3
Reaction score
628
Location
Canada
no, you just need to change the pre-existing getAttackSpeed in player.h
what about in luascript.cpp, normally all the functions you put in there are registered to the Player class so that it can be used in Lua on Player userdata
 

samco

4x4 Developer.
Joined
Jul 3, 2007
Messages
1,019
Solutions
9
Reaction score
237
Location
Spain
I think you are missing that player.h does not have attackSpeed as property... It should be added.

what about in luascript.cpp, normally all the functions you put in there are registered to the Player class so that it can be used in Lua on Player userdata
And if you want to use it in lua scripts, you need to register the methods in Player class as razorBlade said:

Code:
    registerMethod("Player", "getAttackSpeed", LuaScriptInterface::luaPlayerGetAttackSpeed);
    registerMethod("Player", "setAttackSpeed", LuaScriptInterface::luaPlayerSetAttackSpeed);
 
Last edited by a moderator:
OP
OP
Infernum

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,640
Solutions
559
Reaction score
3,916
it doesn't have to be exactly under that function, it can be underneath any function that starts with luaPlayerXXXX
for 1.2 you could put it under static int luaPlayerSetStamina(lua_State* L);
 

Tempesto

Member
Joined
Feb 12, 2018
Messages
79
Reaction score
6
Location
Ruining your servers.
I had other errors with my source where the boost files weren't connecting with compilation process properly as well, so I don't know why there was problem when I tried compiling. I tried putting in the right spots. Idk boost isn't working for me properly. I'm done trying different ideas, thanks for responding though.
 

demon088

#088 in the Horde
Joined
Jun 17, 2009
Messages
236
Solutions
3
Reaction score
28
Location
Hell
I'm sorry for asking this, but how can I apply this to an action or spell script? I have tried only adding something like:
Code:
player:setAttackSpeed(1000)
But it hasn't modified the att speed...
Can someone explain further about this?
Thanks for the assistance!
 
OP
OP
Infernum

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,640
Solutions
559
Reaction score
3,916
You're using it correctly, but I'm guessing your base attack speed is 1000ms in vocations.xml. Remember that it's not an additive bonus, it sets the attack speed to what you pass to the function.
 

rickgv

Member
Joined
Oct 22, 2007
Messages
44
Reaction score
16
I just tested it, and it works perfectly.
I wonder how could I create a spell to temporarily increase my attack speed.
Anyways, thanks, Infernum for one more awesome mod.
 

ssiwyy158

Member
Joined
Jan 24, 2011
Messages
123
Solutions
2
Reaction score
14
0 errors during compile but server cannot take off console appears and disappears

(sorry for english)
 
Last edited:

Mr Noxi

Noxus Otserver
Premium User
Joined
May 13, 2010
Messages
273
Solutions
3
Reaction score
93
Location
Sweden
I have set it up but i dont understand how do i choose the attack speed set?
 

Evil Puncker

I know nothing
TFS Developer
Joined
May 30, 2009
Messages
8,537
Solutions
260
Reaction score
4,526
I have set it up but i dont understand how do i choose the attack speed set?
you can for example add this to an action script and it will set player attack speed to 1000:

Lua:
player:setAttackSpeed(1000)
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,256
Solutions
25
Reaction score
2,524
Location
Poland
GitHub
Zbizu
Interesting, but imo it should be handled the same way the player speed is:

  • a condition with attackspeed change
  • a function to change base value
  • a possibility to do it as an item attribute
 

Evil Puncker

I know nothing
TFS Developer
Joined
May 30, 2009
Messages
8,537
Solutions
260
Reaction score
4,526
Interesting, but imo it should be handled the same way the player speed is:

  • a condition with attackspeed change
  • a function to change base value
  • a possibility to do it as an item attribute

but yeah, I agree, it would be cool to have spells and items with that
 
Top