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

RevScripts Spell with random target going through walls

farp

Member
Joined
Nov 18, 2022
Messages
20
Reaction score
8
As you can see, I have a spell that hits random targets in an area, but it ignores walls and other objects that should block a spell.

spectators wall.gif

Can anyone help with a solution for this?

the code uses Game.getSpectators to find the targets in the area



Here is the code of the spell, if anyone want to check it.
Lua:
local config = {targetNumber = 8}

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, 97)

function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.04) + 11
    local max = (player:getLevel() / 5) + (skill * attack * 0.08) + 21
    return -min, -max
end 

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")




local spell = Spell("instant")
function spell.onCastSpell(creature, variant)

    local spectators = Game.getSpectators(creature:getPosition(), false, false, 5, 5, 5, 5)
    local count = 0
    local rep = 0
    local targets = {}
    local playerPos = creature:getPosition()

    while count <= config.targetNumber do
        rep = rep +1
        local target = math.random(1, #spectators)
        local pos = spectators[target]:getPosition()
        local var = positionToVariant(pos)
        if var and not table.contains(targets, target) and spectators[target] ~= creature then
            targets[#targets +1] = target
            count = count+1         
            combat:execute(creature, var)
            var = nil 
        end     
        if rep > 70 then
            count = config.targetNumber+1
        end
    end
    r
 

Attachments

  • spectators wall.gif
    spectators wall.gif
    301.1 KB · Views: 1 · VirusTotal
Lua:
if creature:getPosition():isSightClear(spectators[target]:getPosition()) then
    -- # code
end
thanks, that solved the problem!

for some reason, it doesn't show on your post the option to mark it as the best answer
 
Last edited:
Back
Top