• 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},  --...
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 t.up[item.itemid] then
        return true
    end
    local item = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    if item and t.up[item.itemid] then
        return true
    end
    local item = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
    if item and t.up[item.itemid] 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 item = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
  local item = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
   local item = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
 
local k = t.up[item.itemid]
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

It find the item now but I get the error:

Code:
[15:28:45.020] [Error - CreatureScript Interface]
[15:28:45.038] data/creaturescripts/scripts/MoreDMG.lua:onStatsChange
[15:28:45.040] Description:
[15:28:45.042] data/creaturescripts/scripts/MoreDMG.lua:36: attempt to index local 'k' (a nil value)
[15:28:45.042] stack traceback:
[15:28:45.042]  data/creaturescripts/scripts/MoreDMG.lua:36: in function <data/creaturescripts/scripts/MoreDMG.lua:29>
 
Last edited:
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 t.up[item.itemid] then
        return true
    end
    local item = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    if item and t.up[item.itemid] then
        return true
    end
    local item = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
    if item and t.up[item.itemid] 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 item = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
  local item = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
   local item = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
 
local k = t.up[item.itemid]
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

It find the item now but I get the error:

Code:
[15:28:45.020] [Error - CreatureScript Interface]
[15:28:45.038] data/creaturescripts/scripts/MoreDMG.lua:onStatsChange
[15:28:45.040] Description:
[15:28:45.042] data/creaturescripts/scripts/MoreDMG.lua:36: attempt to index local 'k' (a nil value)
[15:28:45.042] stack traceback:
[15:28:45.042]  data/creaturescripts/scripts/MoreDMG.lua:36: in function <data/creaturescripts/scripts/MoreDMG.lua:29>
1 variable cant hold 3 values
Lua:
local cfg = {
    storage = 5011,
    items = {
        [2518] = {more_dmg = 7, more_dmg_spell = 5},
        [9778] = {more_dmg = 4, more_dmg_spell = 3}
    }
}

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

local storage = 815500 -- make sure stack overflow doesn't happen

