• 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.X+ Spell Damage Direction Issue

GraveWalker

Member
Joined
Jan 7, 2019
Messages
14
Reaction score
6
Hello everyone,

I've been working on a Kamehameha spell for my game, but I've encountered an issue where the damage area of the spell does not update based on the player's direction. I would appreciate any help to figure out how to fix this problem.

Here's the current code I'm using:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combat:setArea(createCombatArea(AREA_BEAM5))

function onGetFormulaValues(player, level, maglevel)
  local min = (level / 5) + (maglevel * 5) + 50
  local max = (level / 5) + (maglevel * 10) + 100
  return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

local function showDirectionEffect(creature, effectX, effectY)
  local position = creature:getPosition()
  local direction = creature:getDirection()

  if direction == DIRECTION_NORTH then
    position.y = position.y - 1
    position:sendMagicEffect(176)
  elseif direction == DIRECTION_EAST then
    position.x = position.x + 5
    position:sendMagicEffect(177)
  elseif direction == DIRECTION_SOUTH then
    position.y = position.y + 5
    position:sendMagicEffect(176)
  elseif direction == DIRECTION_WEST then
    position.x = position.x - 1
    position:sendMagicEffect(177)
  end
end

function onCastSpell(creature, variant)
  creature:say("Ka...", TALKTYPE_MONSTER_SAY)
  addEvent(function() creature:say("Me...", TALKTYPE_MONSTER_SAY) end, 1000)
  addEvent(function() creature:say("Ha... Me...", TALKTYPE_MONSTER_SAY) end, 2000)
  addEvent(function()
    creature:say("HA!!!", TALKTYPE_MONSTER_SAY)
    showDirectionEffect(creature, CONST_ME_ENERGYAREA)
    combat:execute(creature, variant)
  end, 3000)
  return false
end
XML:
  <instant group="attack" spellid="7" name="Kamehameha" words="kamehameha" level="0" maglevel="0" mana="100" premium="0" range="0" casterTargetOrDirection="1" blockwalls="1" cooldown="3000" groupcooldown="3000" needlearn="0" script="kamehameha.lua">
    <vocation name="Son Goku" />
  </instant>
The showDirectionEffect function works correctly, and the visual effect updates based on the player's direction. However, the damage area does not update properly, and it seems to remain in the same direction regardless of where the player is facing. I'm still relatively new to making scripts and have much to learn.

I would be grateful for any suggestions on how to update the damage area based on the player's direction.

Thank you in advance!
 
Lua:
local function createBeamArea(direction)
  local area = nil
  if direction == DIRECTION_NORTH then
    area = createCombatArea({
      {0, 0, 0},
      {0, 1, 0},
      {0, 1, 0},
      {0, 1, 0},
      {0, 0, 0}
    })
  elseif direction == DIRECTION_EAST then
    area = createCombatArea({
      {0, 0, 0, 0, 0},
      {0, 1, 1, 1, 0},
      {0, 0, 0, 0, 0}
    })
  elseif direction == DIRECTION_SOUTH then
    area = createCombatArea({
      {0, 0, 0},
      {0, 1, 0},
      {0, 1, 0},
      {0, 1, 0},
      {0, 0, 0}
    })
  elseif direction == DIRECTION_WEST then
    area = createCombatArea({
      {0, 0, 0, 0, 0},
      {0, 1, 1, 1, 0},
      {0, 0, 0, 0, 0}
    })
  end
  return area
end

function onCastSpell(creature, variant)
  creature:say("Ka...", TALKTYPE_MONSTER_SAY)
  addEvent(function() creature:say("Me...", TALKTYPE_MONSTER_SAY) end, 1000)
  addEvent(function() creature:say("Ha... Me...", TALKTYPE_MONSTER_SAY) end, 2000)
  addEvent(function()
    creature:say("HA!!!", TALKTYPE_MONSTER_SAY)
    showDirectionEffect(creature, CONST_ME_ENERGYAREA)
    local direction = creature:getDirection()
    local area = createBeamArea(direction)
    combat:setArea(area)
    combat:execute(creature, variant)
  end, 3000)
  return false
