• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[Spell] Circle Area Effect [TFS 1.0]

Eldin

Eldin Projects
Joined
Jun 12, 2008
Messages
1,334
Reaction score
615
Location
Sweden
Greets!

Spells is something that I never really got myself into at a higher Point, now is the time.
The idea is the make the character swing its blade around himself in a circle.

I guess it could be done much shorter, however, I can't get it to work at this stage.

Code:
 local cleaveCircleArea = {
 createCombatArea({
 {0, 0, 1, 2},
 }),
 createCombatArea({
 {0, 0, 1, 0},
 {0, 0, 0, 2},
 }),
 createCombatArea({
 {0, 0, 0, 0},
 {0, 0, 0, 1},
 {0, 0, 0, 2},
 }),
 createCombatArea({
 {0},
 {0},
 {1},
 {2},
 }),
 createCombatArea({
 {0, 0},
 {0, 0},
 {0, 1},
 {2, 0},
 {0, 0},
 {0, 0},
 {0, 0}
 }),
 createCombatArea({
 {0, 0, 0},
 {0, 0, 0},
 {2, 1, 0},
 }),
 createCombatArea({
 {2, 1, 0, 0},
 }),
 createCombatArea({
 {2, 0, 0, 0},
 {0, 1, 0, 0},
 }),
 createCombatArea({
 {2, 0, 0},
 {1, 0, 0},
 {0, 0, 0},
 }),
 createCombatArea({
 {0, 2},
 {1, 0},
 {0, 0},
 {0, 0}
 }),
 createCombatArea({
 {0, 0, 1, 2},
 {0, 0, 0, 0},
 })
 }

 function onTargetTile1(cid, pos)
 doSendDistanceShoot(getCreaturePosition(cid), pos, CONST_ANI_WHIRLWINDAXE)
 end
 local cleaveCircle = {}
 for k, area in ipairs(cleaveCircleArea) do
 cleaveCircle[k] = createCombatObject()
 setCombatParam(cleaveCircle[k], COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
 setCombatParam(cleaveCircle[k], COMBAT_PARAM_EFFECT, CONST_ME_NONE)
 setCombatFormula(cleaveCircle[k], COMBAT_FORMULA_SKILL, 2.55, -100, 2.60, -200)
 setCombatArea(cleaveCircle[k], area)
 _G["callback2" .. k] = onTargetTile2
 setCombatCallback(cleaveCircle[k], CALLBACK_PARAM_TARGETTILE, "callback2" .. k)
 end

 local function castSpellDelay(p)
 doCombat(unpack(p))
 end
 local i = 0
 for k, combat in ipairs(cleaveCircle) do
 addEvent(castSpellDelay, #cleaveCircle * 100 * i + 100 * k, {cid, combat, var})
 end
 return LUA_NO_ERROR
 end

I would like it to be the weapontype as well:
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)

Thanks in advance.

Kind Regards,
Eldin.
 
I don't really do TFS 1.0.
But basically I would do your above spell like this. (This is how I would do it on TFS 0.3.6, some of these functions may not exist for TFS 1.0, but I'm sure you could make them if needed)

Here is a code that will rotate directions depending on your look direction.

Code:
local dirTable = {
[1] = {x = 1, y = 0}, -- East
[2] = {x = 1, y = 1},
[3] = {x = 0, y = 1}, -- South
[4] = {x = -1, y = 1},
[5] = {x = -1, y = 0}, -- West
[6] = {x = -1, y = -1},
[7] = {x = 0, y = -1}, -- North
[8] = {x = 1, y = -1},
}
local lookDir = getCreatureLookDirection(cid)
local startPos = 7
if lookDir == 1 then 
 startPos = 1 
elseif lookDir == 2 then 
 startPos = 3 
elseif lookDir == 3 then 
 startPos = 5 
end
local lastPosition = getCreaturePosition(cid)
for a = 1, 8 do
 local combatPosition = {x = getCreaturePosition(cid).x + dirTable[startPos].x, y = getCreaturePosition(cid).y + dirTable[startPos].y}, z = getCreaturePosition(cid).z}
 -------- Use combatPosition and lastPosition to cast a spell, send distance effects, etc------------------
 startPos = startPos + 1
 if startPos > 8 then startPos = 1 end
 lastPosition = combatPosition
end

So the above script should rotate around your character (even if you move) and always start at your lookPosition.
Just adding in combat, magic effects, distance effects etc should be easy.
 
Ok so I tried to modify both codes and make them work, updating one code to tfs 1.0 and then merging with the other, failed attempt, I don't know much about tables at all, @Flatlander maybe you can see what I was doing wrong with your code,


Code:
function onCastSpell(cid, var)
local dirTable = {
[1] = {x = 1, y = 0}, -- East
[2] = {x = 1, y = 1},
[3] = {x = 0, y = 1}, -- South
[4] = {x = -1, y = 1},
[5] = {x = -1, y = 0}, -- West
[6] = {x = -1, y = -1},
[7] = {x = 0, y = -1}, -- North
[8] = {x = 1, y = -1},
}

local lookDir = Creature(cid):getDirection()
local startPos = 7
if lookDir == 1 then
startPos = 1
elseif lookDir == 2 then
startPos = 3
elseif lookDir == 3 then
startPos = 5
end
local lastPosition = Player(cid):getPosition()
for a = 1, 8 do
local combatPosition = {x = Player(cid):getPosition().x + dirTable[startPos].x, y = Player(cid):getPosition().y + dirTable[startPos].y, z = Player(cid):getPosition().z}
startPos = startPos + 1
if startPos > 8 then startPos = 1 end
lastPosition = combatPosition
end
local combat1 = {}
for k, area in ipairs(a) do
combat1[k] = Combat()
combat1[k]:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
combat1[k]:setParameter(COMBAT_PARAM_BLOCKSHIELD, 1)
combat1[k]:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat1[k]:setFormula(COMBAT_FORMULA_SKILL, 2.55, -100, 2.60, -200)
combat1[k]:setArea(area)
combat1[k]:setCallback(CALLBACK_PARAM_TARGETTILE, "lastPosition")
end

local function castSpellDelay(p)
    combat:execute(cid, var)
    end
    local i = 0
    for k, combat in ipairs(combat1) do
    addEvent(castSpellDelay, #combat1 * 100 * i + 100 * k, {cid, combat, var})
    end
    return true
end

get console error

Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/attack/meleethrow.lua:onCastSpell
data/spells/scripts/attack/meleethrow.lua:56: bad argument #1 to 'ipairs' (table
expected, got nil)
stack traceback:
        [C]: at 0x013f9c39a0
        [C]: in function 'ipairs'
        data/spells/scripts/attack/meleethrow.lua:56: in function <data/spells/s
cripts/attack/meleethrow.lua:6>

Like I said I'm not good with tables...
 
Last edited:
Back
Top