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

qruczu

New Member
Joined
Jan 8, 2012
Messages
104
Reaction score
0
Hello, can anyone make this script better for the engine? And explain because im learning :D

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_CREATEITEM, 11785)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)

local combat1 = Combat()
combat1:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat1:setParameter(COMBAT_PARAM_EFFECT, 0)
combat1:setFormula(COMBAT_FORMULA_LEVELMAGIC, -3.0, -190, -3.0, -210)

local combat2 = Combat()
combat2:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat2:setParameter(COMBAT_PARAM_EFFECT, 0)
combat2:setFormula(COMBAT_FORMULA_LEVELMAGIC, -3.0, -100, -3.0, -120)

local combat3 = Combat()
combat3:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat3:setParameter(COMBAT_PARAM_EFFECT, 0)
combat3:setFormula(COMBAT_FORMULA_LEVELMAGIC, -3.0, -100, -3.0, -120)

local combat4 = Combat()
combat4:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat4:setParameter(COMBAT_PARAM_EFFECT, 0)
combat4:setFormula(COMBAT_FORMULA_LEVELMAGIC, -3.0, -100, -3.0, -120)

local combat5 = Combat()
combat5:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat5:setParameter(COMBAT_PARAM_EFFECT, 0)
combat5:setFormula(COMBAT_FORMULA_LEVELMAGIC, -3.0, -100, -3.0, -120)
 
arr1 = {
{0, 0, 0},
{0, 0, 0, 0},
{1, 0, 0},
{0, 2, 0},
{0, 0, 0}
}
 
 arr2 = {
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 1, 2, 1, 0},
{0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 0, 0, 0, 0}
}
 
  arr3 = {
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 1, 2, 1, 0},
{0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 0, 0, 0, 0}
}
 
  arr4 = {
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 1, 2, 1, 0},
{0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 0, 0, 0, 0}
}
 
   arr5 = {
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 1, 2, 1, 0},
{0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 0, 0, 0, 0}
}
 
   arr6 = {
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 1, 2, 1, 0},
{0, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 0, 0, 0, 0}
}
 
combat:setArea(createCombatArea(arr1))
combat1:setArea(createCombatArea(arr2))
combat2:setArea(createCombatArea(arr3))
combat3:setArea(createCombatArea(arr4))
combat4:setArea(createCombatArea(arr5))
combat5:setArea(createCombatArea(arr6))

 
 local function effecto(cid, variant)
 local player = Player(cid)
        combat:execute(player, variant)
        player:say("2 Hits!", TALKTYPE_MONSTER_SAY)         
    end

 local function effecto1(cid, variant)
local player = Player(cid)
        combat1:execute(player, variant)
        player:say("4 Hits!", TALKTYPE_MONSTER_SAY) 
          
end

 local function effecto2(cid, variant)
 local player = Player(cid)
        combat2:execute(player, variant)
        player:say("8 Hits!", TALKTYPE_MONSTER_SAY) 
          
end

 local function effecto3(cid, variant)
local player = Player(cid)
        combat3:execute(player, variant)
        player:say("16 Hits!", TALKTYPE_MONSTER_SAY) 
          
end

 local function effecto4(cid, variant)
local player = Player(cid)
        combat4:execute(player, variant)
        player:say("32 Hits!", TALKTYPE_MONSTER_SAY)
          
end

 local function effecto5(cid, variant)
local player = Player(cid)
        combat5:execute(player, variant)
        player:say("64 Hits!", TALKTYPE_MONSTER_SAY) 
  
end

  
function onCastSpell(cid, variant)
    local player = Player(cid)
if player then

    addEvent(effecto, 100, cid, variant)
    addEvent(effecto1, 400, cid, variant)
    addEvent(effecto2, 700, cid, variant)
    addEvent(effecto3, 1000, cid, variant)
    addEvent(effecto4, 1300, cid, variant)
    addEvent(effecto5, 1600, cid, variant)
    end
    return true
end

and one more question what is variant ?
 
Last edited:
Lua:
arr1 = {
  {1, 0, 0},
  {0, 2, 0},
  {0, 0, 0}
}
 
arr2 = {
  {1, 1, 1},
  {1, 2, 1},
  {1, 1, 1},
}

local arrs = {createCombatArea(arr1), createCombatArea(arr2)}

local combats = {
  [1] = {delay = 100, dmgType = COMBAT_PHYSICALDAMAGE, effect = 5, text = "2 Hits!",
    formula = {
      skill = COMBAT_FORMULA_LEVELMAGIC,
      mina = -3.0,
      minb = -190,
      maxa = -3.0,
      maxb = -210,
    },
  },

  [2] = {delay = 400, dmgType = COMBAT_PHYSICALDAMAGE, effect = 5, text = "4 Hits!",
    formula = {
      skill = COMBAT_FORMULA_LEVELMAGIC,
      mina = -3.0,
      minb = -100,
      maxa = -3.0,
      maxb = -120,
    },
  },

  [3] = {delay = 700, dmgType = COMBAT_PHYSICALDAMAGE, effect = 5, text = "8 Hits!",
    formula = {
      skill = COMBAT_FORMULA_LEVELMAGIC,
      mina = -3.0,
      minb = -100,
      maxa = -3.0,
      maxb = -120,
    },
  },

  [4] = {delay = 1000, dmgType = COMBAT_PHYSICALDAMAGE, effect = 5, text = "16 Hits!",
    formula = {
      skill = COMBAT_FORMULA_LEVELMAGIC,
      mina = -3.0,
      minb = -100,
      maxa = -3.0,
      maxb = -120,
    },
  },

  [5] = {delay = 1300, dmgType = COMBAT_PHYSICALDAMAGE, effect = 5, text = "32 Hits!",
    formula = {
      skill = COMBAT_FORMULA_LEVELMAGIC,
      mina = -3.0,
      minb = -100,
      maxa = -3.0,
      maxb = -120,
    },
  },

  [6] = {delay = 1600, dmgType = COMBAT_PHYSICALDAMAGE, effect = 5, text = "64 Hits!",
    formula = {
      skill = COMBAT_FORMULA_LEVELMAGIC,
      mina = -3.0,
      minb = -100,
      maxa = -3.0,
      maxb = -120,
    },
  },
}

function onFirstCombatCreateItem(creature, position)
  Game.createItem(11785, 1, position)
end

local combat = {}
for c = 1, #combats do
  combat[c] = Combat()
  combat[c]:setParameter(COMBAT_PARAM_TYPE, combats[c].dmgType)
  combat[c]:setParameter(COMBAT_PARAM_EFFECT, combats[c].effect)
  combat[c]:setFormula(combats[c].formula.skill, combats[c].formula.mina, combats[c].formula.minb, combats[c].formula.maxa, combats[c].formula.maxb)
  if c == 1 then
    combat[1]:setArea(arrs[1])
    combat[1]:setCallback(CALLBACK_PARAM_TARGETTILE, "onFirstCombatCreateItem")
  else
    combat[c]:setArea(arrs[2])
  end
end

local function castSpell(combat, creature, text, variant)
  -- Check if creature still exist during addEvents, to prevent crashes if got killed/removed during spell
  local player = Player(creature)
  if not player then
    return false
  end
  player:say(text, TALKTYPE_MONSTER_SAY)
  return combat:execute(player, variant)
end

function onCastSpell(cid, variant)
  local player = Player(cid)
  if not player then
    return false
  end
  for i = 1, #combats do
    addEvent(castSpell, combats[i].delay, combat[i], player:getId(), combats[i].text, variant)
  end
end
 
Last edited:
Back
Top