TFS 1.X+ Spell area varying according to player position

Kanohn

Intermediate OT User
Joined
Aug 28, 2011
Messages
225
Reaction score
3
Hello!

I'll be very grateful if anyone can help me ..

I'm trying to make a beam spell that the area will vary according to player position:
Example:35345

The max range sqms is 4..

I have tried with callback to get targetPos - creaturePos but i don't know exactly how to send the spell on all sqms..

thanks in advance!
 

Itutorial

Advanced OT User
Joined
Dec 23, 2014
Messages
1,417
Reaction score
310
Make 8x spells check the targets position x and y compared to the players x and y to determine which spell to cast. This can all be done in one file. I would make the code but this isn't the request section and you didn't tell us what distro you are using or anything.
 

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
583
Reaction score
354
Location
United States
Hello!

I'll be very grateful if anyone can help me ..

I'm trying to make a beam spell that the area will vary according to player position:
Example:View attachment 35345

The max range sqms is 4..

I have tried with callback to get targetPos - creaturePos but i don't know exactly how to send the spell on all sqms..

thanks in advance!
There's are some variations you aren't addressing, like if the target is farther away but only offset by one SQM, this results in only a wave of 2 SQM. I did my best and this is what I came up with. During testing I had it set to target needed and range at 7.

Lua:
local combat = createCombatObject()

function Position:getDirectionTo(toPosition)
    local dir = NORTH
    if(self.x > toPosition.x) then
        dir = WEST
        if(self.y > toPosition.y) then
            dir = NORTHWEST
        elseif(self.y < toPosition.y) then
            dir = SOUTHWEST
        end
    elseif(self.x < toPosition.x) then
        dir = EAST
        if(self.y > toPosition.y) then
            dir = NORTHEAST
        elseif(self.y < toPosition.y) then
            dir = SOUTHEAST
        end
    else
        if(self.y > toPosition.y) then
            dir = NORTH
        elseif(self.y < toPosition.y) then
            dir = SOUTH
        end
    end
    return dir
end

local diagonals = {NORTHWEST, SOUTHWEST, NORTHEAST, SOUTHEAST}

function onCastSpell(cid, var)
    if doCombat(cid, combat, var) then
        local creature, target = Creature(cid), Creature(var:getNumber())
        if not target then return true end

        local level, maglevel = creature:getLevel(), creature:getMagicLevel()
        local min = -((level / 5) + (maglevel * 1.4) + 8)
        local max = -((level / 5) + (maglevel * 2.2) + 14)

        local creature_pos, effect_pos = creature:getPosition(), target:getPosition()
        local diagonal = math.abs(effect_pos.x - creature_pos.x) > 0 and math.abs(effect_pos.y - creature_pos.y) > 0
        local distance = getDistanceBetween(effect_pos, creature_pos) - 1

        doAreaCombatHealth(cid, COMBAT_ENERGYDAMAGE, effect_pos, 0, min, max, CONST_ME_ENERGYAREA)
        for i = 1, distance > 4 and 4 or distance do
            local direction = effect_pos:getDirectionTo(creature_pos)
            if (diagonal and isInArray(diagonals, direction)) or (not diagonal and not isInArray(diagonals, direction)) then
                effect_pos:getNextPosition(direction, 1)
                doAreaCombatHealth(cid, COMBAT_ENERGYDAMAGE, effect_pos, 0, min, max, CONST_ME_ENERGYAREA)
            end
        end
        return true
    end
    return false
end
 
Last edited:

Itutorial

Advanced OT User
Joined
Dec 23, 2014
Messages
1,417
Reaction score
310
@Apollos
Should this
Code:
local distance = getDistanceBetween(effect_pos, creature_pos) - 1
be
Code:
local distance = getDistanceBetween(effect_pos, creature_pos)
if he wants the effect to happen on the monster itself? I think that's what he wants. I kind of speed read the code and was curious.
 

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
583
Reaction score
354
Location
United States
@Apollos
Should this
Code:
local distance = getDistanceBetween(effect_pos, creature_pos) - 1
be
Code:
local distance = getDistanceBetween(effect_pos, creature_pos)
if he wants the effect to happen on the monster itself? I think that's what he wants. I kind of speed read the code and was curious.
It will. It's actually going backwards from the target to the player. Had to do it that way cause reasons.
 
OP
Kanohn

Kanohn

Intermediate OT User
Joined
Aug 28, 2011
Messages
225
Reaction score
3
Hey, sorry, i was off for a while..

The spell worked! thank you @Apollos
 
Top