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

Lua Help to make two functions as one (spell) TFS 1.3

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hi guys, I have two different spells with two different functions and I would like to put them together.

That's the first script:

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_BLOCKSHIELD, true)
combat:setParameter(COMBAT_PARAM_EFFECT, 208)
combat:setArea(createCombatArea({{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, 0},
  {0, 0, 0, 0, 0, 0, 0}}))

function onGetFormulaValues(player, skill, attack, shield)

    local maxHealth = player:getMaxHealth()
    local playlvl = player:getLevel()
    local shield = player:getSkillLevel(SKILL_SHIELD)

    if (playlvl<300) then
    local min = (player:getLevel()) + (maxHealth / 16) + (attack * 2) + (shield * 2) * 0,55
    local max = (player:getLevel()) + (maxHealth / 16) + (attack * 2) + (shield * 2) * 1,1
    return -min, -max
    
    else
    local min = (300) + (maxHealth / 16) + (attack * 2) + (shield * 2) * 0,55
    local max = (300) + (maxHealth / 16) + (attack * 2) + (shield * 2) * 1,1
    return -min, -max
    end   
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onTargetCreature(creature, target)
    return doChallengeCreature(creature, target)
end

combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(creature, variant)
    local weapons = {26238, 26240, 26328, 26330, 26329, 26239, 26331, 26158, 26159, 26136, 26145, 26218, 26302, 26303, 26300, 26301, 26219, 26162, 26217, 26163,
    26215, 26298, 26299, 26296, 26297, 26216, 26214, 26227, 26314, 26315, 26312, 26313, 26228, 26226, 26221, 26306, 26307, 26304, 26305, 26222, 26220, 26224,
    26310, 26311, 26308, 26309, 26225, 26128, 26223, 26230, 26318, 26319, 26316, 26317, 26231, 26166, 26229, 26194, 26268, 26269, 26266, 26267, 26195, 26126,
    26193, 26254, 26350, 26351, 26105, 26348, 26349, 26255, 26134, 26160, 26253, 26236, 26326, 26165, 26327, 26324, 26325, 26237, 26127, 26235, 26245, 26338,
    26339, 26336, 26337, 26246, 26149, 26244, 26251, 26346, 26347, 26344, 26345, 26252, 26150, 26250, 26191, 26108, 26151, 26131, 26133, 26103, 26146, 26156,
    26212, 26294, 26295, 26292, 26293, 26213, 26179, 26107, 26211, 26233, 26322, 26323, 26320, 26321, 26234, 26232, 26242, 26334, 26157, 26335, 26332, 26333,
    26243, 26115, 26241, 26260, 26358, 26359, 26356, 26357, 26261, 26142, 26259, 26263, 26362, 26363, 26360, 26361, 26264, 26155, 26262, 26197, 26274, 26275,
    26272, 26273, 26198, 26175, 26196, 26201, 26278, 26279, 26276, 26277, 26199, 26177, 26135, 26176, 26200, 26154, 26119, 26172, 26138, 26148, 26161, 26169,
    26257, 26354, 26355, 26352, 26353, 26258, 26256, 26203, 26282, 26283, 26280, 26281, 26204, 26102, 26202, 26180, 26124, 26116, 26141, 26152, 26144, 26167,
    26209, 26290, 26291, 26288, 26289, 26210, 26208, 26147, 26248, 26342, 26343, 26340, 26341, 26249, 26247, 26114, 26189, 26171, 26132, 26178, 26164, 26174,
    26153, 26117, 26270, 26265, 26139, 26123, 26104, 26192, 26206, 26286, 26287, 26284, 26285, 26207, 26205, 26182, 26111, 26190, 26143, 26140, 26113, 26122,
    26118, 26181, 26129, 26173, 26271, 26137, 26121, 26168, 26106, 26110, 26112, 26109, 26120, 26130, 26170, 26186, 26183, 26185, 26184, 26187, 26125, 26188} -- axe weapons
    local shields = {27213, 27204, 27211, 27208, 27187, 27219, 27252, 27218, 27225, 27254, 27230, 27232, 27198, 27197, 27245, 27174, 27256, 27239, 27222,
    27206, 27246, 27205, 27176, 27240, 27192, 27250, 27175, 27257, 27221, 27190, 27260, 27251, 27223, 27200, 27195, 27199, 27231, 27266, 27193, 27264, 27185,
    27268, 27210, 27181, 27173, 27220, 27234, 27184, 27258, 27249, 27201, 27233, 27217, 27235, 27265, 27186, 27237, 27248, 27196, 27267, 27189, 27209, 27270,
    27259, 27238, 27183, 27271, 27263, 27236, 27191, 27215, 27224, 27228, 27243, 27269, 27226, 27202, 27188, 27194, 27182, 27261, 27253, 27247, 27262, 27229,
    27177}

        local slotWeapon = CONST_SLOT_LEFT
        local slotShield = CONST_SLOT_RIGHT
        
        local playerWeapon = creature:getSlotItem(slotWeapon)
        local playerShield = creature:getSlotItem(slotShield)
        if playerWeapon and table.contains(weapons, playerWeapon:getId()) then
        if playerShield and table.contains(shields, playerShield:getId()) then
            return combat:execute(creature, variant)
        end
    end

    creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You need an axe and a shield to cast this spell.")
    return false
