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

TFS 1.X+ aoe attack weapon

Darius93

Active Member
Joined
Oct 16, 2022
Messages
88
Reaction score
27
I want to make an AOE attack, but I’d like to adjust it for my server.
I’d like the player who hits a monster with a weapon that has “rare” in its name to deal area damage, but only to monsters. I’ll set the damage multiplier myself, but I’m wondering how to implement something like that.


In general, I could do something like this inside the weapon scripts, but then I’d have to make a separate script for every weapon.
Does anyone have an idea how to do this in the best way? Also, in a way that wouldn’t put too much load on the server?

TFS 1.2
 
You can use onHealthChange event and check origin of damage, for weaponattack it will be ORIGIN_MELEE or ORIGIN_RANGED:
IDK how it will work for wands, on newest TFS there is extra ORIGIN_WAND.

Event has parameters onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin):
To reduce CPU usage by Lua, you should add player:getWeapon() in C++ or even player:isWeaponRare() to process slot items and their name/attributes in C++.
Then you can call in Lua doAreaCombat(cid, type, pos, area, min, max, effect[, origin = ORIGIN_SPELL[, blockArmor = false[, blockShield = false[, ignoreResistances = false]]]]) or list creatures hit by given area combat, check if they are monsters and deal damage only to monsters.

It will waste a lot of CPU. I've seen systems like that, that wasted 1% of total CPU power.

Effective implementation would be 100% in C++. Where you can getSpectators and call same 'Combat' object on multiple monsters.
It should be added below that line:
 
LUA:
-- prosty standardowy combat (fizyczny)
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, true)
setCombatParam(combat, COMBAT_PARAM_BLOCKSHIELD, true)

-- formuła oparta na skillu (tak jak w twoim wcześniejszym przykładzie)
-- (parametry można dopasować do swojego serwera)
setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1, 0)

-- funkcja wywoływana przy użyciu broni
function onUseWeapon(cid, var)
    -- nie robimy żadnych dodatkowych efektów, tylko standardowy atak
    return doCombat(cid, combat, var)
end

So what if I used this code — of course, I’d modify it a bit, kind of like how the burst arrow works.

Basically, I’d make it check on every hit whether the weapon’s name contains “rare”.
Then I’d just make one script and attach it to all weapons.

What do you think — would that cause a lot of server load?
I’m making a server for around 50 players max 😄
 
LUA:
local plagueBite = Weapon(WEAPON_AXE)

local combat1 = createCombatObject()
setCombatParam(combat1, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatParam(combat1, COMBAT_PARAM_EFFECT, 38)
setCombatFormula(combat1, COMBAT_FORMULA_SKILL, 0, 0, 1.3, 0)
 
local combat2 = createCombatObject()

setCombatParam(combat2, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatFormula(combat2, COMBAT_FORMULA_SKILL, 0, 0, 1.0, 0)

local arr = {
    {0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 1, 1, 0, 0, 0},
    {0, 0, 1, 1, 1, 1, 0, 0, 0},
    {0, 0, 1, 1, 3, 1, 1, 0, 0},
    {0, 0, 0, 1, 1, 1, 1, 0, 0},
    {0, 0, 0, 1, 1, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0}
}

local area = createCombatArea(arr)
setCombatArea(combat1, area)

plagueBite.onUseWeapon = function(player, variant)
    local rand = math.random(0, 100)
    if 10 <= rand then
        return doCombat(player, combat1, variant)
    end
    return combat2:execute(player, variant)
end

plagueBite:id(25415)
plagueBite:register()
some old script, it's ugly but show how to deal aoe damage

--------------------------------------

for no damaging players you can do something like this, this also work for all sources of damage like spells
LUA:
function Creature:onTargetCombat(target)
    if self and target and self:getPlayer() and target:getPlayer() then
        if self:hasSecureMode() then
            return RETURNVALUE_NOTPOSSIBLE
        end
    end
    if hasEvent.onTargetCombat then
        return Event.onTargetCombat(self, target)
    end
    return RETURNVALUE_NOERROR
end

also ugly xd

@edit well... im missing second part of the question... please ignore this response :|
 
Last edited:
Back
Top