end
 
Hello GamerGoiano,

Thank you for your suggestion. I tried implementing the code you provided, but I encountered an error when setting the area for the combat object:

Code:
luaCombatSetArea(). This function can only be used while loading the script.

It appears that the combat:setArea(area) function cannot be used within the onCastSpell function, as it should only be called while loading the script.

Do you have any alternative solutions or ideas to resolve this issue? I'm looking for a way to update the damage area depending on the player's direction, just like the effect. Any help would be greatly appreciated.

Thanks in advance for your assistance!
 
Hello GamerGoiano,

Thank you for your suggestion. I tried implementing the code you provided, but I encountered an error when setting the area for the combat object:

Code:
luaCombatSetArea(). This function can only be used while loading the script.

It appears that the combat:setArea(area) function cannot be used within the onCastSpell function, as it should only be called while loading the script.

Do you have any alternative solutions or ideas to resolve this issue? I'm looking for a way to update the damage area depending on the player's direction, just like the effect. Any help would be greatly appreciated.

Thanks in advance for your assistance!

Create 4 combat objects (or 2).
Use one depending on direction.

Not tested. You should also add nil check for creature. As always when You use addEvent.
Lua:
local combatNorth = Combat()
combatNorth:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatNorth:setArea(createCombatArea(AREA_BEAM5))

function onGetFormulaValues(player, level, maglevel)
  local min = (level / 5) + (maglevel * 5) + 50
  local max = (level / 5) + (maglevel * 10) + 100
  return -min, -max
end

combatNorth:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
combatNorth:setArea(createCombatArea({
   {0, 0, 0},
   {0, 1, 0},
   {0, 1, 0},
   {0, 1, 0},
   {0, 0, 0}
}))

local combatWest = Combat()
combatWest:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatWest:setArea(createCombatArea(AREA_BEAM5))
combatWest:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
combatWest:setArea(createCombatArea({
   {0, 0, 0, 0, 0},
   {0, 1, 1, 1, 0},
   {0, 0, 0, 0, 0}
}))


function onCastSpell(creature, variant)
  creature:say("Ka...", TALKTYPE_MONSTER_SAY)
  addEvent(function() creature:say("Me...", TALKTYPE_MONSTER_SAY) end, 1000)
  addEvent(function() creature:say("Ha... Me...", TALKTYPE_MONSTER_SAY) end, 2000)
  addEvent(function()
    creature:say("HA!!!", TALKTYPE_MONSTER_SAY)
    showDirectionEffect(creature, CONST_ME_ENERGYAREA)
    local direction = creature:getDirection()
    if direction == DIRECTION_NORTH or direction == DIRECTION_SOUTH then
      combatNorth:execute(creature, variant)
    elseif direction == DIRECTION_WEST or direction == DIRECTION_EAST then
      combatWest:execute(creature, variant)
    end

  end, 3000)
  return false
end
 
Hello Hellboy,
I tried implementing the suggested changes, but I still face some errors. I would appreciate it if someone could take a look at my code and help me figure out what's going wrong.

Here's the modified code I'm currently using:
Lua:
local combatNorth = Combat()
combatNorth:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatNorth:setArea(createCombatArea(AREA_BEAM5_NORTH))

local combatEast = Combat()
combatEast:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatEast:setArea(createCombatArea(AREA_BEAM5_EAST))

local combatSouth = Combat()
combatSouth:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatSouth:setArea(createCombatArea(AREA_BEAM5_SOUTH))

local combatWest = Combat()
combatWest:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatWest:setArea(createCombatArea(AREA_BEAM5_WEST))

function onGetFormulaValues(player, level, maglevel)
  local min = (level / 5) + (maglevel * 5) + 50
  local max = (level / 5) + (maglevel * 10) + 100
  return -min, -max
end