end

The only part I want from this script is:

Code:
function onCastSpell(creature, variant)
    local weapons = {26238, 26240, 26328, 26330, 26329, 26239, 26331, 26158, 26159, 26136, 26145, 26218, 26302, 26303, 26300, 26301, 26219, 26162, 26217, 26163,
    26215, 26298, 26299, 26296, 26297, 26216, 26214, 26227, 26314, 26315, 26312, 26313, 26228, 26226, 26221, 26306, 26307, 26304, 26305, 26222, 26220, 26224,
    26310, 26311, 26308, 26309, 26225, 26128, 26223, 26230, 26318, 26319, 26316, 26317, 26231, 26166, 26229, 26194, 26268, 26269, 26266, 26267, 26195, 26126,
    26193, 26254, 26350, 26351, 26105, 26348, 26349, 26255, 26134, 26160, 26253, 26236, 26326, 26165, 26327, 26324, 26325, 26237, 26127, 26235, 26245, 26338,
    26339, 26336, 26337, 26246, 26149, 26244, 26251, 26346, 26347, 26344, 26345, 26252, 26150, 26250, 26191, 26108, 26151, 26131, 26133, 26103, 26146, 26156,
    26212, 26294, 26295, 26292, 26293, 26213, 26179, 26107, 26211, 26233, 26322, 26323, 26320, 26321, 26234, 26232, 26242, 26334, 26157, 26335, 26332, 26333,
    26243, 26115, 26241, 26260, 26358, 26359, 26356, 26357, 26261, 26142, 26259, 26263, 26362, 26363, 26360, 26361, 26264, 26155, 26262, 26197, 26274, 26275,
    26272, 26273, 26198, 26175, 26196, 26201, 26278, 26279, 26276, 26277, 26199, 26177, 26135, 26176, 26200, 26154, 26119, 26172, 26138, 26148, 26161, 26169,
    26257, 26354, 26355, 26352, 26353, 26258, 26256, 26203, 26282, 26283, 26280, 26281, 26204, 26102, 26202, 26180, 26124, 26116, 26141, 26152, 26144, 26167,
    26209, 26290, 26291, 26288, 26289, 26210, 26208, 26147, 26248, 26342, 26343, 26340, 26341, 26249, 26247, 26114, 26189, 26171, 26132, 26178, 26164, 26174,
    26153, 26117, 26270, 26265, 26139, 26123, 26104, 26192, 26206, 26286, 26287, 26284, 26285, 26207, 26205, 26182, 26111, 26190, 26143, 26140, 26113, 26122,
    26118, 26181, 26129, 26173, 26271, 26137, 26121, 26168, 26106, 26110, 26112, 26109, 26120, 26130, 26170, 26186, 26183, 26185, 26184, 26187, 26125, 26188} -- axe weapons
    local shields = {27213, 27204, 27211, 27208, 27187, 27219, 27252, 27218, 27225, 27254, 27230, 27232, 27198, 27197, 27245, 27174, 27256, 27239, 27222,
    27206, 27246, 27205, 27176, 27240, 27192, 27250, 27175, 27257, 27221, 27190, 27260, 27251, 27223, 27200, 27195, 27199, 27231, 27266, 27193, 27264, 27185,
    27268, 27210, 27181, 27173, 27220, 27234, 27184, 27258, 27249, 27201, 27233, 27217, 27235, 27265, 27186, 27237, 27248, 27196, 27267, 27189, 27209, 27270,
    27259, 27238, 27183, 27271, 27263, 27236, 27191, 27215, 27224, 27228, 27243, 27269, 27226, 27202, 27188, 27194, 27182, 27261, 27253, 27247, 27262, 27229,
    27177}

        local slotWeapon = CONST_SLOT_LEFT
        local slotShield = CONST_SLOT_RIGHT
        
        local playerWeapon = creature:getSlotItem(slotWeapon)
        local playerShield = creature:getSlotItem(slotShield)
        if playerWeapon and table.contains(weapons, playerWeapon:getId()) then
        if playerShield and table.contains(shields, playerShield:getId()) then
            return combat:execute(creature, variant)
        end
    end

    creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You need an axe and a shield to cast this spell.")
    return false
