• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Spell help / skill tries [TFS 1.2]

Aeronx

Intermediate OT User
Joined
Dec 17, 2015
Messages
746
Solutions
9
Reaction score
125
Hello everyone! I've been trying this custom spell.

Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)

function onGetFormulaValues(player, skill, attack, factor)
        if player:getSlotItem(CONST_SLOT_LEFT) == nil then
            return false
        end
    local item = player:getSlotItem(CONST_SLOT_LEFT)
    local weapon = item:getType():getWeaponType()
    local level = player:getLevel()
    local hit = ((2 * (attack * (skill + 5.8) / 25 + (level - 1) / 10)) / factor)
        if weapon == 1 then
        local sword = math.ceil(player:getVocation():getRequiredSkillTries(SKILL_SWORD, player:getSkillLevel(SKILL_SWORD) + 1) / configManager.getNumber(configKeys.RATE_SKILL))
        player:addSkillTries(SKILL_SWORD, sword)
        elseif weapon == 2 then
        local club = math.ceil(player:getVocation():getRequiredSkillTries(SKILL_CLUB, player:getSkillLevel(SKILL_CLUB) + 1) / configManager.getNumber(configKeys.RATE_SKILL))
        player:addSkillTries(SKILL_CLUB, club)
        elseif weapon == 3 then
        local axe = math.ceil(player:getVocation():getRequiredSkillTries(SKILL_AXE, player:getSkillLevel(SKILL_AXE) + 1) / configManager.getNumber(configKeys.RATE_SKILL))
        player:addSkillTries(SKILL_AXE, axe)
        end
        return -(0), -(hit)
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end

It works fine! BUT, i want it to ONLY addskilltries if the spell damaged any player/creature, but dunno how to do it.

Also, is it possible to dissable the autoattack when you have a target?

Thank you all guys!
 
Solution
No. Sorry If i explained myself wrong. The thing is, my spell was adding skills whenever you cast the spell, even if you didnt damage any creature. Now, it adds skills when you HIT your TARGET. But the spell can be used without target, and still damage a monster. (The spell works like ice strike(exori frigo), can be casted on target or direction). I want the spell to add skill when it damages the monster even if you dont have that monster on target.
This requires more than simply casting of a spell because you are looking for confirmation of damage done to the creature from the server. The callback function doesn't send this information. What you need is an additional script in creature events. Especially since you want to add...
Try this:
LUA:
--Edited by Aelu 05/03/2017
--Changed parameters in which "addskilltries" is only triggered by damaged given to a player/monster.
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)

function onGetFormulaValues(player, skill, attack, factor)
  if player:getSlotItem(CONST_SLOT_LEFT) == nil then
    return false
  end

  function onCastSpell(creature, var)
    local item = player:getSlotItem(CONST_SLOT_LEFT)
    local weapon = item:getType():getWeaponType()
    local level = player:getLevel()
    local hit = ((2 * (attack * (skill + 5.8) / 25 + (level - 1) / 10)) / factor)
    if weapon == 1 then
      local sword = math.ceil(player:getVocation():getRequiredSkillTries(SKILL_SWORD, player:getSkillLevel(SKILL_SWORD) + 1) / configManager.getNumber(configKeys.RATE_SKILL))
      player:addSkillTries(SKILL_SWORD, sword)
    elseif weapon == 2 then
      local club = math.ceil(player:getVocation():getRequiredSkillTries(SKILL_CLUB, player:getSkillLevel(SKILL_CLUB) + 1) / configManager.getNumber(configKeys.RATE_SKILL))
      player:addSkillTries(SKILL_CLUB, club)
    elseif weapon == 3 then
      local axe = math.ceil(player:getVocation():getRequiredSkillTries(SKILL_AXE, player:getSkillLevel(SKILL_AXE) + 1) / configManager.getNumber(configKeys.RATE_SKILL))
      player:addSkillTries(SKILL_AXE, axe)
    end
    return -(0), -(hit)
  end
 
That wont work. First of all, there's no player on oncast, secondly, even if it worked it would add skilltries on cast, not on healthchange, also, you deleted combat callback.. wtf..

Anyone that could help me out?

Really appreciate it! Thanks!
 
Last edited by a moderator:
Try this I haven't tested it at all.
LUA:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)

local rate = configManager.getNumber(configKeys.RATE_SKILL)
local cid = 0
local skills = {
    [1] = 2,
    [2] = 1,
    [3] = 3
}

