• 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.2 how to edit this spell so every creature could cast this spell

Lopaskurwa

Active Member
Joined
Oct 6, 2017
Messages
873
Solutions
2
Reaction score
49
Hi,
how can i make so even monsters could cast this spell? because now it executes only for players
Lua:
local minTargets = 1
local thunderstorm = 28001 -- Storage used for thunderstorm cooldown
local duration = 6000 -- 60 Lasts seconds
local ticks = 2000 -- Hits every 5 seconds

function shuffle(t)
    local rand = math.random
    assert(t, "table.shuffle() expected a table, got nil")
    local iterations = #t
    local j
  
    for i = iterations, 2, -1 do
        j = rand(i)
        t[i], t[j] = t[j], t[i]
    end
end
                  
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_YELLOWENERGY)

-- For exhaust on the first cast
local exhaust = Condition(CONDITION_EXHAUST)
exhaust:setParameter(CONDITION_PARAM_TICKS, 2000)

function thunderStormDuration(playeruid, count)
    -- Convert back to Player object
    local player = Player(playeruid)
    if player then -- If player still logged in
        local playerPos = player:getPosition()
        playerPos:sendMagicEffect(CONST_ME_YELLOWENERGY)
        local playerTile = Tile(Position(playerPos))
        if playerTile:hasFlag(TILESTATE_PROTECTIONZONE) == false and playerTile:hasFlag(TILESTATE_HOUSE) == false then -- if player not in PZ
            local targets = Game.getSpectators(playerPos, false, false, 7, 7, 5, 5)
            -- Shuffle targets table
            if targets then
                if #targets > 1 then
                    shuffle(targets)
                end
            end
            -- Strike targets
            local validTargets = {}
            local level = player:getLevel()
            local maglevel = player:getMagicLevel()
            local targetCount = minTargets + math.floor(maglevel / 20) -- Get extra target every 20 magic levels
            for k,v in pairs(targets) do
                -- Only target monsters
                if v:isMonster() then
                    local monsterPos = v:getPosition()
                    if monsterPos:isSightClear(playerPos) then
                        local currentTargets = #validTargets or 0
                        if currentTargets < targetCount then
                            table.insert(validTargets, v)
                        end
                    end
                end
            end
            if validTargets then
                for i = 1,#validTargets do
                    -- Animation
                    local monsterPos = validTargets[i]:getPosition()
                    monsterPos:sendMagicEffect(CONST_ME_BIGCLOUDS)
                    monsterPos.y = monsterPos.y - 1
                    monsterPos:sendMagicEffect(CONST_ME_BIGCLOUDS)
                    monsterPos.y = monsterPos.y + 2
                    monsterPos:sendMagicEffect(CONST_ME_BIGCLOUDS)
                    monsterPos.x = monsterPos.x - 1
                    monsterPos.y = monsterPos.y - 1
                    monsterPos:sendMagicEffect(CONST_ME_BIGCLOUDS)
                    monsterPos.x = monsterPos.x + 2
                    monsterPos:sendMagicEffect(CONST_ME_BIGCLOUDS)
                    -- Damage Formula
                    local min = (level / 5) + (maglevel * 1.4) + 15
                    local max = (level / 5) + (maglevel * 2.0) + 35
                    combat:setFormula(COMBAT_FORMULA_LEVELMAGIC, 0, -min, 0, -max)  
                    combat:execute(player, Variant(validTargets[i].uid)) -- Strike Monster
                end
            end
        end
        -- Repeat until count reaches 0
        local counter = count - 1
        if counter > 0 then
            addEvent(thunderStormDuration, ticks, playeruid, counter)
        else
            player:setStorageValue(thunderstorm, -1)
        end
    else
        return false
    end
end

function onCastSpell(creature, var, isHotkey)
    print(0)
    if not creature:isMonster() then
        print(1)
        local position = creature:getPosition()
        print(2)
        if creature:getCondition(CONDITION_EXHAUST) then
            print(3)
            creature:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_YOUAREEXHAUSTED))
            print(4)
            position:sendMagicEffect(CONST_ME_POFF)
            print(5)
            return false
        end    

        local thunderstormExhaust = creature:getStorageValue(thunderstorm)
        print(6)
        if thunderstormExhaust ~= -1 and thunderstormExhaust > os.time() then
            print(7)
            creature:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_YOUAREEXHAUSTED))
            print(8)
            position:sendMagicEffect(CONST_ME_POFF)
            print(9)
            return false
        end
        print(10)

        creature:setStorageValue(thunderstorm, os.time() + duration)
        print(11)
        creature:addCondition(exhaust) -- Only exhaust on original cast
        print(12)
    end
    print(13)
    addEvent(thunderStormDuration, 0, creature.uid, math.floor(duration / ticks))
    print(14)
    return true
end
 
so it gives errors saying getstoragevalue is a nil value

Remove everything related to storage values, or add a if creature:isMonster() then at the end and copy stuff into there.
Probably the latter since doing the former would break the exhaust system for players as well (unless you make so that only monsters can cast the spell).
 
Back
Top