• 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+ Item status varying

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hello guys, hope you are all good.

I'm planning on add a feature to my custom server that a weapon can be crafted with a different amount of damage, for example:

Player craft dragon hammer and it can have 30 atk, or 31 atk, or 32 atk... With a range of +-5 atk varying.

The way I came up to do this is to add the same sprite of dragon hammer +4 times and create 5 different dragon hammers with different ids to vary the atk, however that's a lot work for a simple feature. Is there a easier way where I can do this through .lua?
 
yes it does
At my server all itens are craftable, so it has a lot of itens being crafted at the same script and they have different atk, so if I wanted to add this to all itens that have atk and the amount would vary between the weapon atk +5 for example, I would have to add like this:

Lua:
            local item = self:addItem(recipes[Type[p]].options[Option[p]].id, recipes[Type[p]].options[Option[p]].count)
            if item:hasAttribute(ITEM_ATTRIBUTE_ATTACK) then
            item:setAttribute(ITEM_ATTRIBUTE_ATTACK, math.random(ItemType(recipes[Type[p]].options[Option[p]].id):getAttack()),ItemType(recipes[Type[p]].options[Option[p]].id):getAttack())+5)
            end

Would that statement be right?
 
At my server all itens are craftable, so it has a lot of itens being crafted at the same script and they have different atk, so if I wanted to add this to all itens that have atk and the amount would vary between the weapon atk +5 for example, I would have to add like this:

Lua:
            local item = self:addItem(recipes[Type[p]].options[Option[p]].id, recipes[Type[p]].options[Option[p]].count)
            if item:hasAttribute(ITEM_ATTRIBUTE_ATTACK) then
            item:setAttribute(ITEM_ATTRIBUTE_ATTACK, math.random(ItemType(recipes[Type[p]].options[Option[p]].id):getAttack()),ItemType(recipes[Type[p]].options[Option[p]].id):getAttack())+5)
            end

Would that statement be right?
use some local variables my dude.
Makes it 600x easier to read.

Coding is roughly 90% reading and 10% coding.
Make the reading as easy as possible.

Lua:
local itemIndex = recipes[Type[p]].options[Option[p]]
local item = self:addItem(itemIndex.id, itemIndex.count)
if item:hasAttribute(ITEM_ATTRIBUTE_ATTACK) then
    local weaponAttackValue = ItemType(itemIndex.id):getAttack() + math.random(0, 5)
    item:setAttribute(ITEM_ATTRIBUTE_ATTACK, weaponAttackValue)
end
 
use some local variables my dude.
Makes it 600x easier to read.

Coding is roughly 90% reading and 10% coding.
Make the reading as easy as possible.

Lua:
local itemIndex = recipes[Type[p]].options[Option[p]]
local item = self:addItem(itemIndex.id, itemIndex.count)
if item:hasAttribute(ITEM_ATTRIBUTE_ATTACK) then
    local weaponAttackValue = ItemType(itemIndex.id):getAttack() + math.random(0, 5)
    item:setAttribute(ITEM_ATTRIBUTE_ATTACK, weaponAttackValue)
end
Thanks, your way it's much more clean. I will test it out later
 
Back
Top