function onStatsChange(cid, attacker, type, combat, value)
    local damage = searchExtraDamage(cid)
    if not (damage.more_dmg > 0 and damage.more_dmg_spell > 0) then
        return true -- return true early, no point in executing below code if the player has no extra damage items
    end
    if isPlayer(attacker) and getPlayerStorageValue(attacker, cfg.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
                    value = value * 2 + ((value * 2) * damage.more_dmg/100)
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
                else
                    value = value * 2 + ((value * 2) * damage.more_dmg_spell/100)
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
                end
                return false -- cancel the initial damage
            else
                doPlayerSetStorageValue(cid, storage, -1)
            end
        end
    end
    return true
end
 
Lua:
local cfg = {
    storage = 5011,
    items = {
        [2518] = {more_dmg = 7, more_dmg_spell = 5},
        [9778] = {more_dmg = 4, more_dmg_spell = 3}
    }
}
local function searchExtraDamage(cid)
print("searchExtraDamage")
    local damage = {more_dmg = 0, more_dmg_spell = 0}
    for slot = 1, 10 do
        local item = getPlayerSlotItem(cid, slot)
        if item then
            local tmp = cfg.items[item.itemid]
            if tmp then
                damage.more_dmg = damage.more_dmg + tmp.more_dmg
                damage.more_dmg_spell = damage.more_dmg + tmp.more_dmg_spell
            end
        end
    end
    return damage
end
local storage = 815500 -- make sure stack overflow doesn't happen
function onStatsChange(cid, attacker, type, combat, value)
print("start statschange execution")
    local damage = searchExtraDamage(cid)
    local value = value * 2 + ((value * 2) * damage.more_dmg/100)
    local value2 = value * 2 + ((value * 2) * damage.more_dmg_spell/100)
    if not (damage.more_dmg > 0 and damage.more_dmg_spell > 0) then
print("Damage not > 0")
        return true -- return true early, no point in executing below code if the player has no extra damage items
    end
    if isPlayer(attacker) and getPlayerStorageValue(attacker, cfg.storage) == 1 then
    print("statement 1 passed")
        if (type == STATSCHANGE_HEALTHLOSS or STATSCHANGE_MANALOSS) and checkDamageIncrease(attacker) then
        print("statement 2 passed")
            if getPlayerStorageValue(cid, storage) == -1 then
             print("statement 3 passed")
                doPlayerSetStorageValue(cid, storage, 1) -- set storage value before the creature takes another hit to avoid overflow
                if (combat == COMBAT_PHYSICALDAMAGE) then
                print("physical damage")
                return false,
               
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
                else
                print("other damage")
                return false,
              
                    doTargetCombatHealth(attacker, cid, combat, -value2, -value2, 255)
                end
           
            else
                doPlayerSetStorageValue(cid, storage, -1)
            end
        end
          print("end execution // return false")
    end
     print("end execution // return true")
    return true
end

Code:
start statschange execution
searchExtraDamage
Damage not > 0
start statschange execution
searchExtraDamage
Damage not > 0
I think that extra damage isn't added at searchExtraDamage function
@Edit
The mistake is here:
Lua:
 local damage = {more_dmg = 0, more_dmg_spell = 0}
If I change the values here than for each item the value will change according with it.
 
Last edited:
Lua:
local cfg = {
    storage = 5011,
    items = {
        [2518] = {more_dmg = 7, more_dmg_spell = 5},
        [9778] = {more_dmg = 4, more_dmg_spell = 3}
    }
}
local function searchExtraDamage(cid)
print("searchExtraDamage")
    local damage = {more_dmg = 0, more_dmg_spell = 0}
    for slot = 1, 10 do
        local item = getPlayerSlotItem(cid, slot)
        if item then
            local tmp = cfg.items[item.itemid]
            if tmp then
                damage.more_dmg = damage.more_dmg + tmp.more_dmg
                damage.more_dmg_spell = damage.more_dmg + tmp.more_dmg_spell
            end
        end
    end
    return damage
end
local storage = 815500 -- make sure stack overflow doesn't happen
function onStatsChange(cid, attacker, type, combat, value)
print("start statschange execution")
    local damage = searchExtraDamage(cid)
    local value = value * 2 + ((value * 2) * damage.more_dmg/100)
    local value2 = value * 2 + ((value * 2) * damage.more_dmg_spell/100)
    if not (damage.more_dmg > 0 and damage.more_dmg_spell > 0) then
print("Damage not > 0")
        return true -- return true early, no point in executing below code if the player has no extra damage items
    end
    if isPlayer(attacker) and getPlayerStorageValue(attacker, cfg.storage) == 1 then
    print("statement 1 passed")
        if (type == STATSCHANGE_HEALTHLOSS or STATSCHANGE_MANALOSS) and checkDamageIncrease(attacker) then
        print("statement 2 passed")
            if getPlayerStorageValue(cid, storage) == -1 then
             print("statement 3 passed")
                doPlayerSetStorageValue(cid, storage, 1) -- set storage value before the creature takes another hit to avoid overflow
                if (combat == COMBAT_PHYSICALDAMAGE) then
                print("physical damage")
                return false,
               
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
                else
                print("other damage")
                return false,
              
                    doTargetCombatHealth(attacker, cid, combat, -value2, -value2, 255)
                end
           
            else
                doPlayerSetStorageValue(cid, storage, -1)
            end
        end
          print("end execution // return false")
    end
     print("end execution // return true")
    return true
end

Code:
start statschange execution
searchExtraDamage
Damage not > 0
start statschange execution
searchExtraDamage
Damage not > 0
I think that extra damage isn't added at searchExtraDamage function
Add "break" on a new line, after line 19's end.

err actually.. just replace..
Lua:
local function searchExtraDamage(cid)
   local damage = {more_dmg = 0, more_dmg_spell = 0}
   for slot = 1, 10 do
       local item = getPlayerSlotItem(cid, slot)
       if item then
           local tmp = cfg.items[item.itemid]
           if tmp then
               damage.more_dmg = damage.more_dmg + tmp.more_dmg
               damage.more_dmg_spell = damage.more_dmg + tmp.more_dmg_spell
           end
       end
   end
   return damage
end
with this
Lua:
local function searchExtraDamage(cid)
   local damage = {more_dmg = 0, more_dmg_spell = 0}
   for slot = 1, 10 do
       local item = getPlayerSlotItem(cid, slot)
       if item then
           local tmp = cfg.items[item.itemid]
           if tmp then
               damage.more_dmg = damage.more_dmg + tmp.more_dmg
               damage.more_dmg_spell = damage.more_dmg + tmp.more_dmg_spell
           end
       end
       break
   end
   return damage
end
 
It doesn't work, if I have declared item equiped or not the damge is always caluclated according to this line:
Lua:
local damage = {more_dmg = 0, more_dmg_spell = 0}

If I set there for example 20 then every damge in game is increased about 20%
 
i don't see any errors but replace searchExtraDamage with this and tell me what it prints
Lua:
local function searchExtraDamage(cid)
    local damage = {more_dmg = 0, more_dmg_spell = 0}
    for slot = 1, 10 do
        local item = getPlayerSlotItem(cid, slot)
        if item then
            local tmp = cfg.items[item.itemid]
            if tmp then
                print("adding damage")
                damage.more_dmg = damage.more_dmg + tmp.more_dmg
                damage.more_dmg_spell = damage.more_dmg + tmp.more_dmg_spell
            end
        end
    end
    print(damage.more_dmg, damage.more_dmg_spell)
    return damage
end
 
put print(item.itemid) under if item then
no idea why it wouldnt work unless you just didnt have it equipped which i doubt
 
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},  -- Yalahari Mask                       y
        [2343]    = {more_dmg = 4,  more_dmg_spell = 2}} -- Helmet of The Ancients              y
 
}
local function searchExtraDamage(cid)
    local damage = {more_dmg = 0, more_dmg_spell = 0}
    for slot = 1, 10 do
        local item = getPlayerSlotItem(cid, slot)
        if item then
        print(item.itemid)
            local tmp = cfg.items[item.itemid]
            if tmp then
                print("adding damage")
                damage.more_dmg = damage.more_dmg + tmp.more_dmg
                damage.more_dmg_spell = damage.more_dmg + tmp.more_dmg_spell
            end
        end
    end
    print(damage.more_dmg, damage.more_dmg_spell)
    return damage
