• 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+ Weapons with advantage vs some vocation

Calder

New Member
Joined
Jul 21, 2019
Messages
21
Reaction score
4
Location
Chile
TFS 1.3.10
Hello again, following the example of this post: Weapons with advantage vs some monsters
Is it possible to make a weapon have an advantage against vocation?

Code:
-- Normal combat damage
local combat_normal = Combat()
combat_normal:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat_normal:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat_normal:setFormula(COMBAT_FORMULA_SKILL, 0, 0, 1, 0)  -- normal damage

-- Combat damage against dragons
local combat_dragons = Combat()
combat_dragons:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat_dragons:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat_dragons:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat_dragons:setFormula(COMBAT_FORMULA_SKILL, 0, 0, 2, 0)  -- damage x 2


-- On use weapon
function onUseWeapon(player, variant)
    local target = Monster(variant.number)
    -- Is target a monster
    if target and target:isMonster() then
        -- Does the target have "dragon" somewhere in the creature name
        if target:getName():lower():find("dragon") then
            -- Use combat_dragons combat object
            return combat_dragons:execute(player, variant)
        end
    end
    -- Use normal combat object
    return combat_normal:execute(player, variant)
end


I think this function can help (taken from an npc) player:getVocation():getBase():getId() == 4 (knight)

1 = Sorcerer
2 = Druid
3 = Paladin
5= MS
6= ED
7= RP
8 =EK
 
Solution
Lua:
-- Normal combat damage
local combat_normal = Combat()
combat_normal:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat_normal:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat_normal:setFormula(COMBAT_FORMULA_SKILL, 0, 0, 1, 0)  -- normal damage

-- Combat damage modified
local combat_modified = Combat()
combat_modified:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat_modified:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat_modified:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)

local tVocs= {
   [{1,5}] = { -- sorcerer
    damage= 2
   },
   [{2,6}] = { -- druid
    damage = 2
   },
   [{3,7}] = { -- paladin
     damage= 3
   },
   [{4,8}] = { -- knight
        damage = 4
    }
}

-- On use weapon...
Lua:
-- Normal combat damage
local combat_normal = Combat()
combat_normal:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat_normal:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat_normal:setFormula(COMBAT_FORMULA_SKILL, 0, 0, 1, 0)  -- normal damage

-- Combat damage modified
local combat_modified = Combat()
combat_modified:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat_modified:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat_modified:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)

local tVocs= {
   [{1,5}] = { -- sorcerer
    damage= 2
   },
   [{2,6}] = { -- druid
    damage = 2
   },
   [{3,7}] = { -- paladin
     damage= 3
   },
   [{4,8}] = { -- knight
        damage = 4
    }
}

-- On use weapon
function onUseWeapon(player, variant)
    local target = Player(variant.number)
    if target and target:isPlayer() then
      local vocId = target:getVocation():getId()
        for voc, x in pairs(tVocs) do
            if isInArray(voc, vocId) then
                combat_modified:setFormula(COMBAT_FORMULA_SKILL, 0, 0, x.damage, 0)
                return combat_modified:execute(player, variant)
            end
        end
    end
    -- Use normal combat object
    return combat_normal:execute(player, variant)
end
 
Solution
Back
Top