• 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 cancel countdown on battle.

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
580
Solutions
2
Reaction score
58
Location
México
Hello, bois im trying to cancel a countdown if player enters in battle.
but it doesnt work and i dont know what im doing bad
here is the script
Lua:
local function countDown2(number, cid)
   local n = number
   for i = 1, number do
        if getCreatureCondition(cid, CONDITION_INFIGHT) == false then
           addEvent(doPlayerSendCancel, i*1000, cid, "Time left: ".. os.date("%M:%S",(n)) .."")
           n = n -1
        end
   end
   n = number
   return true
end
 
Solution
Why do you keep using that broken loop I told you to stop using? lol
You are creating THOUSANDS of addevents because of that, when the entire purpose of using the external function is so you don't have all of those extra addEvents running.

Lua:
local function countDown2(number, cid)
    if not isPlayer(cid) then -- here we check that the player hasn't died or logged out, so functions further in the script don't give us errors.
        return true
    end
    if getCreatureCondition(cid, CONDITION_INFIGHT) == false then
        doPlayerSendCancel(cid, "Time left: " .. os.date("%M:%S", number))
        if number ~= 0 then -- put this inside of the other if statement, because the 'buff' is only supposed to continue if they aren't in battle...
Why do you keep using that broken loop I told you to stop using? lol
You are creating THOUSANDS of addevents because of that, when the entire purpose of using the external function is so you don't have all of those extra addEvents running.

Lua:
local function countDown2(number, cid)
    if not isPlayer(cid) then -- here we check that the player hasn't died or logged out, so functions further in the script don't give us errors.
        return true
    end
    if getCreatureCondition(cid, CONDITION_INFIGHT) == false then
        doPlayerSendCancel(cid, "Time left: " .. os.date("%M:%S", number))
        if number ~= 0 then -- put this inside of the other if statement, because the 'buff' is only supposed to continue if they aren't in battle.
            addEvent(countDown2, 1000, number - 1, cid) -- here we LOOP THE FUNCTION after 1000 milliseconds
        end
    else
        doPlayerSendCancel(cid, "Cancelled. Player has entered combat.")
    end
    return true
end
 
Solution
Back
Top