end
local storage = 815500 -- make sure stack overflow doesn't happen
function onStatsChange(cid, attacker, type, combat, value)
    local damage = searchExtraDamage(cid)
    if not (damage.more_dmg > 0 and damage.more_dmg_spell > 0) then
        return true -- return true early, no point in executing below code if the player has no extra damage items
    end
    if isPlayer(attacker) then
        if (type == STATSCHANGE_HEALTHLOSS or STATSCHANGE_MANALOSS) and searchExtraDamage(cid) 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
                    value = value * 2 + ((value * 2) * damage.more_dmg/100)
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
              
                else
                    value = value * 2 + ((value * 2) * damage.more_dmg_spell/100)
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
              
                end
                return false -- cancel the initial damage
            else
                doPlayerSetStorageValue(cid, storage, -1)
            end
        end
    end
    return true
end

In this case script works in some way but the damage added is wrong and there is constant repeating error in the console:

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},  -- Yalahari Mask                       y
        [2343]    = {more_dmg = 4,  more_dmg_spell = 2}, -- Helmet of The Ancients              y
        [2344]    = {more_dmg = 4,  more_dmg_spell = 2}} -- Helmet of The Ancients              y
 
}
local function searchExtraDamage(attacker)
    local damage = {more_dmg = 0, more_dmg_spell = 0}
    for slot = 1, 10 do
        local item = getPlayerSlotItem(attacker, slot)
        if item then
        print(item.itemid)
            local tmp = cfg.items[item.itemid]
            if tmp then
                print("adding damage")
                damage.more_dmg = damage.more_dmg + tmp.more_dmg
                damage.more_dmg_spell = damage.more_dmg + tmp.more_dmg_spell
            end
        end
    end
    print(damage.more_dmg, damage.more_dmg_spell)
    return damage
end
local storage = 815500 -- make sure stack overflow doesn't happen
function onStatsChange(cid, attacker, type, combat, value)
    local damage = searchExtraDamage(attacker)
    if not (damage.more_dmg > 0 and damage.more_dmg_spell > 0) then
        return true -- return true early, no point in executing below code if the player has no extra damage items
    end
    if isPlayer(attacker) then
        if (type == STATSCHANGE_HEALTHLOSS or STATSCHANGE_MANALOSS) and searchExtraDamage(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
                    value = value * 2 + ((value * 2) * damage.more_dmg/100)
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
               
                else
                    value = value * 2 + ((value * 2) * damage.more_dmg_spell/100)
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
               
                end
                return false -- cancel the initial damage
            else
                doPlayerSetStorageValue(cid, storage, -1)
            end
        end
    end
    return true
end

Code:
2173
1988
2494
8918
adding damage
0
2647
2640
0
0
10
16

2173
1988
2494
8918
adding damage
0
2647
2640
0
0
10
16

[17:30:15.502] [Error - CreatureScript Interface]
[17:30:15.502] data/creaturescripts/scripts/MoreDMG.lua:onStatsChange
[17:30:15.502] Description:
[17:30:15.502] (luaGetPlayerSlotItem) Player not found
0


[17:30:15.502] [Error - CreatureScript Interface]
[17:30:15.502] data/creaturescripts/scripts/MoreDMG.luanStatsChange
[17:30:15.502] Description:
[17:30:15.502] (luaGetPlayerSlotItem) Player not found
0
0
0

The script found the item 8918 here and the rest of the items of the player who is attacking, so no idea why there is the error Player not found. For the item 8918 script should increase damage and magic damage about 6 and it is respectively 10 and 16 . The values like those are not even in the table???
 
Last edited:
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},  -- Yalahari Mask                       y
        [2343]    = {more_dmg = 4,  more_dmg_spell = 2}} -- Helmet of The Ancients              y
 
}
local function searchExtraDamage(cid)
    local damage = {more_dmg = 0, more_dmg_spell = 0}
    for slot = 1, 10 do
        local item = getPlayerSlotItem(cid, slot)
        if item then
        print(item.itemid)
            local tmp = cfg.items[item.itemid]
            if tmp then
                print("adding damage")
                damage.more_dmg = damage.more_dmg + tmp.more_dmg
                damage.more_dmg_spell = damage.more_dmg + tmp.more_dmg_spell
            end
        end
    end
    print(damage.more_dmg, damage.more_dmg_spell)
    return damage
