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

How to use addEvent()

Mesut Ozil

New Member
Joined
Jul 8, 2016
Messages
27
Reaction score
0
hello otland commuinty i know there is tutorial about how to use addevent() in scripts but i didn't understand what it really doing and how i use it if i want to make effect appear on player after 5 seconds such as
 
Here's a basic timed lever script. It uses addEvent.
Code:
local function reset(pos)
     doTransformItem(getTileItemById(pos, 1946).uid, 1945)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)

     -- check if lever is currently used
     if item.itemid == 1946 then
         return doPlayerSendTextMessage(cid, 22, "Wait for switch to reset.")
     end

     -- transform lever, and add reset
     doTransformItem(item.uid, item.itemid + 1)
     addEvent(reset, 10 * 1000, toPosition)

     return true
end
Here's a decent way to loop through multiple actions.
Code:
local loop_1_amount = 5
local loop_1_delay = 2000
local function loop_1(n)

     local count = ((loop_1_amount - n) + 1)
     if count == 1 then
         print("One.")
     elseif count == 2 then
         print("Two.")
     elseif count == 3 then
         print("Three.")
     elseif count == 4 then
         print("Four.")
     elseif count == 5 then
         print("Five.")
     end

     if(n > 0) then
         addEvent(loop_1, loop_1_delay, n - 1)
     end

end

local function reset(pos)
     doTransformItem(getTileItemById(pos, 1946).uid, 1945)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)

     -- check if lever is currently used
     if item.itemid == 1946 then
         return doPlayerSendTextMessage(cid, 22, "Wait for switch to reset.")
     end

     addEvent(loop_1, 0, loop_1_amount)

     -- transform lever, and add reset
     doTransformItem(item.uid, item.itemid + 1)
     addEvent(reset, 10 * 1000, toPosition)

     return true
end
Make an infinite loop. (Unless you reload actions..)
Code:
local loop_1_delay = 5000
local function loop_1(cid)
     doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
     addEvent(loop_1, loop_1_delay)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
     addEvent(loop_1, 0, cid)
     return true
end

-- Edit

All 0.3.x scripting, for the record.

Cheers.
 
Last edited:
easy way to use it { work for 0.4} but try to understand
Xikini post will help u too much
Code:
local function GoBack(cid)
    if(not isPlayer(cid)) then
        return
    end

    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)  --- add any effect u need
    doSendAnimatedText(getPlayerPosition(cid), "WOW!", COLOR_GREY)---- add any word u need
    return true
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
whatever here
addEvent(GoBack,5*1000, cid)  --- this 5 seconds   if u want 10 seconds 10*1000
end
  return true
end
 
Last edited:
easy way to use it { work for 0.4} but try to understand
Xikini post will help u too much
Code:
local function GoBack(cid, pos)
    if(not isPlayer(cid)) then
        return
    end

    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)  --- add any effect u need
    doSendAnimatedText(getPlayerPosition(cid), "WOW!", COLOR_GREY)---- add any word u need
    return true
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
whatever here
addEvent(GoBack,5*1000, cid, pos)  --- this 5 seconds   if u want 10 seconds 10*1000
end
  return true
end
why you call pos and then use "getCreaturePosition(cid)"
 
Back
Top