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

[Weapon] TFS 1.3 Chance to double hit (commented)

Oneda

Aspiring Spriter
Joined
Dec 3, 2013
Messages
159
Solutions
2
Reaction score
104
Location
Brazil
Hey bois, just made a script for double-hitting weapons with configurable chance, this is literally pretty simple and was made for study purposes only, so if yall find any mistakes or anything that could had been better implemented, please let me know!

Commented most likely every single line of the code just so starters like me can use this as a study base.

Preview GIF (50% Chance):
DWswKhx5si.gif

weapons.xml:
XML:
<melee id="WEAPON_ID" level="REQUIRED_LEVEL" script="double.lua" />

double.lua:
Lua:
local animEffect = 5 -- Custom effect ID/name for when the double hit procs
local procChance = 25 -- Chance for the Double Hit to proc.

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE) -- Damage type
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true) -- Is the damage affected by enemies armor? (not really sure but I'm guessing thats what it does)
combat:setFormula(COMBAT_FORMULA_SKILL, 0, 0, 1, 0) -- Damage Formula

function doDoubleHit(player, variant) -- Function to be the callback of our addEvent later on
    return combat:execute(player, variant)
end

function onUseWeapon(player, variant)
local chance = math.random(1,100) -- Defines a random number from 1 to 100
    if chance <= procChance then -- If the number defined on the above variable is lesser or equal to the procChance, runs the code below
        combat:setParameter(COMBAT_PARAM_EFFECT, animEffect) -- As we now know it is a double hit, this line defines a new effect for the combat hit.
        combat:execute(player, variant) -- Executes the first hit
        addEvent(doDoubleHit, 500, player:getId(), variant) -- Adds an event with the doDoubleHit callback, called in 500ms
        player:say("DOUBLE", TALKTYPE_MONSTER_SAY) -- We would like the player to know he just got a double hit, so we make him say "DOUBLE" in orange.
    else return combat:setParameter(COMBAT_PARAM_EFFECT, 1) and combat:execute(player, variant) end
    -- If the number generated on the chance variable is not lesser or equal to the procChance, then it sets the animation effect to the default one and executes the combat hit as usual.
end
 
Last edited:
Are you sure the script above works? You are passing to the doDoubleHit function a player_id as a parameter. However, if I'm not mistaking, combat:execute(player, variant) requires a player object to work. Am I missing something?

The correct function should be as follows:
Lua:
function doDoubleHit(id, variant)
    local player = Player(id)
    if not player then
        return
    end
    combat:execute(player, variant)
end
 
Are you sure the script above works? You are passing to the doDoubleHit function a player_id as a parameter. However, if I'm not mistaking, combat:execute(player, variant) requires a player object to work. Am I missing something?

The correct function should be as follows:
Lua:
function doDoubleHit(id, variant)
    local player = Player(id)
    if not player then
        return
    end
    combat:execute(player, variant)
end

Pretty sure it works as I was testing it out and debugging while scripting. Not really sure if that would make it have any breaches for exploits or any ways of abusing it tho.

Edit for including a gif of it working with a 50% chance:
DWswKhx5si.gif
 
Last edited:
Are you sure the script above works? You are passing to the doDoubleHit function a player_id as a parameter. However, if I'm not mistaking, combat:execute(player, variant) requires a player object to work. Am I missing something?

The correct function should be as follows:
Lua:
function doDoubleHit(id, variant)
    local player = Player(id)
    if not player then
        return
    end
    combat:execute(player, variant)
end
nope, tfs is made to be backwards compatible, so:

Most of the c++ methods take cids properly just like userdata.
 
Back
Top