combatNorth:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
combatEast:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
combatSouth:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
combatWest:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
  creature:say("Ka...", TALKTYPE_MONSTER_SAY)
  addEvent(function()
    if not creature then return true end
    creature:say("Me...", TALKTYPE_MONSTER_SAY)
  end, 1000)
  addEvent(function()
    if not creature then return true end
    creature:say("Ha... Me...", TALKTYPE_MONSTER_SAY)
  end, 2000)
  addEvent(function()
    if not creature then return true end
    creature:say("HA!!!", TALKTYPE_MONSTER_SAY)
    local direction = creature:getDirection()
    if direction == DIRECTION_NORTH then
      combatNorth:execute(creature, variant)
    elseif direction == DIRECTION_EAST then
      combatEast:execute(creature, variant)
    elseif direction == DIRECTION_SOUTH then
      combatSouth:execute(creature, variant)
    elseif direction == DIRECTION_WEST then
      combatWest:execute(creature, variant)
    end
  end, 3000)
  return false
end

I'm receiving the following errors:
Code:
[Warning - CallBack::loadCallBack] Event onGetFormulaValues not found.
[Warning - CallBack::loadCallBack] Event onGetFormulaValues not found.
[Warning - CallBack::loadCallBack] Event onGetFormulaValues not found.
[Warning - CallBack::loadCallBack] Event onGetFormulaValues not found.

I would greatly appreciate any guidance or suggestions for fixing these errors. Thank you in advance for your help!
 
@GraveWalker
Try it now
Lua:
local beamNorth = createCombatArea({
{0, 0, 0},
{0, 1, 0},
{0, 1, 0},
{0, 1, 0},
{0, 0, 0}
})

local beamEast = createCombatArea({
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
{0, 0, 0, 0, 0}
})

local beamSouth = createCombatArea({
{0, 0, 0},
{0, 1, 0},
{0, 1, 0},
{0, 1, 0},
{0, 0, 0}
})

local beamWest = createCombatArea({
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
{0, 0, 0, 0, 0}
})

function onCastSpell(creature, variant)
creature:say("Ka...", TALKTYPE_MONSTER_SAY)
addEvent(function() creature:say("Me...", TALKTYPE_MONSTER_SAY) end, 1000)
addEvent(function() creature:say("Ha... Me...", TALKTYPE_MONSTER_SAY) end, 2000)
addEvent(function()
creature:say("HA!!!", TALKTYPE_MONSTER_SAY)
showDirectionEffect(creature, CONST_ME_ENERGYAREA)
local direction = creature:getDirection()
local area = nil
if direction == DIRECTION_NORTH then
area = beamNorth
elseif direction == DIRECTION_EAST then
area = beamEast
elseif direction == DIRECTION_SOUTH then
area = beamSouth
elseif direction == DIRECTION_WEST then
area = beamWest
end
combat:execute(creature, variant, area)
end, 3000)
return false
end
 
Hi @GamerGoiano,
Unfortunately, the issue still persists. For some reason, you can't use combat:setArea() or createCombatArea / combat:setArea(createCombatArea()) in a function or onCastSpell. It just ends in an error:
Code:
luaCombatSetArea(). This function can only be used while loading the script.

At least I had no luck with it, no matter how many modifications I've done to the script.

I appreciate the time and help!
 
And now?

Lua:
local beamNorth = createCombatArea({
{0, 0, 0},
{0, 1, 0},
{0, 1, 0},
{0, 1, 0},
{0, 0, 0}
})

local beamEast = createCombatArea({
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
{0, 0, 0, 0, 0}
})

local beamSouth = createCombatArea({
{0, 0, 0},
{0, 1, 0},
{0, 1, 0},
{0, 1, 0},
{0, 0, 0}
})

local beamWest = createCombatArea({
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
{0, 0, 0, 0, 0}
})

