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

Solved Run script as long as there is a target with delay

mackerel

Well-Known Member
Joined
Apr 26, 2017
Messages
398
Solutions
18
Reaction score
72
HI, Have this script here but its not working exactly as I want it to

I want the script to run(doCombat) as long as the player has target every 500ms but it happens only once

Lua:
    local timeX = 500
    local y = 1
    for i = 1, y do
        addEvent(function()
            local target = Player(cid):getTarget()
            if target then
                doCombat(cid, combat, var)
                y = y + 1
                timeX = timeX + 500
            end
        end, timeX)
    end

TFS 1.0
If you can help me that would be great

edit/fixed

Lua:
    function repeatX()
            local target = Player(cid):getTarget()
            if target then
                doCombat(cid, combat, var)
                addEvent(repeatX, 500)
            end
    end
 
Last edited:
Solution
HI, Have this script here but its not working exactly as I want it to

I want the script to run(doCombat) as long as the player has target every 500ms but it happens only once

Lua:
    local timeX = 500
    local y = 1
    for i = 1, y do
        addEvent(function()
            local target = Player(cid):getTarget()
            if target then
                doCombat(cid, combat, var)
                y = y + 1
                timeX = timeX + 500
            end
        end, timeX)
    end

TFS 1.0
If you can help me that would be great

edit/fixed

Lua:
    function repeatX()
            local target = Player(cid):getTarget()
            if target then
                doCombat(cid, combat, var)
                addEvent(repeatX...
HI, Have this script here but its not working exactly as I want it to

I want the script to run(doCombat) as long as the player has target every 500ms but it happens only once

Lua:
    local timeX = 500
    local y = 1
    for i = 1, y do
        addEvent(function()
            local target = Player(cid):getTarget()
            if target then
                doCombat(cid, combat, var)
                y = y + 1
                timeX = timeX + 500
            end
        end, timeX)
    end

TFS 1.0
If you can help me that would be great

edit/fixed

Lua:
    function repeatX()
            local target = Player(cid):getTarget()
            if target then
                doCombat(cid, combat, var)
                addEvent(repeatX, 500)
            end
    end

Always check if a userdata value is nil before indexing it.
Use combat:execute(...) insted of doCombat(...)

Lua:
local player = Player(cid)
if not player then
    return false
end

local target = player:getTarget()
if target then
    combat:execute(player, var)
    addEvent(repeatX, 500)
end
 
Solution
Back
Top