1. Guest, do you need help starting your own server? Take a look at our new guide with information and links to tutorials here.
  2. Guest, remember to add your server at our serverlist!

Multiple effects and callbacks

Discussion in 'Spells' started by Deleted member 135, Mar 30, 2017.

  1. A variation of this post from otland Helpful aka @Codex NG
    Example of a very basic way to define a spell with multiple effects and callbacks.
    Code (Lua):
    1.  
    2. local spell = {
    3.     {
    4.          COMBAT_EARTHDAMAGE, -- index 1
    5.          CONST_ME_STONES, -- index 2
    6.          function(player, level, maglevel) -- index 3
    7.              local min = (level / 5) + (maglevel * 3) + 32
    8.              local max = (level / 5) + (maglevel * 9) + 40
    9.              return -min, -max
    10.          end,
    11.          AREA_CIRCLE3X3, -- index 4
    12.          CALLBACK_PARAM_LEVELMAGICVALUE, -- index 5
    13.          "onGetFormulaValues" -- index 6
    14.     },
    15.     {
    16.          COMBAT_EARTHDAMAGE, -- index 1
    17.          CONST_ME_BIGPLANTS, -- index 2
    18.          function(player, skill, attack, factor) -- index 3
    19.              local min = (player:getLevel() / 5) + (skill * attack * 0.06) + 13
    20.              local max = (player:getLevel() / 5) + (skill * attack * 0.14) + 34
    21.              return -min, -max
    22.          end,
    23.          AREA_CIRCLE5X5, -- index 4
    24.          CALLBACK_PARAM_SKILLVALUE, -- index 5
    25.          "onGetFormulaValues" -- index 6
    26.     }
    27. }
    28.  
    29. local combat = {}
    30.  
    31. for i = 1, #spell do
    32.     combat[i] = Combat()
    33.     combat[i]:setParameter(COMBAT_PARAM_TYPE, spell[i][1])
    34.     combat[i]:setParameter(COMBAT_PARAM_EFFECT, spell[i][2])
    35.     combat[i]:setArea(createCombatArea(spell[i][4]))
    36.     _G[spell[i][6]..i] = spell[i][3]
    37.     combat[i]:setCallback(spell[i][5], spell[i][6]..i)
    38. end
    39.  
    40. function onCastSpell(creature, var)
    41.     for x = 1, #spell do
    42.         combat[x]:execute(creature, var)
    43.     end
    44.     return true
    45. end
    I have not tested this script but the logic as far as i can tell seems correct, if not please provide a correction to the code.
     
    Last edited by a moderator: Mar 30, 2017
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.