end
local storage = 815500 -- make sure stack overflow doesn't happen
function onStatsChange(cid, attacker, type, combat, value)
    local damage = searchExtraDamage(cid)
    if not (damage.more_dmg > 0 and damage.more_dmg_spell > 0) then
        return true -- return true early, no point in executing below code if the player has no extra damage items
    end
    if isPlayer(attacker) then
        if (type == STATSCHANGE_HEALTHLOSS or STATSCHANGE_MANALOSS) and searchExtraDamage(cid) 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
                    value = value * 2 + ((value * 2) * damage.more_dmg/100)
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
             
                else
                    value = value * 2 + ((value * 2) * damage.more_dmg_spell/100)
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
             
                end
                return false -- cancel the initial damage
            else
                doPlayerSetStorageValue(cid, storage, -1)
            end
        end
    end
    return true
end

In this case script works in some way but the damage added is wrong and there is constant repeating error in the console:

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},  -- Yalahari Mask                       y
        [2343]    = {more_dmg = 4,  more_dmg_spell = 2}, -- Helmet of The Ancients              y
        [2344]    = {more_dmg = 4,  more_dmg_spell = 2}} -- Helmet of The Ancients              y
 
}
local function searchExtraDamage(attacker)
    local damage = {more_dmg = 0, more_dmg_spell = 0}
    for slot = 1, 10 do
        local item = getPlayerSlotItem(attacker, slot)
        if item then
        print(item.itemid)
            local tmp = cfg.items[item.itemid]
            if tmp then
                print("adding damage")
                damage.more_dmg = damage.more_dmg + tmp.more_dmg
                damage.more_dmg_spell = damage.more_dmg + tmp.more_dmg_spell
            end
        end
    end
    print(damage.more_dmg, damage.more_dmg_spell)
    return damage
end
local storage = 815500 -- make sure stack overflow doesn't happen
function onStatsChange(cid, attacker, type, combat, value)
    local damage = searchExtraDamage(attacker)
    if not (damage.more_dmg > 0 and damage.more_dmg_spell > 0) then
        return true -- return true early, no point in executing below code if the player has no extra damage items
    end
    if isPlayer(attacker) then
        if (type == STATSCHANGE_HEALTHLOSS or STATSCHANGE_MANALOSS) and searchExtraDamage(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
                    value = value * 2 + ((value * 2) * damage.more_dmg/100)
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
              
                else
                    value = value * 2 + ((value * 2) * damage.more_dmg_spell/100)
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
              
                end
                return false -- cancel the initial damage
            else
                doPlayerSetStorageValue(cid, storage, -1)
            end
        end
    end
    return true
end

Code:
2173
1988
2494
8918
adding damage
0
2647
2640
0
0
10
16

2173
1988
2494
8918
adding damage
0
2647
2640
0
0
10
16

[17:30:15.502] [Error - CreatureScript Interface]
[17:30:15.502] data/creaturescripts/scripts/MoreDMG.lua:onStatsChange
[17:30:15.502] Description:
[17:30:15.502] (luaGetPlayerSlotItem) Player not found
0


[17:30:15.502] [Error - CreatureScript Interface]
[17:30:15.502] data/creaturescripts/scripts/MoreDMG.luanStatsChange
[17:30:15.502] Description:
[17:30:15.502] (luaGetPlayerSlotItem) Player not found
0
0
0

The script found the item 8918 here and the rest of the items of the player who is attacking, so no idea why there is the error Player not found. For the item 8918 script should increase damage and magic damage about 6 and it is respectively 10 and 16 . The values like those are not even in the table???
AH IM STUPID
Lua:
local cfg = {
    storage = 5011,
    items = {
        [2518] = {more_dmg = 7, more_dmg_spell = 5},
        [9778] = {more_dmg = 4, more_dmg_spell = 3}
    }
}

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

local storage = 815500 -- make sure stack overflow doesn't happen

function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(attacker) and getPlayerStorageValue(attacker, cfg.storage) == 1 then
        local damage = searchExtraDamage(attacker)
        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
                    value = value * 2 + ((value * 2) * damage.more_dmg/100)
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
                else
                    value = value * 2 + ((value * 2) * damage.more_dmg_spell/100)
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
                end
                return false -- cancel the initial damage
            else
                doPlayerSetStorageValue(cid, storage, -1)
            end
        end
    end
    return true
end
 
Solution
I have to admit that before your first post I didn't belive it can be done but to my amazment it works perfect now :D
Dude , you are really great scripter!
Thank you very very much :)
 
