• 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 put loop function?

chupaescadatri

Banned User
Joined
Jul 5, 2014
Messages
338
Reaction score
49
I click on a button the function is looped?

example..
I clicked on the button and the character is talking hi without stopping
Or walking upwards without stopping
 
How to make button and make something execute 'on click' you must find by yourself.
This is code you must execute to make player walk north 5 times per second (every 0.2 sec):
PHP:
myLoopEventId = 0

function myLoop()
    local dashWalk = true
    g_game.walk(Directions.North, dashWalk)

    -- execute same function after 0.2 sec, function call itself = we good loop (but with delay)
    myLoopEventId = scheduleEvent(myLoop, 200)
end

-- this will start event
myLoop()

-- to stop execution of event you must call:
removeEvent(myLoopEventId)
There is also code you need to call to 'stop' this event.

You can't use 'for' or 'while', because normal 'loop' will execute in 0.001 sec (and for time of execution it will freez client).
You can't use any 'sleep' command, because it will freez whole client for time of 'sleep'.
For your kind of problems there is 'scheduleEvent' function which execute your function with some delay. In OTSes is same function, but under name 'addEvent'.
 
How to make button and make something execute 'on click' you must find by yourself.
This is code you must execute to make player walk north 5 times per second (every 0.2 sec):
PHP:
myLoopEventId = 0

function myLoop()
    local dashWalk = true
    g_game.walk(Directions.North, dashWalk)

    -- execute same function after 0.2 sec, function call itself = we good loop (but with delay)
    myLoopEventId = scheduleEvent(myLoop, 200)
end

-- this will start event
myLoop()

-- to stop execution of event you must call:
removeEvent(myLoopEventId)
There is also code you need to call to 'stop' this event.

You can't use 'for' or 'while', because normal 'loop' will execute in 0.001 sec (and for time of execution it will freez client).
You can't use any 'sleep' command, because it will freez whole client for time of 'sleep'.
For your kind of problems there is 'scheduleEvent' function which execute your function with some delay. In OTSes is same function, but under name 'addEvent'.
Thanks man, but console is
Code:
ERROR: caught a lua call to a bot protected game function, the call was cancelled
stack traceback:
    [C]: ?
    [C]: in function 'walk'
 
Most of functions are blocked in 'scheduleEvent', because these functions are required to make any bot (walk, use item, say something [spell to heal etc.]) - to make bot 'work automatically' you need to create some 'loop' that watch HP and heal player = you need scheduleEvent.
If you want to use functions 'for bots' you need to compile OTClient without 'BOT_PROTECTION' flag (compilator flag) or without that code (just remove these lines from source):
otclient/game.cpp at 2292df922d4a77de90802209f0b06423cc4b2699 · edubart/otclient · GitHub

If you use client of some OTS (got only compiled .exe), you cannot use most of LUA functions in 'scheduleEvent', because author of that OTS decided to block simple bots.
 
Most of functions are blocked in 'scheduleEvent', because these functions are required to make any bot (walk, use item, say something [spell to heal etc.]) - to make bot 'work automatically' you need to create some 'loop' that watch HP and heal player = you need scheduleEvent.
If you want to use functions 'for bots' you need to compile OTClient without 'BOT_PROTECTION' flag (compilator flag) or without that code (just remove these lines from source):
otclient/game.cpp at 2292df922d4a77de90802209f0b06423cc4b2699 · edubart/otclient · GitHub

If you use client of some OTS (got only compiled .exe), you cannot use most of LUA functions in 'scheduleEvent', because author of that OTS decided to block simple bots.
Thanks!!!!
 
Most of functions are blocked in 'scheduleEvent', because these functions are required to make any bot (walk, use item, say something [spell to heal etc.]) - to make bot 'work automatically' you need to create some 'loop' that watch HP and heal player = you need scheduleEvent.
If you want to use functions 'for bots' you need to compile OTClient without 'BOT_PROTECTION' flag (compilator flag) or without that code (just remove these lines from source):
otclient/game.cpp at 2292df922d4a77de90802209f0b06423cc4b2699 · edubart/otclient · GitHub

If you use client of some OTS (got only compiled .exe), you cannot use most of LUA functions in 'scheduleEvent', because author of that OTS decided to block simple bots.
Now bot protection is disable, but..
Code:
 Unable to send extended opcode 1, extended opcodes are not enabled
 
Yes =)

Code:
local anda
function anda()
        g_game.walk(North)
end

        icon.onClick = function() scheduleEvent(anda(), 2000) end
Error about OPCode 1 is there everytime you login characer. It's not related to your code. Some OTC .lua script tries to send 'extra code with ID 1', server did not send 'OP codes enable' in login packet, so it shows that error.

Your code is almost good, you just need to replace:
Code:
function() scheduleEvent(anda(), 2000) end
with:
Code:
function() scheduleEvent(anda, 2000) end
because 'scheduleEvent' expects first argument to be function pointer ( anda = function name/pointer), not result of function execution ( anda() = result of function)
 
Error about OPCode 1 is there everytime you login characer. It's not related to your code. Some OTC .lua script tries to send 'extra code with ID 1', server did not send 'OP codes enable' in login packet, so it shows that error.

Your code is almost good, you just need to replace:
Code:
function() scheduleEvent(anda(), 2000) end
with:
Code:
function() scheduleEvent(anda, 2000) end
because 'scheduleEvent' expects first argument to be function pointer ( anda = function name/pointer), not result of function execution ( anda() = result of function)
Thank you, all my doubts resolved, it worked!
 
Back
Top