end

That's the second script, that's the one I want to put the function above with.

Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE) -- Lembrar de alterar o elemento quando for duplicar.
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, false)
combat:setParameter(COMBAT_PARAM_USECHARGES, true)
combat:setArea(createCombatArea(AREA_WAVE6, AREADIAGONAL_WAVE6))

local combat2 = Combat()
combat2:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat2:setParameter(COMBAT_PARAM_BLOCKARMOR, false)
combat2:setParameter(COMBAT_PARAM_USECHARGES, true)
combat2:setArea(createCombatArea(AREA_WAVE6, AREADIAGONAL_WAVE6))

local combat3 = Combat()
combat3:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat3:setParameter(COMBAT_PARAM_BLOCKARMOR, false)
combat3:setParameter(COMBAT_PARAM_USECHARGES, true)
combat3:setArea(createCombatArea(AREA_WAVE6, AREADIAGONAL_WAVE6))

local combat4 = Combat()
combat4:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat4:setParameter(COMBAT_PARAM_BLOCKARMOR, false)
combat4:setParameter(COMBAT_PARAM_USECHARGES, true)
combat4:setArea(createCombatArea(AREA_WAVE6, AREADIAGONAL_WAVE6))

function onGetFormulaValues(player, skill, attack, skill, factor)

    local maxHealth = player:getMaxHealth()
    local maxMana = player:getMaxMana()
    local playlvl = player:getLevel()

    if (playlvl<300) then
    local min = ((player:getLevel()) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 0,5
    local max = ((player:getLevel()) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 1,0
    return -min, -max
    
    else
    local min = ((300) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 0,5
    local max = ((300) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 1,0
    return -min, -max
    end   
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onGetFormulaValues2(player, skill, attack, skill, factor)

    local maxHealth = player:getMaxHealth()
    local maxMana = player:getMaxMana()
    local playlvl = player:getLevel()

    if (playlvl<300) then
    local min = ((player:getLevel()) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 0,5
    local max = ((player:getLevel()) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 1,0
    return -min, -max
    
    else
    local min = ((300) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 0,5
    local max = ((300) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 1,0
    return -min, -max
    end   
end
combat2:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues2")

function onGetFormulaValues3(player, skill, attack, skill, factor)

    local maxHealth = player:getMaxHealth()
    local maxMana = player:getMaxMana()
    local playlvl = player:getLevel()

    if (playlvl<300) then
    local min = ((player:getLevel()) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 0,5
    local max = ((player:getLevel()) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 1,0
    return -min, -max
    
    else
    local min = ((300) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 0,5
    local max = ((300) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 1,0
    return -min, -max
    end   
end
combat3:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues3")

function onGetFormulaValues4(player, skill, attack, skill, factor)

    local maxHealth = player:getMaxHealth()
    local maxMana = player:getMaxMana()
    local playlvl = player:getLevel()

    if (playlvl<300) then
    local min = ((player:getLevel()) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 0,5
    local max = ((player:getLevel()) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 1,0
    return -min, -max
    
    else
    local min = ((300) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 0,5
    local max = ((300) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 1,0
    return -min, -max
    end   
end
combat4:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues4")

function onCastSpell(creature, variant, player)
    local creatureDirection = creature:getDirection()
    local creaturePos = creature:getPosition()
    if creatureDirection== DIRECTION_SOUTH then
        creaturePos.x = creaturePos.x
        creaturePos.y = creaturePos.y +1
        creaturePos:sendMagicEffect(5)
        combat:execute(creature, variant)
    elseif creatureDirection == DIRECTION_NORTH then
        creaturePos.x = creaturePos.x +1
        creaturePos.y = creaturePos.y -1
        creaturePos:sendMagicEffect(5)
        combat2:execute(creature, variant)
    elseif creatureDirection == DIRECTION_WEST then
        creaturePos.x = creaturePos.x -1
        creaturePos.y = creaturePos.y
        creaturePos:sendMagicEffect(6)
        combat3:execute(creature, variant)
    elseif creatureDirection == DIRECTION_EAST then
        creaturePos.x = creaturePos.x +1
        creaturePos.y = creaturePos.y
        creaturePos:sendMagicEffect(6)
        combat4:execute(creature, variant)
    end
    return true
    end

Both scripts and functions works perfectly separeted, but I can't seem to be able to put them together. Can somebody help me?
 
Back
Top