• 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 0.X Show total armor, defense and attack

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
580
Solutions
2
Reaction score
58
Location
México
Hello, otlanders, im making a status-like feature that will show values from the equipped items

Player uses !statusand will be able to see (E.g.)

Total armor: 22 (showing the sum of all equipped armory)
Total defense: 29 (showing defense from weapon + shield)
Total attack: 22 (showing attack from weapon + trinket (ammo slot))

I've been trying to do it but i dont know how to get the summation of all values, all i could do for now is:


Lua:
local slotName = {"Head Slot", "Amulet Slot", "Backpack Slot", "Armor Slot", "Right Hand", "Left Hand", "Legs Slot", "Feet Slot", "Ring Slot", "Ammo Slot"}
    local player = getPlayerByNameWildcard(param)
    if isPlayer(cid) == TRUE then
        local text = getPlayerName(cid).."'s Equipment: "
        for i=1, 10 do
            text = text.."\n"
            local item = getPlayerSlotItem(cid, i)
            if item.itemid > 0 then
                -- if isContainer(item.uid) == TRUE then
                --     text = text..slotName[i]..": "..getItemInfo(item.itemid).armor..getItemsInContainer(item, 1)
                -- else
                    text = text..slotName[i]..": "..getItemInfo(item.itemid).armor
                -- end
            else
                text = text..slotName[i]..": Empty"
            end
        end
        doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE, "[Armor]: "..text)

But, this shows me the value of the single equip, need to show the summation of values.

And i was trying with this script: but it says attempt to index a boolean value at line 6

Lua:
function getTotalArmor(cid)
    local total = 0
    for i = 1, 10 do
        local item = getPlayerSlotItem(cid, i)
        if item then
            total = total + getItemInfo(item.itemid).armor
        end
    end
    return total
end


Im using TFS 0.4
 
Last edited:
Solution
Hello, otlanders, im making a status-like feature that will show values from the equipped items

Player uses !statusand will be able to see (E.g.)

Total armor: 22 (showing the sum of all equipped armory)
Total defense: 29 (showing defense from weapon + shield)
Total attack: 22 (showing attack from weapon + trinket (ammo slot))

I've been trying to do it but i dont know how to get the summation of all values, all i could do for now is:


Lua:
local slotName = {"Head Slot", "Amulet Slot", "Backpack Slot", "Armor Slot", "Right Hand", "Left Hand", "Legs Slot", "Feet Slot", "Ring Slot", "Ammo Slot"}
    local player = getPlayerByNameWildcard(param)
    if isPlayer(cid) == TRUE then
        local text = getPlayerName(cid).."'s Equipment...
Hello, otlanders, im making a status-like feature that will show values from the equipped items

Player uses !statusand will be able to see (E.g.)

Total armor: 22 (showing the sum of all equipped armory)
Total defense: 29 (showing defense from weapon + shield)
Total attack: 22 (showing attack from weapon + trinket (ammo slot))

I've been trying to do it but i dont know how to get the summation of all values, all i could do for now is:


Lua:
local slotName = {"Head Slot", "Amulet Slot", "Backpack Slot", "Armor Slot", "Right Hand", "Left Hand", "Legs Slot", "Feet Slot", "Ring Slot", "Ammo Slot"}
    local player = getPlayerByNameWildcard(param)
    if isPlayer(cid) == TRUE then
        local text = getPlayerName(cid).."'s Equipment: " 
        for i=1, 10 do
            text = text.."\n"
            local item = getPlayerSlotItem(cid, i)
            if item.itemid > 0 then
                -- if isContainer(item.uid) == TRUE then
                --     text = text..slotName[i]..": "..getItemInfo(item.itemid).armor..getItemsInContainer(item, 1)
                -- else
                    text = text..slotName[i]..": "..getItemInfo(item.itemid).armor
                -- end
            else
                text = text..slotName[i]..": Empty"
            end
        end
        doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE, "[Armor]: "..text)

But, this shows me the value of the single equip, need to show the summation of values.

Im using TFS 0.4
u can use this functions
Lua:
function getDef(cid)
   local defense = 0
   for i = CONST_SLOT_RIGHT,CONST_SLOT_LEFT do
     if getPlayerSlotItem(cid, i).uid > 0  then
       if getItemInfo(getPlayerSlotItem(cid,i).itemid).defense then
         defense = defense + getItemInfo(getPlayerSlotItem(cid,i).itemid).defense
       end
     end
     if getPlayerSlotItem(cid, i).uid > 0 then
       if getItemInfo(getPlayerSlotItem(cid, i).itemid).extraDefense > 0 then
         defense = defense + getItemInfo(getPlayerSlotItem(cid, i).itemid).extraDefense
       end
     end
   end
   return defense 
end

function getArm(cid)
   local armor = 0
   for i = CONST_SLOT_FIRST,CONST_SLOT_LAST do
     if getPlayerSlotItem(cid, i).uid > 0 then
       if getItemInfo(getPlayerSlotItem(cid,i).itemid).armor > 0 then
         armor = armor + getItemInfo(getPlayerSlotItem(cid,i).itemid).armor
       end
     end
   end
   return armor > 0 and armor or 1
end

function getAtk(cid)
   local weapon = getPlayerWeapon(cid)
   local attack = 1
   if weapon.uid > 0 then
     if getItemInfo(weapon.itemid).attack then
       attack = attack + getItemInfo(weapon.itemid).attack
     end
     if getItemInfo(weapon.itemid).extraAttack then
       attack = attack + getItemInfo(weapon.itemid).extraAttack
     end
   end
   return attack
end

from here Spell - Advanced Shadow Clones (https://otland.net/threads/advanced-shadow-clones.244486/)
i use and work with me
 
Solution
u can use this functions
Lua:
function getDef(cid)
   local defense = 0
   for i = CONST_SLOT_RIGHT,CONST_SLOT_LEFT do
     if getPlayerSlotItem(cid, i).uid > 0  then
       if getItemInfo(getPlayerSlotItem(cid,i).itemid).defense then
         defense = defense + getItemInfo(getPlayerSlotItem(cid,i).itemid).defense
       end
     end
     if getPlayerSlotItem(cid, i).uid > 0 then
       if getItemInfo(getPlayerSlotItem(cid, i).itemid).extraDefense > 0 then
         defense = defense + getItemInfo(getPlayerSlotItem(cid, i).itemid).extraDefense
       end
     end
   end
   return defense
end

function getArm(cid)
   local armor = 0
   for i = CONST_SLOT_FIRST,CONST_SLOT_LAST do
     if getPlayerSlotItem(cid, i).uid > 0 then
       if getItemInfo(getPlayerSlotItem(cid,i).itemid).armor > 0 then
         armor = armor + getItemInfo(getPlayerSlotItem(cid,i).itemid).armor
       end
     end
   end
   return armor > 0 and armor or 1
end

function getAtk(cid)
   local weapon = getPlayerWeapon(cid)
   local attack = 1
   if weapon.uid > 0 then
     if getItemInfo(weapon.itemid).attack then
       attack = attack + getItemInfo(weapon.itemid).attack
     end
     if getItemInfo(weapon.itemid).extraAttack then
       attack = attack + getItemInfo(weapon.itemid).extraAttack
     end
   end
   return attack
end

from here Spell - Advanced Shadow Clones (https://otland.net/threads/advanced-shadow-clones.244486/)
i use and work with me
thank you very much sir :)
 
Back
Top