• 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.3 - RevScripts] Spell Error: LuaScriptInterface::luaCreateCombatArea(). This function can only be used while loading the script.

Yan18

Member
Joined
Jun 14, 2014
Messages
104
Solutions
3
Reaction score
17
Hello Guys!

I created a spell in area that depending on the direction, will change the area and effect. When I use the spell, generate this error:

Bash:
LuaScriptInterface::luaCreateCombatArea(). This function can only be used while loading the script.
stack traceback:
  [C]: in function 'createCombatArea'

My Spell script:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setFormula(COMBAT_FORMULA_DAMAGE, -1, -250, -1, -450)

local area_north = createCombatArea(AREA_NORTH)
local area_east = createCombatArea(AREA_EAST)
local area_south = createCombatArea(AREA_SOUTH)
local area_west = createCombatArea(AREA_WEST)

local spell = Spell(SPELL_INSTANT)

function spell.onCastSpell(creature, variant)   

    if creature:getDirection() == NORTH then
        creature:getPosition():sendMagicEffect(187)
        combat:setArea(area_north)
        
    elseif creature:getDirection() == EAST then
        creature:getPosition():sendMagicEffect(188)
        combat:setArea(area_east)
    
    elseif creature:getDirection() == SOUTH then
        creature:getPosition():sendMagicEffect(189)
        combat:setArea(area_south)
        
    elseif creature:getDirection() == WEST then
        creature:getPosition():sendMagicEffect(190)
        combat:setArea(area_west)       
    end

return combat:execute(creature, variant)
end

spell:group("attack")
spell:id(2004)
spell:name("Sper")
spell:words("Sper")
spell:level(50)
spell:mana(100)
spell:isPremium(false)
spell:range(1)
spell:needCasterTargetOrDirection(false)
spell:isBlockingWalls(true)
spell:cooldown(8000)
spell:groupCooldown(8000)
spell:needLearn(false)
spell:vocation("sorcerer;true", "druid;true", "master sorcerer", "elder druid")
spell:register()

I tried to put the local variables area inside the function onCastSpell(), but the error remains.
 
Solution
Hello Guys!

I created a spell in area that depending on the direction, will change the area and effect. When I use the spell, generate this error:

Bash:
LuaScriptInterface::luaCreateCombatArea(). This function can only be used while loading the script.
stack traceback:
  [C]: in function 'createCombatArea'

My Spell script:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setFormula(COMBAT_FORMULA_DAMAGE, -1, -250, -1, -450)

local area_north = createCombatArea(AREA_NORTH)
local area_east = createCombatArea(AREA_EAST)
local area_south = createCombatArea(AREA_SOUTH)
local area_west = createCombatArea(AREA_WEST)

local spell = Spell(SPELL_INSTANT)

