• 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+ Attackspeed as item attribute

DaBlauwk

Psychedelic
Joined
Jun 9, 2014
Messages
41
Reaction score
3
Location
The Moon
Hello!
I've tried to add attackspeed to item attributes.
I'm using this release: [8.6] [TFS1.3] Global + Source + Web + tools + Quest Reward System (https://otland.net/threads/8-6-tfs1-3-global-source-web-tools-quest-reward-system.271659/)
I recompiled successfully and added everything here TFS 1.X+ - [C++] item attack speed (attr key not recognized) (https://otland.net/threads/c-item-attack-speed-attr-key-not-recognized.262272/)
Tried adding attackSpeed attribute to items.xml but actual attackspeed doesn't change, item shows AtkSpd +500 but doesn't hit twice every second.

This error comes when I try to attack a creature
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/others/stats.lua:onHealthChange
data/stats.lua:720: attempt to call method 'getAttackSpeed' (a nil value)
stack traceback:
        [C]: in function 'getAttackSpeed'
        data/stats.lua:720: in function 'getItemAttribute'
        data/stats.lua:2442: in function 'getLevel'
        data/stats.lua:29: in function 'getStatReqLevel'
        data/stats.lua:1424: in function <data/stats.lua:1408>

This error comes when I try to use item to add item attributes to it
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/other/slot.lua:onUse
data/stats.lua:720: attempt to call method 'getAttackSpeed' (a nil value)
stack traceback:
        [C]: in function 'getAttackSpeed'
        data/stats.lua:720: in function 'getItemAttribute'
        data/stats.lua:1089: in function 'addStat'
        data/stats.lua:2532: in function 'generateTier'
        data/stats.lua:2578: in function 'generateLooted'
        data/stats.lua:2638: in function 'generateStats'
        data/stats.lua:1369: in function <data/stats.lua:1127>

Thanks in advance!
Post automatically merged:

Should I even try to continue fixing this or should I remove this and implement another system like this.
 

Attachments

Last edited:
Solution
tried it like this
Lua:
..'\basestats2[spellname]: '.. tostring(basestats2[spellname])
got
Code:
spellname: attackspeed
spellvalue: 26
attrkeys[spellname]: 16777216
fullstats[spellname]: asestats2[spellname]: nil----------

like this
Lua:
..'\basestats2[spellname]: '.. basestat
and got
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/other/slot.lua:onUse
data/stats.lua:1114: attempt to concatenate global 'basestat' (a nil value)
stack traceback:
        [C]: in function '__concat'
        data/stats.lua:1114: in function 'addStat'
        data/stats.lua:2540: in function 'generateTier'
        data/stats.lua:2586: in function 'generateLooted'
        data/stats.lua:2646: in function 'generateStats'
        data/stats.lua:1377: in function...

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,244
Solutions
71
Reaction score
555
Location
Hell
Hello!
I've tried to add attackspeed to item attributes.
I'm using this release: [8.6] [TFS1.3] Global + Source + Web + tools + Quest Reward System (https://otland.net/threads/8-6-tfs1-3-global-source-web-tools-quest-reward-system.271659/)
I recompiled successfully and added everything here TFS 1.X+ - [C++] item attack speed (attr key not recognized) (https://otland.net/threads/c-item-attack-speed-attr-key-not-recognized.262272/)
Tried adding attackSpeed attribute to items.xml but actual attackspeed doesn't change, item shows AtkSpd +500 but doesn't hit twice every second.

This error comes when I try to attack a creature
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/others/stats.lua:onHealthChange
data/stats.lua:720: attempt to call method 'getAttackSpeed' (a nil value)
stack traceback:
        [C]: in function 'getAttackSpeed'
        data/stats.lua:720: in function 'getItemAttribute'
        data/stats.lua:2442: in function 'getLevel'
        data/stats.lua:29: in function 'getStatReqLevel'
        data/stats.lua:1424: in function <data/stats.lua:1408>

This error comes when I try to use item to add item attributes to it
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/other/slot.lua:onUse
data/stats.lua:720: attempt to call method 'getAttackSpeed' (a nil value)
stack traceback:
        [C]: in function 'getAttackSpeed'
        data/stats.lua:720: in function 'getItemAttribute'
        data/stats.lua:1089: in function 'addStat'
        data/stats.lua:2532: in function 'generateTier'
        data/stats.lua:2578: in function 'generateLooted'
        data/stats.lua:2638: in function 'generateStats'
        data/stats.lua:1369: in function <data/stats.lua:1127>

Thanks in advance!
Post automatically merged:

Should I even try to continue fixing this or should I remove this and implement another system like this.
This means that getAttackSpeed is not found.
attempt to call method 'getAttackSpeed' (a nil value)

Have you added the luascript part?
C++:
registerEnum(ITEM_ATTRIBUTE_ATTACK)
registerEnum(ITEM_ATTRIBUTE_ATTACKSPEED)
C++:
registerMethod("ItemType", "getAttack", LuaScriptInterface::luaItemTypeGetAttack);
registerMethod("ItemType", "getAttackSpeed", LuaScriptInterface::luaItemTypeGetAttackSpeed);
C++:
int LuaScriptInterface::luaItemTypeGetAttack(lua_State* L)
{
    // itemType:getAttack()
    const ItemType* itemType = getUserdata<const ItemType>(L, 1);
    if (itemType) {
        lua_pushnumber(L, itemType->attack);
    } else {
        lua_pushnil(L);
    }
    return 1;
}

int LuaScriptInterface::luaItemTypeGetAttackSpeed(lua_State* L)
{
    // itemType:getAttackSpeed()
    const ItemType* itemType = getUserdata<const ItemType>(L, 1);
    if (itemType) {
        lua_pushnumber(L, itemType->attackSpeed);
    } else {
        lua_pushnil(L);
    }
    return 1;
}
 
OP
OP
DaBlauwk

DaBlauwk

Psychedelic
Joined
Jun 9, 2014
Messages
41
Reaction score
3
Location
The Moon
This means that getAttackSpeed is not found.
attempt to call method 'getAttackSpeed' (a nil value)

Have you added the luascript part?
C++:
registerEnum(ITEM_ATTRIBUTE_ATTACK)
registerEnum(ITEM_ATTRIBUTE_ATTACKSPEED)
C++:
registerMethod("ItemType", "getAttack", LuaScriptInterface::luaItemTypeGetAttack);
registerMethod("ItemType", "getAttackSpeed", LuaScriptInterface::luaItemTypeGetAttackSpeed);
C++:
int LuaScriptInterface::luaItemTypeGetAttack(lua_State* L)
{
    // itemType:getAttack()
    const ItemType* itemType = getUserdata<const ItemType>(L, 1);
    if (itemType) {
        lua_pushnumber(L, itemType->attack);
    } else {
        lua_pushnil(L);
    }
    return 1;
}

int LuaScriptInterface::luaItemTypeGetAttackSpeed(lua_State* L)
{
    // itemType:getAttackSpeed()
    const ItemType* itemType = getUserdata<const ItemType>(L, 1);
    if (itemType) {
        lua_pushnumber(L, itemType->attackSpeed);
    } else {
        lua_pushnil(L);
    }
    return 1;
}
Also added to luascript.h
C++:
        static int luaItemTypeGetAttack(lua_State* L);
        static int luaItemTypeGetAttackSpeed(lua_State* L);
and this all worked for the last error but now we got a new one that I havent got a clue about
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/other/slot.lua:onUse
data/stats.lua:1108: attempt to perform arithmetic on a nil value
stack traceback:
        [C]: in function '__mul'
        data/stats.lua:1108: in function 'addStat'
        data/stats.lua:2532: in function 'generateTier'
        data/stats.lua:2578: in function 'generateLooted'
        data/stats.lua:2638: in function 'generateStats'
        data/stats.lua:1369: in function <data/stats.lua:1127>

This happens everytime it tries to add attackspeed to a item.
 

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,244
Solutions
71
Reaction score
555
Location
Hell
Also added to luascript.h
C++:
        static int luaItemTypeGetAttack(lua_State* L);
        static int luaItemTypeGetAttackSpeed(lua_State* L);
and this all worked for the last error but now we got a new one that I havent got a clue about
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/other/slot.lua:onUse
data/stats.lua:1108: attempt to perform arithmetic on a nil value
stack traceback:
        [C]: in function '__mul'
        data/stats.lua:1108: in function 'addStat'
        data/stats.lua:2532: in function 'generateTier'
        data/stats.lua:2578: in function 'generateLooted'
        data/stats.lua:2638: in function 'generateStats'
        data/stats.lua:1369: in function <data/stats.lua:1127>

This happens everytime it tries to add attackspeed to a item.
Something on this line is evaluated to nil
Lua:
item:setAttribute(attrkeys[spellname], fullstats[spellname] + math.abs(math.floor((basestats2[spellname] * spellvalue/100))))
add this before that line to see what values are being used
Lua:
print(
    'spellname: ' .. spellname
    ..'\nspellvalue: '.. spellvalue
    ..'\nattrkeys[spellname]: '.. tostring(attrkeys[spellname])
    ..'\nfullstats[spellname]: '.. tostring(fullstats[spellname])
    ..'----------'
)
 
OP
OP
DaBlauwk

DaBlauwk

Psychedelic
Joined
Jun 9, 2014
Messages
41
Reaction score
3
Location
The Moon
Something on this line is evaluated to nil
Lua:
item:setAttribute(attrkeys[spellname], fullstats[spellname] + math.abs(math.floor((basestats2[spellname] * spellvalue/100))))
add this before that line to see what values are being used
Lua:
print(
    'spellname: ' .. spellname
    ..'\nspellvalue: '.. spellvalue
    ..'\nattrkeys[spellname]: '.. tostring(attrkeys[spellname])
    ..'\nfullstats[spellname]: '.. tostring(fullstats[spellname])
    ..'----------'
)
Code:
fullstats[spellname]: 3----------
spellname: attackspeed
spellvalue: 27
attrkeys[spellname]: 16777216
fullstats[spellname]: 0----------

Lua Script Error: [Action Interface]
data/actions/scripts/other/other/slot.lua:onUse
data/stats.lua:1115: attempt to perform arithmetic on a nil value
stack traceback:
        [C]: in function '__mul'
        data/stats.lua:1115: in function 'addStat'
        data/stats.lua:2539: in function 'generateTier'
        data/stats.lua:2585: in function 'generateLooted'
        data/stats.lua:2645: in function 'generateStats'
        data/stats.lua:1376: in function <data/stats.lua:1134>
 

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,244
Solutions
71
Reaction score
555
Location
Hell
Code:
fullstats[spellname]: 3----------
spellname: attackspeed
spellvalue: 27
attrkeys[spellname]: 16777216
fullstats[spellname]: 0----------

Lua Script Error: [Action Interface]
data/actions/scripts/other/other/slot.lua:onUse
data/stats.lua:1115: attempt to perform arithmetic on a nil value
stack traceback:
        [C]: in function '__mul'
        data/stats.lua:1115: in function 'addStat'
        data/stats.lua:2539: in function 'generateTier'
        data/stats.lua:2585: in function 'generateLooted'
        data/stats.lua:2645: in function 'generateStats'
        data/stats.lua:1376: in function <data/stats.lua:1134>
try printing this one as well basestats2[spellname] assuming it's this part 🤔
 
OP
OP
DaBlauwk

DaBlauwk

Psychedelic
Joined
Jun 9, 2014
Messages
41
Reaction score
3
Location
The Moon
try printing this one as well basestats2[spellname] assuming it's this part 🤔
tried it like this
Lua:
..'\basestats2[spellname]: '.. tostring(basestats2[spellname])
got
Code:
spellname: attackspeed
spellvalue: 26
attrkeys[spellname]: 16777216
fullstats[spellname]: asestats2[spellname]: nil----------

like this
Lua:
..'\basestats2[spellname]: '.. basestat
and got
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/other/slot.lua:onUse
data/stats.lua:1114: attempt to concatenate global 'basestat' (a nil value)
stack traceback:
        [C]: in function '__concat'
        data/stats.lua:1114: in function 'addStat'
        data/stats.lua:2540: in function 'generateTier'
        data/stats.lua:2586: in function 'generateLooted'
        data/stats.lua:2646: in function 'generateStats'
        data/stats.lua:1377: in function <data/stats.lua:1135>

like this:
Lua:
..'\basestats2[spellname]: '.. basestats2
got
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/other/slot.lua:onUse
data/stats.lua:1114: attempt to concatenate local 'basestats2' (a table value)
stack traceback:
        [C]: in function '__concat'
        data/stats.lua:1114: in function 'addStat'
        data/stats.lua:2540: in function 'generateTier'
        data/stats.lua:2586: in function 'generateLooted'
        data/stats.lua:2646: in function 'generateStats'
        data/stats.lua:1377: in function <data/stats.lua:1135>

and like this:
Lua:
..'\basestats2[spellname]: '.. spellvalue
and got:
Code:
spellname: attackspeed
spellvalue: 26
attrkeys[spellname]: 16777216
fullstats[spellname]: asestats2[spellname]: 26----------

Lua Script Error: [Action Interface]
data/actions/scripts/other/other/slot.lua:onUse
data/stats.lua:1116: attempt to perform arithmetic on a nil value
stack traceback:
        [C]: in function '__mul'
        data/stats.lua:1116: in function 'addStat'
        data/stats.lua:2540: in function 'generateTier'
        data/stats.lua:2586: in function 'generateLooted'
        data/stats.lua:2646: in function 'generateStats'
        data/stats.lua:1377: in function <data/stats.lua:1135>

also
Lua:
..'\basestats2[spellname]: '.. spellname
Code:
spellname: attackspeed
spellvalue: 30
attrkeys[spellname]: 16777216
fullstats[spellname]: asestats2[spellname]: attackspeed----------
 

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,244
Solutions
71
Reaction score
555
Location
Hell
tried it like this
Lua:
..'\basestats2[spellname]: '.. tostring(basestats2[spellname])
got
Code:
spellname: attackspeed
spellvalue: 26
attrkeys[spellname]: 16777216
fullstats[spellname]: asestats2[spellname]: nil----------

like this
Lua:
..'\basestats2[spellname]: '.. basestat
and got
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/other/slot.lua:onUse
data/stats.lua:1114: attempt to concatenate global 'basestat' (a nil value)
stack traceback:
        [C]: in function '__concat'
        data/stats.lua:1114: in function 'addStat'
        data/stats.lua:2540: in function 'generateTier'
        data/stats.lua:2586: in function 'generateLooted'
        data/stats.lua:2646: in function 'generateStats'
        data/stats.lua:1377: in function <data/stats.lua:1135>

like this:
Lua:
..'\basestats2[spellname]: '.. basestats2
got
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/other/slot.lua:onUse
data/stats.lua:1114: attempt to concatenate local 'basestats2' (a table value)
stack traceback:
        [C]: in function '__concat'
        data/stats.lua:1114: in function 'addStat'
        data/stats.lua:2540: in function 'generateTier'
        data/stats.lua:2586: in function 'generateLooted'
        data/stats.lua:2646: in function 'generateStats'
        data/stats.lua:1377: in function <data/stats.lua:1135>

and like this:
Lua:
..'\basestats2[spellname]: '.. spellvalue
and got:
Code:
spellname: attackspeed
spellvalue: 26
attrkeys[spellname]: 16777216
fullstats[spellname]: asestats2[spellname]: 26----------

Lua Script Error: [Action Interface]
data/actions/scripts/other/other/slot.lua:onUse
data/stats.lua:1116: attempt to perform arithmetic on a nil value
stack traceback:
        [C]: in function '__mul'
        data/stats.lua:1116: in function 'addStat'
        data/stats.lua:2540: in function 'generateTier'
        data/stats.lua:2586: in function 'generateLooted'
        data/stats.lua:2646: in function 'generateStats'
        data/stats.lua:1377: in function <data/stats.lua:1135>
basestats2[spellname]: nil
------------------------------
spellname : attackspeed
basestats2["attackspeed"] == nil 🤔
------------------------------
['attackspeed'] = basestats.attackspeed

If I'm thinking right, basestats.attackspeed is nil.

Looking at the method which should be responsible for this seems to be missing attackspeed
Lua:
function Item:getBaseStatsInfo()
    local it_id = self:getType()
    local t = {
        attack = it_id:getAttack(),
        defense = it_id:getDefense(),
        extraDefense = it_id:getExtraDefense(),
        armor = it_id:getArmor(),
        hitChance = it_id:getHitChance(),
        shootRange = it_id:getShootRange(),
        charges = it_id:getCharges(),
        duration = self:getBaseDuration()
    }
    return t
end
 
Solution
OP
OP
DaBlauwk

DaBlauwk

Psychedelic
Joined
Jun 9, 2014
Messages
41
Reaction score
3
Location
The Moon
basestats2[spellname]: nil
------------------------------
spellname : attackspeed
basestats2["attackspeed"] == nil 🤔
------------------------------
['attackspeed'] = basestats.attackspeed

If I'm thinking right, basestats.attackspeed is nil.

Looking at the method which should be responsible for this seems to be missing attackspeed
Lua:
function Item:getBaseStatsInfo()
    local it_id = self:getType()
    local t = {
        attack = it_id:getAttack(),
        defense = it_id:getDefense(),
        extraDefense = it_id:getExtraDefense(),
        armor = it_id:getArmor(),
        hitChance = it_id:getHitChance(),
        shootRange = it_id:getShootRange(),
        charges = it_id:getCharges(),
        duration = self:getBaseDuration()
    }
    return t
end
Well no errors, but it doesn't seem to add the attackspeed bonus, everything works like it used to, but it just doesn't add attackspeed bonus to anything.
 

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,244
Solutions
71
Reaction score
555
Location
Hell
Well no errors, but it doesn't seem to add the attackspeed bonus, everything works like it used to, but it just doesn't add attackspeed bonus to anything.
have you modified Player::getAttackSpeed() ?

Looks like this part is supposed to take care of that 🤔
Lua:
elseif eq_stat_conditions[i] == 'attackspeed' then
            if v_stat_normal[eq_stat_conditions[i]] then
                fu = fu+1
                doAddCondition(cid,stat_conditions[1][eq_stat_conditions[i]][math.floor(math.max(math.min(100, v_stat_normal[eq_stat_conditions[i]]), -100))])
                ca[62] = 1
            end
            
            if v_stat_percent[eq_stat_conditions[i]] then
                fu = fu+1
                doAddCondition(cid, stat_conditions[2][eq_stat_conditions[i]][math.floor(math.max(math.min(300, v_stat_percent[eq_stat_conditions[i]] * 100), -95))])
                ca[63] = 1
            end
. . .

In which file? I guess not
player.h
 
OP
OP
DaBlauwk

DaBlauwk

Psychedelic
Joined
Jun 9, 2014
Messages
41
Reaction score
3
Location
The Moon
No
Post automatically merged:

player.h lines using attackspeed:
C++:
uint32_t getAttackSpeed() const {
            return vocation->getAttackSpeed();
        }
C++:
void doAttacking(uint32_t interval) override;
        bool hasExtraSwing() override {
            return lastAttack > 0 && ((OTSYS_TIME() - lastAttack) >= getAttackSpeed());
        }
Post automatically merged:

What does classicAttackSpeed in config.lua do?
@Snavy
 
Last edited:
OP
OP
DaBlauwk

DaBlauwk

Psychedelic
Joined
Jun 9, 2014
Messages
41
Reaction score
3
Location
The Moon
Got it working after adding
Lua:
{
            name = 'attackspeed',
           
            weaponLootName = {'fast',''},
            armorLootName = {'',''},
            otherLootName = {'',''},
           
            spellName = 'attackspeed',
            enabledValues = true,
            enabledPercent = true
        },
after
Lua:
{
            name = 'atk',
           
            weaponLootName = {'sharpened',''},
            armorLootName = {'',''},
            otherLootName = {'',''},
           
            spellName = 'Attack',
            enabledValues = true,
            enabledPercent = true
        },
under
-- attr based stats

Haven't tested yet if it actually gives more attackspeed or not.

17:34 Item modification successful.
17:34 You see a legendary magic sword (Atk:48, AtkSpd:1, Def:54 +4).
It can only be wielded properly by players of level 80 or higher.
It weighs 42.00 oz.
[def.+56%]
[melee.+14%]
[extra def.+1]
[attackspeed.+1]
Post automatically merged:

Should I also add this to luascript.cpp and recompile?
C++:
registerEnum(CONDITION_PARAM_ATTACKSPEED)
@Snavy
 
Last edited:
Top