function onCastSpell(creature, variant)
  creature:say("Ka...", TALKTYPE_MONSTER_SAY)
  addEvent(function() creature:say("Me...", TALKTYPE_MONSTER_SAY) end, 1000)
  addEvent(function() creature:say("Ha... Me...", TALKTYPE_MONSTER_SAY) end, 2000)
  addEvent(function()
    creature:say("HA!!!", TALKTYPE_MONSTER_SAY)
    showDirectionEffect(creature, CONST_ME_ENERGYAREA)
    local direction = creature:getDirection()
    local area = nil
    if direction == DIRECTION_NORTH then
      area = beamNorth
    elseif direction == DIRECTION_EAST then
      area = beamEast
    elseif direction == DIRECTION_SOUTH then
      area = beamSouth
    elseif direction == DIRECTION_WEST then
      area = beamWest
    end
    combat:execute(creature, variant, area)
  end, 3000)
  return false
end
 
And now?

Lua:
local beamNorth = createCombatArea({
{0, 0, 0},
{0, 1, 0},
{0, 1, 0},
{0, 1, 0},
{0, 0, 0}
})

local beamEast = createCombatArea({
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
{0, 0, 0, 0, 0}
})

local beamSouth = createCombatArea({
{0, 0, 0},
{0, 1, 0},
{0, 1, 0},
{0, 1, 0},
{0, 0, 0}
})

local beamWest = createCombatArea({
{0, 0, 0, 0, 0},
{0, 1, 1, 1, 0},
{0, 0, 0, 0, 0}
})

function onCastSpell(creature, variant)
  creature:say("Ka...", TALKTYPE_MONSTER_SAY)
  addEvent(function() creature:say("Me...", TALKTYPE_MONSTER_SAY) end, 1000)
  addEvent(function() creature:say("Ha... Me...", TALKTYPE_MONSTER_SAY) end, 2000)
  addEvent(function()
    creature:say("HA!!!", TALKTYPE_MONSTER_SAY)
    showDirectionEffect(creature, CONST_ME_ENERGYAREA)
    local direction = creature:getDirection()
    local area = nil
    if direction == DIRECTION_NORTH then
      area = beamNorth
    elseif direction == DIRECTION_EAST then
      area = beamEast
    elseif direction == DIRECTION_SOUTH then
      area = beamSouth
    elseif direction == DIRECTION_WEST then
      area = beamWest
    end
    combat:execute(creature, variant, area)
  end, 3000)
  return false
end
No errors, but whenever the spell is fired, for example, north, and if you turn in another direction while the spell is casting. The damage does not update where the player faces at the time.

So that I know that we are working on the same page, here's what the script I'm checking looks like so far:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combat:setArea(createCombatArea(AREA_BEAM5))

function onGetFormulaValues(player, level, maglevel)
  local min = (level / 5) + (maglevel * 5) + 50
  local max = (level / 5) + (maglevel * 10) + 100
  return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

local function showDirectionEffect(creature, effectX, effectY)
  local position = creature:getPosition()
  local direction = creature:getDirection()

  if direction == DIRECTION_NORTH then
    position.y = position.y - 1
    position:sendMagicEffect(176)
  elseif direction == DIRECTION_EAST then
    position.x = position.x + 5
    position:sendMagicEffect(177)
  elseif direction == DIRECTION_SOUTH then
    position.y = position.y + 5
    position:sendMagicEffect(176)
  elseif direction == DIRECTION_WEST then
    position.x = position.x - 1
    position:sendMagicEffect(177)
  end
end

