• 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+ 1.2 getAbsorbPercent

Ascuas Funkeln

Rakkedo Game
Joined
Apr 14, 2013
Messages
549
Solutions
32
Reaction score
307
Location
Poland
GitHub
AscuasFunkeln
Hello, i was try this one from there TFS 1.X+ - Get item absorbPercent of element
Work but print all in one table, cant get specific element.
Need to trigger it with extendedopcode to show element resist in skill tab.
Something like this
Code:
getItemAttribute(item.uid, "absorbpercentholy")
ofcourse not work.
Already i have for example armor
Code:
(type(item.uid) == "number" and getItemAttribute(item.uid, "armor") or getItemInfo(item.itemid).armor)
and its work perfect.
Any suggestion to get resist value?
 
Solution
Hmm... Not work as i want xD (BUT ANYWAY THANKS!)

I need this to count "all" value from all "equiped" items, and send it as opcode. As i said i have already done it with attack, armor and defence.
Look up post i paste "example" for attack.

Best way will be change itemtype to player or slottype, if you can help me thats will be nice. Already i try editing you code to make this :D
use this:
Code:
function Player.getProtectionAll(player)
    local protectionAll = 0
    for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
        local item = Player.getSlotItem(player, slot)
        if item then
            local itemType = ItemType(item:getId())
            local count = itemType:getAbilities("absorbPercent", 0)
            if count ~= 0...
Im not sure,
Example attack:
Code:
function Player.getTotalAttack(player, item)
    local total = 0
    local slots = { CONST_SLOT_LEFT}
    local item
    for i = 1, #slots do
        item = player:getSlotItem(slots[i])
        if item then
            total = total + (type(item.uid) == "number" and getItemAttribute(item.uid, "attack") or getItemInfo(item.itemid).attack)
        end
    end
    return total
end
and
Code:
    local Attack = (Player(player):getTotalAttack())
    player:sendExtendedOpcode(102, Attack)

Already got it for defense, attack, armor and all other stuff... But have problem with resists, cuz they are not deffined as attribute.
 
You need a new function in the sources.

* luascript.h
Code:
static int luaItemTypeGetAbilities(lua_State* L);

* luascript.cpp
Code:
registerMethod("ItemType", "getAbilities", LuaScriptInterface::luaItemTypeGetAbilities);
Code:
int LuaScriptInterface::luaItemTypeGetAbilities(lua_State* L)
{
    // itemType:getAbilities(ability [, subType])
    ItemType* itemType = getUserdata<ItemType>(L, 1);
    std::string abilityStr = getString(L, 2);
    uint16_t subType = getNumber<uint16_t>(L, 3);
    if (itemType) {
        if (abilityStr == "stats") {
            lua_pushnumber(L, itemType->getAbilities().stats[subType]);
        } else if (abilityStr == "statsPercent") {
            lua_pushnumber(L, itemType->getAbilities().statsPercent[subType]);
        } else if (abilityStr == "skills") {
            lua_pushnumber(L, itemType->getAbilities().skills[subType]);
        } else if (abilityStr == "specialSkills") {
            lua_pushnumber(L, itemType->getAbilities().specialSkills[subType]);
        } else if (abilityStr == "fieldAbsorbPercent") {
            lua_pushnumber(L, itemType->getAbilities().fieldAbsorbPercent[subType]);
        } else if (abilityStr == "absorbPercent") {
            lua_pushnumber(L, itemType->getAbilities().absorbPercent[subType]);
        } else if (abilityStr == "elementType") {
            lua_pushnumber(L, itemType->getAbilities().elementType);
        } else if (abilityStr == "elementDamage") {
            lua_pushnumber(L, itemType->getAbilities().elementDamage);
        } else if (abilityStr == "speed") {
            lua_pushnumber(L, itemType->getAbilities().speed);
        } else if (abilityStr == "manaShield") {
            lua_pushboolean(L, itemType->getAbilities().manaShield);
        } else if (abilityStr == "invisible") {
            lua_pushboolean(L, itemType->getAbilities().invisible);
        } else if (abilityStr == "regeneration") {
            lua_pushboolean(L, itemType->getAbilities().regeneration);
        } else if (abilityStr == "healthGain") {
            lua_pushnumber(L, itemType->getAbilities().healthGain);
        } else if (abilityStr == "healthTicks") {
            lua_pushnumber(L, itemType->getAbilities().healthTicks);
        } else if (abilityStr == "manaGain") {
            lua_pushnumber(L, itemType->getAbilities().manaGain);
        } else if (abilityStr == "manaTicks") {
            lua_pushnumber(L, itemType->getAbilities().manaTicks);
        } else if (abilityStr == "conditionImmunities") {
            lua_pushnumber(L, itemType->getAbilities().conditionImmunities);
        } else if (abilityStr == "conditionSuppressions") {
            lua_pushnumber(L, itemType->getAbilities().conditionSuppressions);
        } else {
            lua_pushnumber(L, -1);
        }
    }
    else {
        lua_pushnil(L);
    }
    return 1;
}

