• 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!

Lua Making script work for more than one item.

Apoccalypse

New Member
Joined
Apr 15, 2017
Messages
114
Solutions
2
Reaction score
4
Hello guys,
Thanks to Static_ and Xikini it was finally possible to create the script which increase damge dealt by the item at tfs 0.3.6.
I wanted to make it work for x declared items ,not only for one, so I was trying to create a table.

Lua:
local config = {
    item_id = 2518, -- right or left hand
    more_dmg = 7, -- percent
    more_dmg_spell = 7, -- percent
    storage = 5011
}
local function checkDamageIncrease(cid)
    local item = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
    if item and item.itemid == config.item_id then
        return true
    end
    item = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    if item and item.itemid == config.item_id then
        return true
    end
    return false
end
local storage = 815500 -- make sure stack overflow doesn't happen
function onStatsChange(cid, attacker, type, combat, value)
local correct = value * 2 + ((value * 2) * config.more_dmg/100)
local correct2 = value * 2 + ((value * 2) * config.more_dmg_spell/100)
    if isPlayer(attacker) and getPlayerStorageValue(attacker, config.storage) == 1 then
        if (type == STATSCHANGE_HEALTHLOSS or STATSCHANGE_MANALOSS) and checkDamageIncrease(attacker) then
            if getPlayerStorageValue(cid, storage) == -1 then
                doPlayerSetStorageValue(cid, storage, 1) -- set storage value before the creature takes another hit to avoid overflow
                if (combat == COMBAT_PHYSICALDAMAGE) then
                return false,
                   
                    doTargetCombatHealth(attacker, cid, combat, -correct, -correct, 255)
                else
                return false,
                    doTargetCombatHealth(attacker, cid, combat, -correct2, -correct2, 255)
                   
                   
                end
            else
                doPlayerSetStorageValue(cid, storage, -1)
            end
           
        end
    end
    return true
end

Lua:
local t = {
storage = 5011,
   
    up  = {
        [2518]    = {more_dmg = 7,  more_dmg_spell = 5},
        [9778]    = {more_dmg = 4,  more_dmg_spell = 3}}
        }

local function checkDamageIncrease(cid)
    local item = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
    if item and item.itemid == t.up[getItemById] then
        return true
    end
    item = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    if item and item.itemid == t.up[getItemById] then
        return true
    end
    return false
end
local storage = 815500 -- make sure stack overflow doesn't happen
function onStatsChange(cid, attacker, type, combat, value)
local k = t.up[getItemById]
local correct = value * 2 + ((value * 2) * k.more_dmg/100)
local correct2 = value * 2 + ((value * 2) * k.more_dmg_spell/100)
    if isPlayer(attacker) and getPlayerStorageValue(attacker, t.storage) == 1 then
        if (type == STATSCHANGE_HEALTHLOSS or STATSCHANGE_MANALOSS) and checkDamageIncrease(attacker) then
            if getPlayerStorageValue(cid, storage) == -1 then
                doPlayerSetStorageValue(cid, storage, 1) -- set storage value before the creature takes another hit to avoid overflow
                if (combat == COMBAT_PHYSICALDAMAGE) then
                return false,
                   
                    doTargetCombatHealth(attacker, cid, combat, -correct, -correct, 255)
                else
                return false,
                    doTargetCombatHealth(attacker, cid, combat, -correct2, -correct2, 255)
                   
                   
                end
            else
                doPlayerSetStorageValue(cid, storage, -1)
            end
           
        end
    end
    return true
end

Unfortunately it des not work but I am sure that the mistake is here:
Lua:
if item and item.itemid == t.up[getItemById] then

t.up[getItemById]- this line is bad declared ,so script can not work ,because item can not be found.

If anyone would help me to solve it that would be great :)
 
Solution
In this case the script finds the item of the victim:
Lua:
local cfg = {
    storage = 5011,
    items = {
        [2433]    = {more_dmg = 3,  more_dmg_spell = 3},  -- Magic Staff                         z
        [7426]    = {more_dmg = 3,  more_dmg_spell = 3},  -- Radagast Staff                      z
        [7451]    = {more_dmg = 5,  more_dmg_spell = 5},  -- Shadow Spectre                      z
        [12318]    = {more_dmg = 5,  more_dmg_spell = 5},  -- Antibiotic Sceptre                 z
        [2518]    = {more_dmg = 4,  more_dmg_spell = 4},  -- Beholder Shield                     x
        [8918]    = {more_dmg = 6,  more_dmg_spell = 6},   -- Spellbook of dark Mesterious        x
        [9778]    = {more_dmg = 4,  more_dmg_spell = 4},  --...
I think this is the best solution, but thanks a lot Itutorial, without you, the idea with putting it directly into the spell, could not be done :)

Lua:
local items_spell = {
        [2433]    = {more_dmg_spell = 3},  -- Magic Staff                         z
        [7426]    = {more_dmg_spell = 3},  -- Radagast Staff                      z
        [7451]    = {more_dmg_spell = 5},  -- Shadow Spectre                      z
        [12318]    = {more_dmg_spell = 5},  -- Antibiotic Sceptre                 z
        [2518]    = {more_dmg_spell = 4},  -- Beholder Shield                     x
        [8918]    = {more_dmg_spell = 6},   -- Spellbook of dark Mesterious        x
        [9778]    = {more_dmg_spell = 4},  -- Yalahari Mask                       y
        [2343]    = {more_dmg_spell = 4} -- Helmet of The Ancients              y
     
}

local function getExtraDamage(cid)
 
    local damage = {more_dmg_spell = 0}
        for slot = 1, 10 do
            local item = getPlayerSlotItem(cid, slot)
                if item then
                    tmp = items_spell[item.itemid]
                        if tmp then
                            damage.more_dmg_spell = damage.more_dmg_spell + tmp.more_dmg_spell
                        end
                end
        end
        print(damage.more_dmg_spell)
return damage
end

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)


local arr = {
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 0, 1, 0, 0},
{0, 1, 1, 3, 1, 1, 0},
{0, 0, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0}
}


local area = createCombatArea(arr)
setCombatArea(combat, area)

function onGetFormulaValues(cid, level, maglevel)

    local damage = getExtraDamage(cid)
    damagecombat = ((damage.more_dmg_spell/100)+1)
 
    maglevel = getPlayerMagLevel(cid)
    level = getPlayerLevel(cid)

return -((YOUR MAGIC FORMULA)*damagecombat) -- 30% more-->
end

setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onCastSpell(cid, var)
return doCombat(cid, combat, var)
end
 
Back
Top