Setting Up Threading With Status Tutorial

A lot of people have been asking me how I show the “Status” or “Live Logs” of what the bot is doing during runtime. I have made this UBot script for you guys who want to show “Status With Threading” which you can use in your bots.

 

This script uses the “Thread Counter Plugin” from UBot Dev, if you don’t have it I would highly recommend installing it and using it with every bot you make that is multithreaded! You can get the plugin here: http://ubotdev.com/free-plugin-threads-counter

This script uses two &tables one for finding a “FREE Thread ID” and one to hold the “Threading Status”.

Anyhow here is the UBot Code for you to take a look at:

 


ui html panel("<!DOCTYPE html>
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
<link href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css\" rel=\"stylesheet\"/>
<title>Threading With Status Example</title>
</head>
<body>

<div class=\"container\">
<div class=\"row\">
<div class=\"col-md-6\">
<form class=\"form\">
<div class=\"form-group\">
<label>COUNT:</label>
<select class=\"form-control\" variable=\"#ui_Count\">
<option>10</option>
<option>20</option>
<option>30</option>
<option>40</option>
<option>50</option>
</select>
</div>
<div class=\"form-group\">
<label>THREAD COUNT:</label>
<select class=\"form-control\" variable=\"#ui_Thread_Count\">
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select>
</div>

<div class=\"form-group\">
<textarea class=\"form-control\" rows=\"10\" variable=\"#ui_Thread_Status\"></textarea>

</div>
<div class=\"form-group\">
<div class=\"row\">
<div class=\"col-md-6\">
<label>THREADS ACTIVE: <span variable=\"#Threads_ACTIVE\" fillwith=\"innertext\"></span></label>
</div>
<div class=\"col-md-6\">
<label>COUNT: <span variable=\"#COUNT\" fillwith=\"innertext\"></span></label>
</div>

</div>
</div>

</form>
</div>
</div>
</div>

</div>
</body>
</html>
", 400)
Start Bot()
define Start Bot {
set(#Threads_ACTIVE, $plugin function("Threads Counter.dll", "threads counter", "reset"), "Global")
set(#Thread_MAX, #ui_Thread_Count, "Global")
set(#COUNT, #ui_Count, "Global")
Setup_Thread_Status()
Start Threading()
}
define Start Threading {
loop while($comparison(#COUNT, ">", 0)) {
if($comparison($plugin function("Threads Counter.dll", "threads counter", "read"), "<", #Thread_MAX)) {
then {
set(#Threads_ACTIVE, $plugin function("Threads Counter.dll", "threads counter", "increment"), "Global")
thread {
in new browser {
THREAD START($Get Thread ID Row())
set(#Threads_ACTIVE, $plugin function("Threads Counter.dll", "threads counter", "decrement"), "Global")
}
}
decrement(#COUNT)
wait(0.2)
}
else {
wait(0.2)
}
}
}
comment("Wait for threads to finish")
loop while($comparison(#Threads_ACTIVE, ">", 0)) {
wait(1)
}
alert("Complete!")
}
define THREAD START(#ID) {
set(#ID, #ID, "Local")
set(#Wait_Count, 1, "Local")
loop(3) {
set(#Random_Wait, $rand(3, 10), "Local")
Set Thread Status(#ID, "Waiting {#Wait_Count}/3 for {#Random_Wait} sec..")
wait(#Random_Wait)
increment(#Wait_Count)
}
Set Thread Status(#ID, "Complete!")
comment("DONT FORGET THIS!!")
Set Thread Status(#ID, "END")
}
comment("THREADING WITH STATUS COMMANDS")
define Setup_Thread_Status {
clear table(&Thread_Status)
clear table(&Free_Threads)
set(#Row, 0, "Local")
loop(#Thread_MAX) {
set table cell(&Free_Threads, #Row, 0, "FREE")
set table cell(&Free_Threads, #Row, 1, #Row)
increment(#Row)
}
}
define $Get Thread ID Row {
set(#Found, $false, "Local")
set(#Row, 0, "Local")
loop while($comparison(#Found, "=", $false)) {
if($comparison($table total rows(&Free_Threads), "=", #Row)) {
then {
set(#Row, 0, "Local")
}
else {
}
}
if($comparison($table cell(&Free_Threads, #Row, 0), "=", "FREE")) {
then {
set table cell(&Free_Threads, #Row, 0, "USING")
set(#Found, $true, "Local")
return($table cell(&Free_Threads, #Row, 1))
}
else {
}
}
increment(#Row)
}
}
comment("SET YOUR UI TEXTAREA VAR IN THIS COMMAND")
define Set Thread Status(#Thread_ID, #Thread_Status) {
set(#Thread_ID, #Thread_ID, "Local")
set(#Thread_Status, #Thread_Status, "Local")
if($comparison(#Thread_Status, "=", "END")) {
then {
set table cell(&Free_Threads, #Thread_ID, 0, "FREE")
}
else {
set table cell(&Thread_Status, #Thread_ID, 0, "[THREAD {#Thread_ID}] {#Thread_Status}")
}
}
comment("CHANGE THIS VARIABLE TO YOUR UI TEXTAREA")
set(#ui_Thread_Status, &Thread_Status, "Global")
}

 

I hope you find this tutorial helpful and feel free to ask any questions below!

Carl Smith

(LazyBotter)

Comments are closed.