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

EnergyDamge by % with table

henkas

Well-Known Member
Joined
Jul 8, 2015
Messages
1,055
Solutions
5
Reaction score
62
Hi,
i have this custom item creaturescript when you wear item you get like 5% more dmg with ENERGYDAMAGE, but it would be better to improve it with more customizable code so i could add more items into this table and adjust %, so for example code looks like this now
LUA:
local specialRings = {1526}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
  if creature and attacker then
    if attacker:isPlayer() then
      local ring = attacker:getSlotItem(CONST_SLOT_RING)
      if ring and primaryType == COMBAT_ENERGYDAMAGE then
        if table.contains(specialRings, ring.itemid) then
          local tmpDamage = primaryDamage
          primaryDamage = primaryDamage * 1.05
        end
      end
    end
  end
  return primaryDamage, primaryType, secondaryDamage, secondaryType
end

And it would be nice to have something like this
Code:
local specialRings = {
      [ITEMID] = {PrecentDamage = 6, Slot = Legs}},
      [ITEMID] = {PrecentDamage = 2, Slot = Amulet}},
      [ITEMID] = {PrecentDamage = 22, Slot = Feet}}
},
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
  if creature and attacker then
    if attacker:isPlayer() then
      local ring = attacker:getSlotItem(CONST_SLOT_RING)
      if ring and primaryType == COMBAT_ENERGYDAMAGE then
        if table.contains(specialRings, ring.itemid) then
          local tmpDamage = primaryDamage
          primaryDamage = primaryDamage * 1.05
        end
      end
    end
  end
  return primaryDamage, primaryType, secondaryDamage, secondaryType
end
So it would be possible to add more items into this table with custom damage precent increase. TFS 1.2
 
Solution
LUA:
local specialItems = {
    [1000] = {PercentDamage = 6},
    [1001] = {PercentDamage = 2},
    [1002] = {PercentDamage = 2}
}

-- add more slots to check here
local checkslots = {
    CONST_SLOT_RING,
    CONST_SLOT_NECKLACE,
    CONST_SLOT_LEGS,
    CONST_SLOT_ARMOR,
    CONST_SLOT_HEAD,
    CONST_SLOT_FEET
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature and attacker then
        if attacker:isPlayer() then
            local extraDmg = 0
            for i = 1,#checkslots do
                local slotitem = attacker:getSlotItem(checkslots[i])
                if slotitem and primaryType == COMBAT_ENERGYDAMAGE then
                    for k,v in...
LUA:
local specialItems = {
    [1000] = {PercentDamage = 6},
    [1001] = {PercentDamage = 2},
    [1002] = {PercentDamage = 2}
}

-- add more slots to check here
local checkslots = {
    CONST_SLOT_RING,
    CONST_SLOT_NECKLACE,
    CONST_SLOT_LEGS,
    CONST_SLOT_ARMOR,
    CONST_SLOT_HEAD,
    CONST_SLOT_FEET
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature and attacker then
        if attacker:isPlayer() then
            local extraDmg = 0
            for i = 1,#checkslots do
                local slotitem = attacker:getSlotItem(checkslots[i])
                if slotitem and primaryType == COMBAT_ENERGYDAMAGE then
                    for k,v in pairs(specialItems) do
                        if k == slotitem.itemid then
                            -- add up all combined extraDmg here (if wearing multiple specialItems)
                            extraDmg = extraDmg + ((v.PercentDamage / 100) * primaryDamage)
                        end
                    end
                end
            end
            -- add combined extraDmg here
            primaryDamage = primaryDamage + extraDmg
        end
    end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end

Edit: I've edited this a bit, so re-copy and try again if the damage isn't applying.
 
Last edited:
Solution
LUA:
local specialItems = {
    [1000] = {PercentDamage = 6},
    [1001] = {PercentDamage = 2},
    [1002] = {PercentDamage = 2}
}

-- add more slots to check here
local checkslots = {
    CONST_SLOT_RING,
    CONST_SLOT_NECKLACE,
    CONST_SLOT_LEGS,
    CONST_SLOT_ARMOR,
    CONST_SLOT_HEAD,
    CONST_SLOT_FEET
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature and attacker then
        if attacker:isPlayer() then
            local extraDmg = 0
            for i = 1,#checkslots do
                local slotitem = attacker:getSlotItem(checkslots[i])
                if slotitem and primaryType == COMBAT_ENERGYDAMAGE then
                    local slotitemid = slotitem:getId()
                    for k,v in pairs(specialItems) do
                        if k == slotitemid then
                            -- add up all combined extraDmg here (if wearing multiple specialItems)
                            extraDmg = extraDmg + ((v.PercentDamage / 100) * primaryDamage)
                        end
                    end
                end
            end
            -- add combined extraDmg here
            primaryDamage = primaryDamage + extraDmg
        end
    end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
Untitled.png
 
My hunch is you didn't copy over the top bit after I edited it so PercentDamage is spelled incorrectly like in your original post:

Does your shit say this?
LUA:
local specialItems = {
    [1000] = {PercentDamage = 6},
    [1001] = {PercentDamage = 2},
    [1002] = {PercentDamage = 2}
}

or this:
LUA:
local specialItems = {
    [1000] = {PrecentDamage = 6},
    [1001] = {PrecentDamage = 2},
    [1002] = {PrecentDamage = 2}
}
 
My hunch is you didn't copy over the top bit after I edited it so PercentDamage is spelled incorrectly like in your original post:

Does your shit say this?
LUA:
local specialItems = {
    [1000] = {PercentDamage = 6},
    [1001] = {PercentDamage = 2},
    [1002] = {PercentDamage = 2}
}

or this:
LUA:
local specialItems = {
    [1000] = {PrecentDamage = 6},
    [1001] = {PrecentDamage = 2},
    [1002] = {PrecentDamage = 2}
}
Yea i didnt copied top but there is no difference in them
LUA:
local specialItems = {
    [15773] = {PrecentDamage = 6},
    [15781] = {PrecentDamage = 6},
    [15782] = {PrecentDamage = 6},
    [15783] = {PrecentDamage = 6},
    [15792] = {PrecentDamage = 3},
    [15791] = {PrecentDamage = 3}
}


-- add more slots to check here
local checkslots = {
    CONST_SLOT_RING,
    CONST_SLOT_NECKLACE,
    CONST_SLOT_LEGS,
    CONST_SLOT_ARMOR,
    CONST_SLOT_HEAD,
    CONST_SLOT_FEET
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if creature and attacker then
        if attacker:isPlayer() then
            local extraDmg = 0
            for i = 1,#checkslots do
                local slotitem = attacker:getSlotItem(checkslots[i])
                if slotitem and primaryType == COMBAT_ENERGYDAMAGE then
                    for k,v in pairs(specialItems) do
                        if k == slotitem.itemid then
                            -- add up all combined extraDmg here (if wearing multiple specialItems)
                            extraDmg = extraDmg + ((v.PercentDamage / 100) * primaryDamage)
                        end
                    end
                end
            end
            -- add combined extraDmg here
            primaryDamage = primaryDamage + extraDmg
        end
    end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
LUA:
local specialItems = {
    [15773] = {PrecentDamage = 6},
    [15781] = {PrecentDamage = 6},
    [15782] = {PrecentDamage = 6},
    [15783] = {PrecentDamage = 6},
    [15792] = {PrecentDamage = 3},
    [15791] = {PrecentDamage = 3}
}

PrecentDamage
PercentDamage

d2aa0137b334ef00b8f05f6de182ce5d.gif
 
Back
Top