• 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 How to properly code formulas into a config section

aalqaq2

Trying to help, but I'm not too good at it.
Joined
Apr 10, 2017
Messages
112
Solutions
3
Reaction score
8
TFS 1.3
I need to know how to code
Lua:
local min = (level / 5) + (maglevel * 4.3) + 32
local max = (level / 5) + (maglevel * 7.4) + 48
into
Lua:
local config = {
     damage = {-min, -max},
}

Here's the rest of the code.
Lua:
function doAreaCombatDamage(cid, attacker, combatType, position, min, max, effect)
     local creature = Creature(cid)--// Incase the creature disappears within 120-250ms time window
 
     if not creature then
        return
     end
 
    doAreaCombatHealth(attacker, combatType, position, 0, min, max, effect)

end

    local running = {}

local function runSpell(cid, i, j, delay, radius, damage, damageType, areaEffect, distanceEffect)
     local player = Player(cid)--// Player doesn't exist anymore
     if not player or Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) and bit.band(player:getGroup():getFlags(), PlayerFlag_IgnoreProtectionZone) == 0 then
         stopEvent(running[cid])
         running[cid] = nil
         return
     end

    if i > j then--// Maximum rounds complete
        stopEvent(running[cid])
        running[cid] = nil
        return
end

    local center = player:getPosition()
    local specs = Game.getSpectators(center, false, false, radius.x, radius.x, radius.y, radius.y)
    local args = {nil, cid, damageType, nil, damage.min, damage.max, areaEffect}--// Send effects and damage creatures within radius
     for i = 1, #specs do
         if specs[i]:isMonster() then
         local specPos = specs[i]:getPosition()
         args[1] = specs[i]:getId()
         args[4] = specPos
         center:sendDistanceEffect(specPos, distanceEffect)
         addEvent(doAreaCombatDamage, 120 + (center:getDistance(specPos) * 7), unpack(args))
        end
    end
        addEvent(runSpell, delay, cid, i+1, j, delay, radius, damage, damageType, areaEffect, distanceEffect)
end

    local offsets = {DIRECTION_WEST, DIRECTION_NORTH, DIRECTION_EAST, DIRECTION_SOUTH}
    local function sendEffects(cid, delay, areaEffect, distanceEffect)
    local player = Player(cid)

    if not player or Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) and bit.band(player:getGroup():getFlags(), PlayerFlag_IgnoreProtectionZone) == 0 then
        stopEvent(running[cid])
        running[cid] = nil
        return
    end

        local pos = player:getPosition()
         for i = 1, #offsets do--// Send distance effects (N/E/S/W) & area effect on player
               local fromPos = pos:setDirectionOffset(offsets[i])
               local fromPos = pos:setDirectionOffset(player:getPosition())
               local toPos = pos:setDirectionOffset(offsets[i+1] or offsets[1])
  fromPos:sendDistanceEffect(toPos, distanceEffect)
         end
 
        pos:sendMagicEffect(areaEffect)
        running[cid] = addEvent(sendEffects, delay, cid, delay, areaEffect, distanceEffect)
end

local config = {
    damage = {min = -68, max = -136}, -------THIS IS THE LINE I WANT TO CHANGE
    rounds = 30, -- number of times the spell loops (effects & damage)
    delay = 320, -- ms
    radius = {x = 5, y = 5}, -- sqm radius
    damageType = COMBAT_DEATHDAMAGE,
    areaEffect = CONST_ME_MORTAREA,
    distanceEffect = CONST_ANI_DEATH,
}

function onCastSpell(cid, creature, variant)
    local player = Player(cid)
    if not player then
        return false
    end
 
    sendEffects(player:getId(), config.delay, config.areaEffect, config.distanceEffect)
    runSpell(player:getId(), 0, config.rounds, config.delay, config.radius, config.damage, config.damageType, config.areaEffect, config.distanceEffect)
     return true
end

The closest I could get was the spell working but no damage being dealt.
 
Last edited by a moderator:
Back
Top