local beamNorth = createCombatArea({
  {0, 0, 0},
  {0, 1, 0},
  {0, 1, 0},
  {0, 1, 0},
  {0, 0, 0}
  })
 
  local beamEast = createCombatArea({
  {0, 0, 0, 0, 0},
  {0, 1, 1, 1, 0},
  {0, 0, 0, 0, 0}
  })
 
  local beamSouth = createCombatArea({
  {0, 0, 0},
  {0, 1, 0},
  {0, 1, 0},
  {0, 1, 0},
  {0, 0, 0}
  })
 
  local beamWest = createCombatArea({
  {0, 0, 0, 0, 0},
  {0, 1, 1, 1, 0},
  {0, 0, 0, 0, 0}
  })
 
  function onCastSpell(creature, variant)
    creature:say("Ka...", TALKTYPE_MONSTER_SAY)
    addEvent(function() creature:say("Me...", TALKTYPE_MONSTER_SAY) end, 1000)
    addEvent(function() creature:say("Ha... Me...", TALKTYPE_MONSTER_SAY) end, 2000)
    addEvent(function()
      creature:say("HA!!!", TALKTYPE_MONSTER_SAY)
      showDirectionEffect(creature, CONST_ME_ENERGYAREA)
      local direction = creature:getDirection()
      local area = nil
      if direction == DIRECTION_NORTH then
        area = beamNorth
      elseif direction == DIRECTION_EAST then
        area = beamEast
      elseif direction == DIRECTION_SOUTH then
        area = beamSouth
      elseif direction == DIRECTION_WEST then
        area = beamWest
      end
      combat:execute(creature, variant, area)
    end, 3000)
    return false
  end
 
Last edited:
Hello Hellboy,
I tried implementing the suggested changes, but I still face some errors. I would appreciate it if someone could take a look at my code and help me figure out what's going wrong.

Here's the modified code I'm currently using:
Lua:
local combatNorth = Combat()
combatNorth:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatNorth:setArea(createCombatArea(AREA_BEAM5_NORTH))

local combatEast = Combat()
combatEast:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatEast:setArea(createCombatArea(AREA_BEAM5_EAST))

local combatSouth = Combat()
combatSouth:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatSouth:setArea(createCombatArea(AREA_BEAM5_SOUTH))

local combatWest = Combat()
combatWest:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatWest:setArea(createCombatArea(AREA_BEAM5_WEST))

function onGetFormulaValues(player, level, maglevel)
  local min = (level / 5) + (maglevel * 5) + 50
  local max = (level / 5) + (maglevel * 10) + 100
  return -min, -max
end

combatNorth:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
combatEast:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
combatSouth:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
combatWest:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
  creature:say("Ka...", TALKTYPE_MONSTER_SAY)
  addEvent(function()
    if not creature then return true end
    creature:say("Me...", TALKTYPE_MONSTER_SAY)
  end, 1000)
  addEvent(function()
    if not creature then return true end
    creature:say("Ha... Me...", TALKTYPE_MONSTER_SAY)
  end, 2000)
  addEvent(function()
    if not creature then return true end
    creature:say("HA!!!", TALKTYPE_MONSTER_SAY)
    local direction = creature:getDirection()
    if direction == DIRECTION_NORTH then
      combatNorth:execute(creature, variant)
    elseif direction == DIRECTION_EAST then
      combatEast:execute(creature, variant)
    elseif direction == DIRECTION_SOUTH then
      combatSouth:execute(creature, variant)
    elseif direction == DIRECTION_WEST then
      combatWest:execute(creature, variant)
    end
  end, 3000)
  return false
end

I'm receiving the following errors:
Code:
[Warning - CallBack::loadCallBack] Event onGetFormulaValues not found.
[Warning - CallBack::loadCallBack] Event onGetFormulaValues not found.
[Warning - CallBack::loadCallBack] Event onGetFormulaValues not found.
[Warning - CallBack::loadCallBack] Event onGetFormulaValues not found.

I would greatly appreciate any guidance or suggestions for fixing these errors. Thank you in advance for your help!
Based on this post You can try:

Lua:
local combatNorth = Combat()
combatNorth:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatNorth:setArea(createCombatArea(AREA_BEAM5_NORTH))

local combatEast = Combat()
combatEast:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatEast:setArea(createCombatArea(AREA_BEAM5_EAST))

local combatSouth = Combat()
combatSouth:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatSouth:setArea(createCombatArea(AREA_BEAM5_SOUTH))

local combatWest = Combat()
combatWest:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatWest:setArea(createCombatArea(AREA_BEAM5_WEST))

