• 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+ OnEquip error

mRefaat

Marketing and Coding
Joined
Jan 18, 2014
Messages
854
Solutions
3
Reaction score
141
Location
Egypt
Hello

I am using this script to update some storages but i get this error when equip the ring
script

Lua:
local config = {
    [2471] = {attackspeed= 50, damageincrease = 50, dodge = 50, healingbonus = 50, damagereduction = 50}, -- golden helmet
    [2493] = {attackspeed= 50, damageincrease = 50, dodge = 50, healingbonus = 50, damagereduction = 50}, -- ring of the sky
    [2525] = {attackspeed= 50, damageincrease = 50, dodge = 50, healingbonus = 50, damagereduction = 50}, -- dwarven shield
}


function onEquip(player, item, slot, isCall)
    if isCall == false then
        player:setStorageValue(PlayerStorageKeys.ItemsExtraAttackSpeed, player:getStorageValue(PlayerStorageKeys.ItemsExtraAttackSpeed) + config[item:getId()].attackspeed) -- add attack speed
        player:setStorageValue(PlayerStorageKeys.ItemsExtraDamageIncrease, player:getStorageValue(PlayerStorageKeys.ItemsExtraDamageIncrease) + config[item:getId()].damageincrease) -- add damage increase
        player:setStorageValue(PlayerStorageKeys.ItemsExtraDodge, player:getStorageValue(PlayerStorageKeys.ItemsExtraDodge) + config[item:getId()].dodge) -- add dodge
        player:setStorageValue(PlayerStorageKeys.ItemsExtraHealingBonus, player:getStorageValue(PlayerStorageKeys.ItemsExtraHealingBonus) + config[item:getId()].healingbonus) -- add healing bonus
        player:setStorageValue(PlayerStorageKeys.ItemsDamageReduction, player:getStorageValue(PlayerStorageKeys.ItemsDamageReduction) + config[item:getId()].damagereduction) -- add damage reduction
    end
    return true
end

function onDeEquip(player, item, slot)
    player:setStorageValue(PlayerStorageKeys.ItemsExtraAttackSpeed, player:getStorageValue(PlayerStorageKeys.ItemsExtraAttackSpeed) - config[item:getId()].attackspeed) -- remove attack speed
    player:setStorageValue(PlayerStorageKeys.ItemsExtraDamageIncrease, player:getStorageValue(PlayerStorageKeys.ItemsExtraDamageIncrease) - config[item:getId()].damageincrease) -- remove damage increase
    player:setStorageValue(PlayerStorageKeys.ItemsExtraDodge, player:getStorageValue(PlayerStorageKeys.ItemsExtraDodge) - config[item:getId()].dodge) -- remove dodge
    player:setStorageValue(PlayerStorageKeys.ItemsExtraHealingBonus, player:getStorageValue(PlayerStorageKeys.ItemsExtraHealingBonus) - config[item:getId()].healingbonus) -- remove healing bonus
    player:setStorageValue(PlayerStorageKeys.ItemsDamageReduction, player:getStorageValue(PlayerStorageKeys.ItemsDamageReduction) - config[item:getId()].damagereduction) -- remove damage reduction
    return true
end
XML:
    <movevent event="Equip" itemid="2471" slot="head" function="onEquipItem" script="custom/items_attributes.lua" />
    <movevent event="DeEquip" itemid="2471" slot="head" function="onDeEquipItem" script="custom/items_attributes.lua" />
    <movevent event="Equip" itemid="2123" slot="ring" function="onEquipItem" script="custom/items_attributes.lua" />
    <movevent event="DeEquip" itemid="2123" slot="ring" function="onDeEquipItem" script="custom/items_attributes.lua" />   
    <movevent event="Equip" itemid="2525" slot="shield" function="onEquipItem" script="custom/items_attributes.lua" />
    <movevent event="DeEquip" itemid="2525" slot="shield" function="onDeEquipItem" script="custom/items_attributes.lua" />

error

Code:
Lua Script Error: [MoveEvents Interface]
data/movements/scripts/custom/items_attributes.lua:onEquip
data/movements/scripts/custom/items_attributes.lua:10: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/movements/scripts/custom/items_attributes.lua:10: in function <data/movements/scripts/custom/items_attributes.lua:8>

Lua Script Error: [MoveEvents Interface]
data/movements/scripts/custom/items_attributes.lua:onDeEquip
data/movements/scripts/custom/items_attributes.lua:20: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/movements/scripts/custom/items_attributes.lua:20: in function <data/movements/scripts/custom/items_attributes.lua:19>

How to fix this error or how to make this script with the right way without errors and avoid the tfs bug/w.e (3 times check on equip)?
 
Solution
config[item:getId()]
This one
XML:
    <movevent event="Equip" itemid="2123" slot="ring" function="onEquipItem" script="custom/items_attributes.lua" />
    <movevent event="DeEquip" itemid="2123" slot="ring" function="onDeEquipItem" script="custom/items_attributes.lua" />
There is no 2123 in config.
Hello

I am using this script to update some storages but i get this error when equip the ring
script

Lua:
local config = {
    [2471] = {attackspeed= 50, damageincrease = 50, dodge = 50, healingbonus = 50, damagereduction = 50}, -- golden helmet
    [2493] = {attackspeed= 50, damageincrease = 50, dodge = 50, healingbonus = 50, damagereduction = 50}, -- ring of the sky
    [2525] = {attackspeed= 50, damageincrease = 50, dodge = 50, healingbonus = 50, damagereduction = 50}, -- dwarven shield
}