Last edited:
AH IM STUPID
Lua:
local cfg = {
    storage = 5011,
    items = {
        [2518] = {more_dmg = 7, more_dmg_spell = 5},
        [9778] = {more_dmg = 4, more_dmg_spell = 3}
    }
}

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

local storage = 815500 -- make sure stack overflow doesn't happen

function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(attacker) and getPlayerStorageValue(attacker, cfg.storage) == 1 then
        local damage = searchExtraDamage(attacker)
        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
                    value = value * 2 + ((value * 2) * damage.more_dmg/100)
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
                else
                    value = value * 2 + ((value * 2) * damage.more_dmg_spell/100)
                    doTargetCombatHealth(attacker, cid, combat, -value, -value, 255)
                end
                return false -- cancel the initial damage
            else
                doPlayerSetStorageValue(cid, storage, -1)
            end
        end
    end
    return true
end
Took me awhile to compare the two scripts, but that's pretty funny. lol
 
This is not the correct way to do this... You wont be able to make spells that deal physical damage because it will act like a weapon, and you cant make weapons hit anything but physical damage or it will act as a spell...

The correct way would be adding a code into each spell file and weapon file that adds the dmg based on the items he has equip.

Here is an example...

For each of your spells you would add this at the top...

Lua:
local items_spell = {
[1111] = 5,
[1111] = 7
}

local combat_type = COMBAT_ICEDAMAGE --So the extra damage is the same color/type as the actual spell dmg.--

local function getExtraDamage(cid)
    local dmg_inc = 0
        for slot = 1, 10 do
            local item = getPlayerSlotItem(cid, slot)
                if item then
                    ITEM = items_spell[item]
                        if ITEM then
                            dmg_inc = dmg_inc + ITEM
                        end
                end
        end
return dmg_inc
end

then add this in the body of the onCastSpell(cid, var) above doCombat(cid, var, combat).

Lua:
if isPlayer(cid) then
        local dmg_inc = getExtraDamage(cid)
        doTargetCombatHealth(cid, var, combat_type, -dmg_inc, -dmg_inc, 255)
    end
 
Last edited by a moderator:
There is indeed a problem at the first solution, because if player has active mana shield the script damages only mana points of the player even if mana is exhausted and I have no idea how to fix it.

Lua:
if isPlayer(cid) then
        local dmg_inc = getExtraDamage(cid)
        doTargetCombatHealth(cid, var, combat_type, -dmg_inc, -dmg_inc, 255)
    end

This part unfortunately does not work, bacause target can not be found for some reasons, so I put the dmg_inc to the formula of the spell and now finally is perfect :)

@Edit Ok, I solved it in other way :)
 
Last edited:
To make mine work as it was (and I knew this but was lazy) you would need to do:

Code:
if isPlayer(cid) then
     local dmg_inc = getExtraDamage(cid)
     target = variantToNumber(var)
     doTargetCombatHealth(cid, target, combat_type, -dmg_inc, -dmg_inc, 255)
end

but if its solved then you are good to go.
 
Last edited:
To make mine work as it was (and I knew this but was lazy) you would need to do:

Code:
if isPlayer(cid) then
     local dmg_inc = getExtraDamage(cid)
     target = varientToNumber(var)
     doTargetCombatHealth(cid, target, combat_type, -dmg_inc, -dmg_inc, 255)
end

but if its solved then you are good to go.
variant not varient
 
Back
Top