example of use!
Code:
0 is COMBAT_PHYSICALDAMAGE
1 is COMBAT_ENERGYDAMAGE
2 is COMBAT_EARTHDAMAGE
3 is COMBAT_FIREDAMAGE
4 is COMBAT_UNDEFINEDDAMAGE
5 is COMBAT_LIFEDRAIN
6 is COMBAT_MANADRAIN
7 is COMBAT_HEALING
8 is COMBAT_DROWNDAMAGE
9 is COMBAT_ICEDAMAGE
10 is COMBAT_HOLYDAMAGE
11 is COMBAT_DEATHDAMAGE

ItemType("magma boots"):getAbilities("absorbPercent", 3)
ItemType(7891):getAbilities("absorbPercent", 3)
 
You need a new function in the sources.

* luascript.h
Code:
static int luaItemTypeGetAbilities(lua_State* L);

* luascript.cpp
Code:
registerMethod("ItemType", "getAbilities", LuaScriptInterface::luaItemTypeGetAbilities);
Code:
int LuaScriptInterface::luaItemTypeGetAbilities(lua_State* L)
{
    // itemType:getAbilities(ability [, subType])
    ItemType* itemType = getUserdata<ItemType>(L, 1);
    std::string abilityStr = getString(L, 2);
    uint16_t subType = getNumber<uint16_t>(L, 3);
    if (itemType) {
        if (abilityStr == "stats") {
            lua_pushnumber(L, itemType->getAbilities().stats[subType]);
        } else if (abilityStr == "statsPercent") {
            lua_pushnumber(L, itemType->getAbilities().statsPercent[subType]);
        } else if (abilityStr == "skills") {
            lua_pushnumber(L, itemType->getAbilities().skills[subType]);
        } else if (abilityStr == "specialSkills") {
            lua_pushnumber(L, itemType->getAbilities().specialSkills[subType]);
        } else if (abilityStr == "fieldAbsorbPercent") {
            lua_pushnumber(L, itemType->getAbilities().fieldAbsorbPercent[subType]);
        } else if (abilityStr == "absorbPercent") {
            lua_pushnumber(L, itemType->getAbilities().absorbPercent[subType]);
        } else if (abilityStr == "elementType") {
            lua_pushnumber(L, itemType->getAbilities().elementType);
        } else if (abilityStr == "elementDamage") {
            lua_pushnumber(L, itemType->getAbilities().elementDamage);
        } else if (abilityStr == "speed") {
            lua_pushnumber(L, itemType->getAbilities().speed);
        } else if (abilityStr == "manaShield") {
            lua_pushboolean(L, itemType->getAbilities().manaShield);
        } else if (abilityStr == "invisible") {
            lua_pushboolean(L, itemType->getAbilities().invisible);
        } else if (abilityStr == "regeneration") {
            lua_pushboolean(L, itemType->getAbilities().regeneration);
        } else if (abilityStr == "healthGain") {
            lua_pushnumber(L, itemType->getAbilities().healthGain);
        } else if (abilityStr == "healthTicks") {
            lua_pushnumber(L, itemType->getAbilities().healthTicks);
        } else if (abilityStr == "manaGain") {
            lua_pushnumber(L, itemType->getAbilities().manaGain);
        } else if (abilityStr == "manaTicks") {
            lua_pushnumber(L, itemType->getAbilities().manaTicks);
        } else if (abilityStr == "conditionImmunities") {
            lua_pushnumber(L, itemType->getAbilities().conditionImmunities);
        } else if (abilityStr == "conditionSuppressions") {
            lua_pushnumber(L, itemType->getAbilities().conditionSuppressions);
        } else {
            lua_pushnumber(L, -1);
        }
    }
    else {
        lua_pushnil(L);
    }
    return 1;
}