function spell.onCastSpell(creature...
Hello Guys!

I created a spell in area that depending on the direction, will change the area and effect. When I use the spell, generate this error:

Bash:
LuaScriptInterface::luaCreateCombatArea(). This function can only be used while loading the script.
stack traceback:
  [C]: in function 'createCombatArea'

My Spell script:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setFormula(COMBAT_FORMULA_DAMAGE, -1, -250, -1, -450)

local area_north = createCombatArea(AREA_NORTH)
local area_east = createCombatArea(AREA_EAST)
local area_south = createCombatArea(AREA_SOUTH)
local area_west = createCombatArea(AREA_WEST)

local spell = Spell(SPELL_INSTANT)

function spell.onCastSpell(creature, variant)  

    if creature:getDirection() == NORTH then
        creature:getPosition():sendMagicEffect(187)
        combat:setArea(area_north)
       
    elseif creature:getDirection() == EAST then
        creature:getPosition():sendMagicEffect(188)
        combat:setArea(area_east)
   
    elseif creature:getDirection() == SOUTH then
        creature:getPosition():sendMagicEffect(189)
        combat:setArea(area_south)
       
    elseif creature:getDirection() == WEST then
        creature:getPosition():sendMagicEffect(190)
        combat:setArea(area_west)      
    end

return combat:execute(creature, variant)
end

spell:group("attack")
spell:id(2004)
spell:name("Sper")
spell:words("Sper")
spell:level(50)
spell:mana(100)
spell:isPremium(false)
spell:range(1)
spell:needCasterTargetOrDirection(false)
spell:isBlockingWalls(true)
spell:cooldown(8000)
spell:groupCooldown(8000)
spell:needLearn(false)
spell:vocation("sorcerer;true", "druid;true", "master sorcerer", "elder druid")
spell:register()

I tried to put the local variables area inside the function onCastSpell(), but the error remains.
Yep, the error is pretty concise.
You can only created combat area's while loading the script.

So if you want 4 different effects, you'll have to artificially create them yourself, or create 4 different combats, and then decide inside of onCastSpell() which combat you want to use, during that spell cast.
 
Solution
Try this:
Lua:
local combatNorth = Combat()
combatNorth:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combatNorth:setFormula(COMBAT_FORMULA_DAMAGE, -1, -250, -1, -450)
combatNorth:setArea(createCombatArea(AREA_NORTH))

local combatEast = Combat()
combatEast:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combatEast:setFormula(COMBAT_FORMULA_DAMAGE, -1, -250, -1, -450)
combatEast:setArea(createCombatArea(AREA_EAST))

local combatSouth = Combat()
combatSouth:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combatSouth:setFormula(COMBAT_FORMULA_DAMAGE, -1, -250, -1, -450)
combatSouth:setArea(createCombatArea(AREA_SOUTH))

local combatWest = Combat()
combatWest:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combatWest:setFormula(COMBAT_FORMULA_DAMAGE, -1, -250, -1, -450)
combatWest:setArea(createCombatArea(AREA_WEST))

local combats = {
    combatNorth,
    combatEast,
    combatSouth,
    combatWest
}
local magicEffects = {
    187, -- north
    188, -- east
    189, -- south
    190 -- west
}

local spell = Spell(SPELL_INSTANT)

spell:group("attack")
spell:id(2004)
spell:name("Sper")
spell:words("Sper")
spell:level(50)
spell:mana(100)
spell:isPremium(false)
spell:range(1)
spell:needCasterTargetOrDirection(false)
spell:isBlockingWalls(true)
spell:cooldown(8000)
spell:groupCooldown(8000)
spell:needLearn(false)
spell:vocation("sorcerer;true", "druid;true", "master sorcerer", "elder druid")

function spell.onCastSpell(creature, variant)   
    local direction = creature:getDirection()
    creature:getPosition():sendMagicEffect(magicEffects[direction])
    return combats[direction]:execute(creature, variant)
end

spell:register()
 
Yep, the error is pretty concise.
You can only created combat area's while loading the script.

So if you want 4 different effects, you'll have to artificially create them yourself, or create 4 different combats, and then decide inside of onCastSpell() which combat you want to use, during that spell cast.
I created 4 differents combat as you said and works!! Thanks!! But, how could I create by a "artificially" way as you mentioned? I stay in doubt. Could you explain?

Thanks again!!

Try this:
Lua:
local combatNorth = Combat()
combatNorth:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combatNorth:setFormula(COMBAT_FORMULA_DAMAGE, -1, -250, -1, -450)
combatNorth:setArea(createCombatArea(AREA_NORTH))

local combatEast = Combat()
combatEast:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combatEast:setFormula(COMBAT_FORMULA_DAMAGE, -1, -250, -1, -450)
combatEast:setArea(createCombatArea(AREA_EAST))

local combatSouth = Combat()
combatSouth:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combatSouth:setFormula(COMBAT_FORMULA_DAMAGE, -1, -250, -1, -450)
combatSouth:setArea(createCombatArea(AREA_SOUTH))

local combatWest = Combat()
combatWest:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combatWest:setFormula(COMBAT_FORMULA_DAMAGE, -1, -250, -1, -450)
combatWest:setArea(createCombatArea(AREA_WEST))

local combats = {
    combatNorth,
    combatEast,
    combatSouth,
    combatWest
}
local magicEffects = {
    187, -- north
    188, -- east
    189, -- south
    190 -- west
}

local spell = Spell(SPELL_INSTANT)

spell:group("attack")
spell:id(2004)
spell:name("Sper")
spell:words("Sper")
spell:level(50)
spell:mana(100)
spell:isPremium(false)
spell:range(1)
spell:needCasterTargetOrDirection(false)
spell:isBlockingWalls(true)
spell:cooldown(8000)
spell:groupCooldown(8000)
spell:needLearn(false)
spell:vocation("sorcerer;true", "druid;true", "master sorcerer", "elder druid")

function spell.onCastSpell(creature, variant)  
    local direction = creature:getDirection()
    creature:getPosition():sendMagicEffect(magicEffects[direction])
    return combats[direction]:execute(creature, variant)
end

spell:register()
Thanks bro 😀!

I did as the Xikini said, I created 4 differents combat and worked! My script looks like yours! But thanks again!
 
Back
Top