function onGetFormulaValues(player, level, maglevel)
  local min = (level / 5) + (maglevel * 5) + 50
  local max = (level / 5) + (maglevel * 10) + 100
  return -min, -max
end

function onGetFormulaValuesNorth(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

function onGetFormulaValuesSouth(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

function onGetFormulaValuesWest(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

function onGetFormulaValuesEast(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

combatNorth:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesNorth")
combatEast:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesEast")
combatSouth:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesSouth")
combatWest:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesWest")

function onCastSpell(creature, variant)
  creature:say("Ka...", TALKTYPE_MONSTER_SAY)
  addEvent(function()
    if not creature then return true end
    creature:say("Me...", TALKTYPE_MONSTER_SAY)
  end, 1000)
  addEvent(function()
    if not creature then return true end
    creature:say("Ha... Me...", TALKTYPE_MONSTER_SAY)
  end, 2000)
  addEvent(function()
    if not creature then return true end
    creature:say("HA!!!", TALKTYPE_MONSTER_SAY)
    local direction = creature:getDirection()
    if direction == DIRECTION_NORTH then
      combatNorth:execute(creature, variant)
    elseif direction == DIRECTION_EAST then
      combatEast:execute(creature, variant)
    elseif direction == DIRECTION_SOUTH then
      combatSouth:execute(creature, variant)
    elseif direction == DIRECTION_WEST then
      combatWest:execute(creature, variant)
    end
  end, 3000)
  return false
end
 
Based on this post You can try:

Lua:
local combatNorth = Combat()
combatNorth:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatNorth:setArea(createCombatArea(AREA_BEAM5_NORTH))

local combatEast = Combat()
combatEast:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatEast:setArea(createCombatArea(AREA_BEAM5_EAST))

local combatSouth = Combat()
combatSouth:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatSouth:setArea(createCombatArea(AREA_BEAM5_SOUTH))

local combatWest = Combat()
combatWest:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatWest:setArea(createCombatArea(AREA_BEAM5_WEST))

function onGetFormulaValues(player, level, maglevel)
  local min = (level / 5) + (maglevel * 5) + 50
  local max = (level / 5) + (maglevel * 10) + 100
  return -min, -max
end

function onGetFormulaValuesNorth(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

function onGetFormulaValuesSouth(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

function onGetFormulaValuesWest(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

function onGetFormulaValuesEast(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

combatNorth:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesNorth")
combatEast:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesEast")
combatSouth:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesSouth")
combatWest:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesWest")

function onCastSpell(creature, variant)
  creature:say("Ka...", TALKTYPE_MONSTER_SAY)
  addEvent(function()
    if not creature then return true end
    creature:say("Me...", TALKTYPE_MONSTER_SAY)
  end, 1000)
  addEvent(function()
    if not creature then return true end
    creature:say("Ha... Me...", TALKTYPE_MONSTER_SAY)
  end, 2000)
  addEvent(function()
    if not creature then return true end
    creature:say("HA!!!", TALKTYPE_MONSTER_SAY)
    local direction = creature:getDirection()
    if direction == DIRECTION_NORTH then
      combatNorth:execute(creature, variant)
    elseif direction == DIRECTION_EAST then
      combatEast:execute(creature, variant)
    elseif direction == DIRECTION_SOUTH then
      combatSouth:execute(creature, variant)
    elseif direction == DIRECTION_WEST then
      combatWest:execute(creature, variant)
    end
  end, 3000)
  return false
end
The script seems to be working without any errors. However, the issue I am having is that the player's direction doesn't update correctly.

The problem I'm facing is related to capturing the player's direction right before the spell fires, after the delay, rather than when the spell is initially cast.

In my script, I'm using the onCastSpell function along with addEvent to introduce the delay. However, when I use addEvent with a delay, it seems to capture the player's direction and position only at the time of casting the spell, not when the spell is about to be executed after the delay.

I've tried several approaches to resolve this issue, but none have been successful so far. I'm looking for guidance on how to accurately capture the player's direction right before the spell execution, after the delay, within the onCastSpell function.

I appreciate any information regarding the problem as I believe that it's something either with the functions or the engine itself.

Thank you kindly in advance.
 
Position + direction is parsed when casting the spell and stored on the variant, so you only need to update it before exuting the combat

Lua:
function onCastSpell(player, variant)

    player:say("Ka...", TALKTYPE_MONSTER_SAY)

    for i = 1, 3 do

        addEvent(function(casterId)

            local caster = Player(casterId)
            if not caster then
                return
            end

            if i == 1 then
                player:say("Me...", TALKTYPE_MONSTER_SAY)
            elseif i == 2 then
                player:say("Ha... Me...", TALKTYPE_MONSTER_SAY)
            else
                player:say("HA!!!", TALKTYPE_MONSTER_SAY)
                showDirectionEffect(player, CONST_ME_ENERGYAREA)

                local position = player:getPosition()
                position:getNextPosition(player:getDirection())
  
                variant.pos = position
                combat:execute(player, variant)
            end

        end, i * 1000, player:getId())

    end

    return true
end
 
Position + direction is parsed when casting the spell and stored on the variant, so you only need to update it before exuting the combat

Lua:
function onCastSpell(player, variant)

    player:say("Ka...", TALKTYPE_MONSTER_SAY)

    for i = 1, 3 do

        addEvent(function(casterId)

            local caster = Player(casterId)
            if not caster then
                return
            end

            if i == 1 then
                player:say("Me...", TALKTYPE_MONSTER_SAY)
            elseif i == 2 then
                player:say("Ha... Me...", TALKTYPE_MONSTER_SAY)
            else
                player:say("HA!!!", TALKTYPE_MONSTER_SAY)
                showDirectionEffect(player, CONST_ME_ENERGYAREA)

                local position = player:getPosition()
                position:getNextPosition(player:getDirection())
 
                variant.pos = position
                combat:execute(player, variant)
            end

        end, i * 1000, player:getId())

    end

    return true
end
Thank you so much for your help! Your solution worked perfectly. This post can now be marked as answered/done—also, big thanks to Hellboy and GamerGoiano for trying to help. You're much appreciated too.
 
#EDIT

It took me to long to respond :D

The script seems to be working without any errors. However, the issue I am having is that the player's direction doesn't update correctly.

The problem I'm facing is related to capturing the player's direction right before the spell fires, after the delay, rather than when the spell is initially cast.

In my script, I'm using the onCastSpell function along with addEvent to introduce the delay. However, when I use addEvent with a delay, it seems to capture the player's direction and position only at the time of casting the spell, not when the spell is about to be executed after the delay.

I've tried several approaches to resolve this issue, but none have been successful so far. I'm looking for guidance on how to accurately capture the player's direction right before the spell execution, after the delay, within the onCastSpell function.

I appreciate any information regarding the problem as I believe that it's something either with the functions or the engine itself.

Thank you kindly in advance.

Lua:
local combatNorth = Combat()
combatNorth:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatNorth:setArea(createCombatArea(AREA_BEAM5_NORTH))

local combatEast = Combat()
combatEast:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatEast:setArea(createCombatArea(AREA_BEAM5_EAST))

local combatSouth = Combat()
combatSouth:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatSouth:setArea(createCombatArea(AREA_BEAM5_SOUTH))

local combatWest = Combat()
combatWest:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatWest:setArea(createCombatArea(AREA_BEAM5_WEST))

function onGetFormulaValues(player, level, maglevel)
  local min = (level / 5) + (maglevel * 5) + 50
  local max = (level / 5) + (maglevel * 10) + 100
  return -min, -max
end

function onGetFormulaValuesNorth(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

function onGetFormulaValuesSouth(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

function onGetFormulaValuesWest(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

function onGetFormulaValuesEast(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

combatNorth:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesNorth")
combatEast:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesEast")
combatSouth:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesSouth")
combatWest:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesWest")

local function castStage1(cid)
  local player = Player(cid)
  if not player then
    return true
  end
  player:say("Me...", TALKTYPE_MONSTER_SAY)
  
end

local function castStage2(cid)
  local player = Player(cid)
  if not player then
    return true
  end
  player:say("Ha... Me...", TALKTYPE_MONSTER_SAY)
end

local function castStage3(cid, variant)
  local player = Player(cid)
  if not player then
    return true
  end

  player:say("HA!!!", TALKTYPE_MONSTER_SAY)
  local direction = player:getDirection()
  if direction == DIRECTION_NORTH then
    combatNorth:execute(player, variant)
  elseif direction == DIRECTION_EAST then
    combatEast:execute(player, variant)
  elseif direction == DIRECTION_SOUTH then
    combatSouth:execute(player, variant)
  elseif direction == DIRECTION_WEST then
    combatWest:execute(player, variant)
  end
end

function onCastSpell(creature, variant)
  creature:say("Ka...", TALKTYPE_MONSTER_SAY)
  local cid = creature:getId()
  addEvent(castStage1, 1000, cid)
  addEvent(castStage2, 2000, cid)
  addEvent(castStage3, 3000, cid, variant)
  return false
end

I think we should recreate variant inside function castStage3. But I'm not sure what mean "variant" on combat/spells.
 
#EDIT

It took me to long to respond :D



Lua:
local combatNorth = Combat()
combatNorth:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatNorth:setArea(createCombatArea(AREA_BEAM5_NORTH))

local combatEast = Combat()
combatEast:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatEast:setArea(createCombatArea(AREA_BEAM5_EAST))

local combatSouth = Combat()
combatSouth:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatSouth:setArea(createCombatArea(AREA_BEAM5_SOUTH))

local combatWest = Combat()
combatWest:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatWest:setArea(createCombatArea(AREA_BEAM5_WEST))

function onGetFormulaValues(player, level, maglevel)
  local min = (level / 5) + (maglevel * 5) + 50
  local max = (level / 5) + (maglevel * 10) + 100
  return -min, -max
end

function onGetFormulaValuesNorth(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

function onGetFormulaValuesSouth(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

function onGetFormulaValuesWest(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

function onGetFormulaValuesEast(player, level, maglevel)
  return onGetFormulaValues(player, level, maglevel)
end

combatNorth:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesNorth")
combatEast:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesEast")
combatSouth:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesSouth")
combatWest:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValuesWest")

local function castStage1(cid)
  local player = Player(cid)
  if not player then
    return true
  end
  player:say("Me...", TALKTYPE_MONSTER_SAY)
 
end

local function castStage2(cid)
  local player = Player(cid)
  if not player then
    return true
  end
  player:say("Ha... Me...", TALKTYPE_MONSTER_SAY)
end

local function castStage3(cid, variant)
  local player = Player(cid)
  if not player then
    return true
  end

  player:say("HA!!!", TALKTYPE_MONSTER_SAY)
  local direction = player:getDirection()
  if direction == DIRECTION_NORTH then
    combatNorth:execute(player, variant)
  elseif direction == DIRECTION_EAST then
    combatEast:execute(player, variant)
  elseif direction == DIRECTION_SOUTH then
    combatSouth:execute(player, variant)
  elseif direction == DIRECTION_WEST then
    combatWest:execute(player, variant)
  end
end

function onCastSpell(creature, variant)
  creature:say("Ka...", TALKTYPE_MONSTER_SAY)
  local cid = creature:getId()
  addEvent(castStage1, 1000, cid)
  addEvent(castStage2, 2000, cid)
  addEvent(castStage3, 3000, cid, variant)
  return false
end

I think we should recreate variant inside function castStage3. But I'm not sure what mean "variant" on combat/spells.
Roddet explained what 'variant' in onCastSpell does. I've tested the script, and it works just as the previous one you sent before, but it doesn't update the direction and position of the player after the delay. Again, I appreciate the help, buddy.
 
Back
Top