• 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 Addevent not working as intended

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,424
Solutions
15
Reaction score
176
Location
Sweden
Why wont this hit twice? tfs 1.3, the second time it will only display the hitarea effect.

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)


function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.01) + 1
    local max = (player:getLevel() / 5) + (skill * attack * 0.03) + 6
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(player, variant)
    if not combat:execute(player, variant) then
        return false
    end
   
    function doubleHit()
    combat:execute(creature, variant)
    end
    doubleHit()
    addEvent(doubleHit, 500)
   
    return true
end
 
Solution
try this

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)


function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.01) + 1
    local max = (player:getLevel() / 5) + (skill * attack * 0.03) + 6
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

local function combatSpell(cid, variant)
    local player = Player(cid)
    if not player then
        return
    end
    return combat:execute(player, variant)
end

function onUseWeapon(player, variant)
    for i = 1, 2...
try this

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)


function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.01) + 1
    local max = (player:getLevel() / 5) + (skill * attack * 0.03) + 6
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

local function combatSpell(cid, variant)
    local player = Player(cid)
    if not player then
        return
    end
    return combat:execute(player, variant)
end

function onUseWeapon(player, variant)
    for i = 1, 2 do
        addEvent(combatSpell, 500 * (i -1), player:getId(), variant)
    end
    return true
end
 
Solution
try this

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)


function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.01) + 1
    local max = (player:getLevel() / 5) + (skill * attack * 0.03) + 6
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

local function combatSpell(cid, variant)
    local player = Player(cid)
    if not player then
        return
    end
    return combat:execute(player, variant)
end

function onUseWeapon(player, variant)
    for i = 1, 2 do
        addEvent(combatSpell, 500 * (i -1), player:getId(), variant)
    end
    return true
end
So instead of (i -1), change loop to i = 0, 1 and simply use 500 * i.
 
try this

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)


function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.01) + 1
    local max = (player:getLevel() / 5) + (skill * attack * 0.03) + 6
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

local function combatSpell(cid, variant)
    local player = Player(cid)
    if not player then
        return
    end
    return combat:execute(player, variant)
end

function onUseWeapon(player, variant)
    for i = 1, 2 do
        addEvent(combatSpell, 500 * (i -1), player:getId(), variant)
    end
    return true
end

So instead of (i -1), change loop to i = 0, 1 and simply use 500 * i.
Thanks, that solved it, I still think its weird though that a normal addEvent wouldn't do it, i parsed both creature and variant before aswell but same thing. Thanks again!
And when I have both of you clever-asses here, no pun intended, would you mind to help with this aswell since its driving me nuts:
OTClient - In client issues? (https://otland.net/threads/in-client-issues.277697/)

I have actually printed in the code with changing outfit, and it prints. But it will still not change when clicking "ok" in the outfit window.
 
Back
Top