• 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+ a nil value

alcapone

Member
Joined
Jan 13, 2021
Messages
89
Reaction score
10
Lua:
local function Formula(skill, level, attack)
local skillTotal = skill*attack
local levelTotal = level / 5
return {-(((skillTotal * 0.04) + 8) + (levelTotal)), -(((skillTotal * 0.09) + 13) + (levelTotal))}
end

local area = createCombatArea(AREA_SQUARE1X1)

local function getHighestSkillLevel(creature)
    local skillLevel = -1
    for skillType = SKILL_CLUB, SKILL_AXE do
        if skillLevel < creature:getEffectiveSkillLevel(skillType) then
            skillLevel = creature:getEffectiveSkillLevel(skillType)
        end
    end
    return skillLevel
end

function onCastSpell(creature, var)
 
  local weapon = creature:getSlotItem(CONST_SLOT_LEFT)
    local dmg = ItemType(weapon.itemid):getAttack()
    local edmg = elementalDamage(weapon.itemid)
    local skill = getHighestSkillLevel(creature)
    local level = creature:getLevel()
    local result = Formula(skill, level, dmg + edmg)
    local position = creature:getPosition()
    if getConfigInfo("removeWeaponCharges") == true and weapon:hasAttribute("charges") then
    local charges = weapon:getAttribute("charges")
    if charges == 1 then
    weapon:remove(1)
    else
    weapon:setAttribute("charges", charges-1)
    end
    end

    if dmg > 0 then
    doAreaCombatHealth(creature, COMBAT_PHYSICALDAMAGE, position, area, math.min(0, result[1] * dmg / (edmg + dmg)), math.min(0, result[2] * dmg / (edmg+dmg)), CONST_ME_HITAREA)
    end
    if edmg > 0 then
    doAreaCombatHealth(creature, ItemType(weapon.itemid):getElementType(), position, area, math.min(0, result[1] * edmg / (edmg + dmg)), math.min(0, result[2] * edmg / (edmg+dmg)), CONST_ME_HITAREA)
    end
    return true
end

attempt to index local 'weapon' (a nil value)
 
Solution
a simple weapon check should work:

Lua:
local function Formula(skill, level, attack)
local skillTotal = skill*attack
local levelTotal = level / 5
return {-(((skillTotal * 0.04) + 8) + (levelTotal)), -(((skillTotal * 0.09) + 13) + (levelTotal))}
end

local area = createCombatArea(AREA_SQUARE1X1)

local function getHighestSkillLevel(creature)
    local skillLevel = -1
    for skillType = SKILL_CLUB, SKILL_AXE do
        if skillLevel < creature:getEffectiveSkillLevel(skillType) then
            skillLevel = creature:getEffectiveSkillLevel(skillType)
        end
    end
    return skillLevel
end

function onCastSpell(creature, var)
 
    local weapon = creature:getSlotItem(CONST_SLOT_LEFT)
    if weapon then
        local dmg =...

Evil Puncker

prolonged absenteeism
TFS Developer
Joined
May 30, 2009
Messages
8,038
Solutions
215
Reaction score
3,878
a simple weapon check should work:

Lua:
local function Formula(skill, level, attack)
local skillTotal = skill*attack
local levelTotal = level / 5
return {-(((skillTotal * 0.04) + 8) + (levelTotal)), -(((skillTotal * 0.09) + 13) + (levelTotal))}
end

local area = createCombatArea(AREA_SQUARE1X1)

local function getHighestSkillLevel(creature)
    local skillLevel = -1
    for skillType = SKILL_CLUB, SKILL_AXE do
        if skillLevel < creature:getEffectiveSkillLevel(skillType) then
            skillLevel = creature:getEffectiveSkillLevel(skillType)
        end
    end
    return skillLevel
end

function onCastSpell(creature, var)
 
    local weapon = creature:getSlotItem(CONST_SLOT_LEFT)
    if weapon then
        local dmg = ItemType(weapon.itemid):getAttack()
        local edmg = elementalDamage(weapon.itemid)
        local skill = getHighestSkillLevel(creature)
        local level = creature:getLevel()
        local result = Formula(skill, level, dmg + edmg)
        local position = creature:getPosition()
        if getConfigInfo("removeWeaponCharges") == true and weapon:hasAttribute("charges") then
        local charges = weapon:getAttribute("charges")
        if charges == 1 then
        weapon:remove(1)
        else
        weapon:setAttribute("charges", charges-1)
        end
        end

        if dmg > 0 then
        doAreaCombatHealth(creature, COMBAT_PHYSICALDAMAGE, position, area, math.min(0, result[1] * dmg / (edmg + dmg)), math.min(0, result[2] * dmg / (edmg+dmg)), CONST_ME_HITAREA)
        end
        if edmg > 0 then
        doAreaCombatHealth(creature, ItemType(weapon.itemid):getElementType(), position, area, math.min(0, result[1] * edmg / (edmg + dmg)), math.min(0, result[2] * edmg / (edmg+dmg)), CONST_ME_HITAREA)
        end
    end
    return true
end
 
Solution
Top