• 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.0 player:getTotalArm()

Codinablack

Dreamer
Content Editor
Joined
Dec 26, 2013
Messages
1,635
Solutions
11
Reaction score
879
Hello Otland! I have come to tell everyone about an awesome function I was attempting to make and @Ninja was so kind as to make it, and make it right for me... Full credits go to @Ninja

Ok so open up compat.lua and add this


Code:
function Player.getTotalArmor(self)
    local total = 0
    local slots = { CONST_SLOT_HEAD, CONST_SLOT_NECKLACE, CONST_SLOT_ARMOR, CONST_SLOT_LEGS, CONST_SLOT_FEET, CONST_SLOT_RING }
    local item
    for i = 1, #slots do
        item = self:getSlotItem(slots[i])
        if item then
            total = total + item:getType():getArmor()
        end
    end
    return total
end

Then all you have to do is use it like so

function onSay(cid, words, param)
print(Player(cid):getTotalArmor())
end
So now you can use player:getTotalArmor in formula's or w/e, NOTE THE FUNCTION ONLY RETURNS THE TOTAL ARMOR VALUE, YOU CAN'T USE IT TO SET THE VALUE... As it is, no way to do that through lua that I know of for tfs.1.0 maybe if someone made arm an attribute in the item class, but I wouldn't know how to do that...
 
I add 2 other TotalDefense and TotalAttack.
I use this scripts on my server.
GET VALUE?

local arm = player:getTotalArmor()
local def = player:getTotalDefense()
local atk = player:getTotalAttack()

TFS 1.2 10.98 Working perfect!
Thanks @Ninja


Lua:
function Player.getTotalDefense(self)
    local total = 0
    local slots = { CONST_SLOT_RIGHT, CONST_SLOT_LEFT }
    local item
    for i = 1, #slots do
        item = self:getSlotItem(slots[i])
        if item then
            total = total + item:getType():getDefense()
        end
    end
    return total
end
Lua:
function Player.getTotalAttack(self)
    local total = 0
    local slots = { CONST_SLOT_RIGHT, CONST_SLOT_LEFT }
    local item
    for i = 1, #slots do
        item = self:getSlotItem(slots[i])
        if item then
            total = total + item:getType():getAttack()
        end
    end
    return total
end
 
Back
Top