function onEquip(player, item, slot, isCall)
    if isCall == false then
        player:setStorageValue(PlayerStorageKeys.ItemsExtraAttackSpeed, player:getStorageValue(PlayerStorageKeys.ItemsExtraAttackSpeed) + config[item:getId()].attackspeed) -- add attack speed
        player:setStorageValue(PlayerStorageKeys.ItemsExtraDamageIncrease, player:getStorageValue(PlayerStorageKeys.ItemsExtraDamageIncrease) + config[item:getId()].damageincrease) -- add damage increase
        player:setStorageValue(PlayerStorageKeys.ItemsExtraDodge, player:getStorageValue(PlayerStorageKeys.ItemsExtraDodge) + config[item:getId()].dodge) -- add dodge
        player:setStorageValue(PlayerStorageKeys.ItemsExtraHealingBonus, player:getStorageValue(PlayerStorageKeys.ItemsExtraHealingBonus) + config[item:getId()].healingbonus) -- add healing bonus
        player:setStorageValue(PlayerStorageKeys.ItemsDamageReduction, player:getStorageValue(PlayerStorageKeys.ItemsDamageReduction) + config[item:getId()].damagereduction) -- add damage reduction
    end
    return true
end

function onDeEquip(player, item, slot)
    player:setStorageValue(PlayerStorageKeys.ItemsExtraAttackSpeed, player:getStorageValue(PlayerStorageKeys.ItemsExtraAttackSpeed) - config[item:getId()].attackspeed) -- remove attack speed
    player:setStorageValue(PlayerStorageKeys.ItemsExtraDamageIncrease, player:getStorageValue(PlayerStorageKeys.ItemsExtraDamageIncrease) - config[item:getId()].damageincrease) -- remove damage increase
    player:setStorageValue(PlayerStorageKeys.ItemsExtraDodge, player:getStorageValue(PlayerStorageKeys.ItemsExtraDodge) - config[item:getId()].dodge) -- remove dodge
    player:setStorageValue(PlayerStorageKeys.ItemsExtraHealingBonus, player:getStorageValue(PlayerStorageKeys.ItemsExtraHealingBonus) - config[item:getId()].healingbonus) -- remove healing bonus
    player:setStorageValue(PlayerStorageKeys.ItemsDamageReduction, player:getStorageValue(PlayerStorageKeys.ItemsDamageReduction) - config[item:getId()].damagereduction) -- remove damage reduction
    return true
end
XML:
    <movevent event="Equip" itemid="2471" slot="head" function="onEquipItem" script="custom/items_attributes.lua" />
    <movevent event="DeEquip" itemid="2471" slot="head" function="onDeEquipItem" script="custom/items_attributes.lua" />
    <movevent event="Equip" itemid="2123" slot="ring" function="onEquipItem" script="custom/items_attributes.lua" />
    <movevent event="DeEquip" itemid="2123" slot="ring" function="onDeEquipItem" script="custom/items_attributes.lua" />  
    <movevent event="Equip" itemid="2525" slot="shield" function="onEquipItem" script="custom/items_attributes.lua" />
    <movevent event="DeEquip" itemid="2525" slot="shield" function="onDeEquipItem" script="custom/items_attributes.lua" />

error

Code:
Lua Script Error: [MoveEvents Interface]
data/movements/scripts/custom/items_attributes.lua:onEquip
data/movements/scripts/custom/items_attributes.lua:10: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/movements/scripts/custom/items_attributes.lua:10: in function <data/movements/scripts/custom/items_attributes.lua:8>

Lua Script Error: [MoveEvents Interface]
data/movements/scripts/custom/items_attributes.lua:onDeEquip
data/movements/scripts/custom/items_attributes.lua:20: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/movements/scripts/custom/items_attributes.lua:20: in function <data/movements/scripts/custom/items_attributes.lua:19>

How to fix this error or how to make this script with the right way without errors and avoid the tfs bug/w.e (3 times check on equip)?
If you call script that contains function, dont call basic functions...
<movevent event="Equip" itemid="2471" slot="head" function="onEquipItem" script="custom/items_attributes.lua" /> Wrong
<movevent event="Equip" itemid="2471" slot="head" function="onEquipItem" /> Correct
<movevent event="Equip" itemid="2471" slot="head" script="custom/items_attributes.lua" /> Correct
 
config[item:getId()]
This one
XML:
    <movevent event="Equip" itemid="2123" slot="ring" function="onEquipItem" script="custom/items_attributes.lua" />
    <movevent event="DeEquip" itemid="2123" slot="ring" function="onDeEquipItem" script="custom/items_attributes.lua" />
There is no 2123 in config.
 
Solution
If you call script that contains function, dont call basic functions...
<movevent event="Equip" itemid="2471" slot="head" function="onEquipItem" script="custom/items_attributes.lua" /> Wrong
<movevent event="Equip" itemid="2471" slot="head" function="onEquipItem" /> Correct
<movevent event="Equip" itemid="2471" slot="head" script="custom/items_attributes.lua" /> Correct
ok thanks edited.
Post automatically merged:

XML:
    <movevent event="Equip" itemid="2123" slot="ring" function="onEquipItem" script="custom/items_attributes.lua" />
    <movevent event="DeEquip" itemid="2123" slot="ring" function="onDeEquipItem" script="custom/items_attributes.lua" />
There is no 2123 in config.
Aff, sorry i am dumb didn't notice that.
i was saying what is wrong (helmet, shield working but ring no)
Thanks
 
Back
Top