example of use!
Code:
0 is COMBAT_PHYSICALDAMAGE
1 is COMBAT_ENERGYDAMAGE
2 is COMBAT_EARTHDAMAGE
3 is COMBAT_FIREDAMAGE
4 is COMBAT_UNDEFINEDDAMAGE
5 is COMBAT_LIFEDRAIN
6 is COMBAT_MANADRAIN
7 is COMBAT_HEALING
8 is COMBAT_DROWNDAMAGE
9 is COMBAT_ICEDAMAGE
10 is COMBAT_HOLYDAMAGE
11 is COMBAT_DEATHDAMAGE

ItemType("magma boots"):getAbilities("absorbPercent", 3)
ItemType(7891):getAbilities("absorbPercent", 3)
I will check THIS!!
 
Feel free to use it is a simple function, ;) any inconvenience you tell me.
Hmm... Not work as i want xD (BUT ANYWAY THANKS!)

I need this to count "all" value from all "equiped" items, and send it as opcode. As i said i have already done it with attack, armor and defence.
Look up post i paste "example" for attack.

Best way will be change itemtype to player or slottype, if you can help me thats will be nice. Already i try editing you code to make this :D
 
Hmm... Not work as i want xD (BUT ANYWAY THANKS!)

I need this to count "all" value from all "equiped" items, and send it as opcode. As i said i have already done it with attack, armor and defence.
Look up post i paste "example" for attack.

Best way will be change itemtype to player or slottype, if you can help me thats will be nice. Already i try editing you code to make this :D
use this:
Code:
function Player.getProtectionAll(player)
    local protectionAll = 0
    for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
        local item = Player.getSlotItem(player, slot)
        if item then
            local itemType = ItemType(item:getId())
            local count = itemType:getAbilities("absorbPercent", 0)
            if count ~= 0 then
                for i = 1, 11 do
                    local count2 = itemType:getAbilities("absorbPercent", i)
                    if count2 ~= count then
                        count = 0
                    end
                end
            end
            protectionAll = protectionAll + count
        end
    end
    return protectionAll
end
 
Last edited:
Solution
use this:
Code:
function Player.getProtectionAll(player)
    local protectionAll = 0
    for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
        local item = Player.getSlotItem(player, slot)
        if item then
            local itemType = ItemType(item:getId())
            local count = itemType:getAbilities("absorbPercent", 0)
            if count ~= 0 then
                for i = 1, 11 do
                    local count2 = itemType:getAbilities("absorbPercent", i)
                    if count2 ~= count then
                        count = 0
                    end
                end
            end
            protectionAll = protectionAll + count
        end
    end
    return count
end
0 errors, nothing happened :|
 
Sorry, check again
 
Sorry, check again
Yes i find this incorrect with count and protectionAll and i fix it before, and nothing happend... I trying to fix that :p

@edit Ok i Fix that :p
Just counting absorb percent one by one instead of all "changge "i" to defined number and its work :)
 
Last edited:
This script show how many protectionall my char have?
Exemple:
I use Helmet (+7% protection all) and Armor (+8 protection all), when i use commands show like : You have +15% protection all

Its like that?
 
Back
Top