function onGetFormulaValues(player, skill, attack, factor)
    local item = player:getSlotItem(CONST_SLOT_LEFT)

    if not item or item == 0 then
        return false
    end
  
    local weapon = item:getType():getWeaponType()
    local level = player:getLevel()
    local creature = Creature(cid)
    if creature then
        if skills[weapon] then
            player:addSkillTries(skills[weapon], math.ceil(player:getVocation():getRequiredSkillTries(skills[weapon], player:getSkillLevel(skills[weapon]) + 1) / rate))
        end
    end

    return 0, -((2 * (attack * (skill + 5.8) / 25 + (level - 1) / 10)) / factor)
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onCastSpell(creature, var)
    cid = var['number'] or var.number
    return combat:execute(creature, var)
end
 
@complete blank Hello! Thanks for the help. It works. It only adds skills when you have a target and it damages it. BUT, if you dont have a target, and you damage the creature (Because im using targerordirection = 1 on spells.xml), it doesnt add any skills. Anyway to solve the targetless problem?
 
@complete blank Hello! Thanks for the help. It works. It only adds skills when you have a target and it damages it. BUT, if you dont have a target, and you damage the creature (Because im using targerordirection = 1 on spells.xml), it doesnt add any skills. Anyway to solve the targetless problem?
Sorry I don't understand. You asked for it to add skills if it had a target. Do you want it to not damage the creature if there is no target?
 
No. Sorry If i explained myself wrong. The thing is, my spell was adding skills whenever you cast the spell, even if you didnt damage any creature. Now, it adds skills when you HIT your TARGET. But the spell can be used without target, and still damage a monster. (The spell works like ice strike(exori frigo), can be casted on target or direction). I want the spell to add skill when it damages the monster even if you dont have that monster on target.
 
No. Sorry If i explained myself wrong. The thing is, my spell was adding skills whenever you cast the spell, even if you didnt damage any creature. Now, it adds skills when you HIT your TARGET. But the spell can be used without target, and still damage a monster. (The spell works like ice strike(exori frigo), can be casted on target or direction). I want the spell to add skill when it damages the monster even if you dont have that monster on target.
This requires more than simply casting of a spell because you are looking for confirmation of damage done to the creature from the server. The callback function doesn't send this information. What you need is an additional script in creature events. Especially since you want to add skills if the you have no target.
 
Last edited:
Solution
yep, thats what i thought. I'll try to figure it out.
Another quick question. How can i do the spell to check for weapon extra damage (+15 fire for exemple) and apply it to the damage formula?
 
Unfortunately there is no method to get the extra stats of an item that I am aware of elementFire is an attribute of the fire sword but there is no direct means of getting that value aside from using an onHealthChange/onManaChange the worse part about this is that if you are to use either of those it needs to be applied to all creatures you intend to affect.

If you are unsure of how to use onHealthChange/onManaChange then read up on this tutorial written by Evan
[TFS 1.0] Critical Hit % - Permanent
 
What about this 2 methods?

Code:
itemType:getElementDamage()
itemType:getElementType()

Okey, tested. getElementDamage() print on fire sword gives you a 11, which is the fire sword fire damage, and the ElementType() prints gives a 8 which is fire element. I think i can work with that.
 
You can finish the script I am sure, its been fun. :)
LUA:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)

local rate = configManager.getNumber(configKeys.RATE_SKILL)
local cid = 0
local skills = {
    [1] = 2,
    [2] = 1,
    [3] = 3
}
-- does the spell need a target to do damage?
local needsTarget = true

function onGetFormulaValues(player, skill, attack, factor)
    local item = player:getSlotItem(CONST_SLOT_LEFT)

    if not item or item == 0 then
        return false
    end

    -- in case you want to run a comparison on the types
    local element = item:getType():getElementType()
    -- just in case the weapon doesn't have a elemental damge assigned 1 to it
    local damage = item:getType():getElementDamage() or 1

    --[[
        place your additional code here, comparison, damage manipulation etc..
        without the block comment of course ;)
    ]]
  
    local weapon = item:getType():getWeaponType()
    local level = player:getLevel()
    local creature = Creature(cid)
    if creature then
        if skills[weapon] then
            player:addSkillTries(skills[weapon], math.ceil(player:getVocation():getRequiredSkillTries(skills[weapon], player:getSkillLevel(skills[weapon]) + 1) / rate))
        end
    end

    return needsTarget and 0, -((2 * (attack * (skill + 5.8) / 25 + (level - 1) / 10)) / factor) or 0, 0
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onCastSpell(creature, var)
    cid = var['number'] or var.number
    return combat:execute(creature, var)
end
 
Last edited:
Back
Top