Jump to content
UBot Underground

Share: Start - Stop Button and Status Update


Recommended Posts

Hello.

 

I want to share a small script with you. That's something I'm using in almost all my bots. 

 

Goals:

Prevent users from hitting start button multiple times.

Wait and repeat a command until stop button is pressed.

Stop everything with Stop button.

 

 

Challenge: In the past I was using "stop script()" for this task. But Ubot V5 has changed the behavior of the Stop script command. 

So this is not longer usable because it will stop other threads as well.

 

So I changed my default code a little bit. 

 

I also implemented a method so that the status code is not longer updated after the STOP button has been pressed.

 

 

 

 

ui stat monitor("Status"#status)
on load("Bot Loaded") {
    set(#running"false""Global")
    set(#stop"true""Global")
}
ui button("Start") {
    if($comparison(#running"=""true")) {
        then {
            alert("Task is already running. Please wait.")
        }
        else {
            set(#running"true""Global")
            set(#stop"false""Global")
            statusupdate("Starting Bot....")
            loop while($comparison(#stop"=""false")) {
                comment("YOUR COMMAND HERE")
                set(#waitcounter, 5, "Global")
                loop(#waitcounter) {
                    statusupdate("Waiting:  {#waitcounter}")
                    wait(1)
                    decrement(#waitcounter)
                }
            }
            set(#status"Bot stopped.""Global")
            set(#running"false""Global")
        }
    }
}
ui button("Stop") {
    if($comparison(#stop"!=""true")) {
        then {
            set(#stop"true""Global")
            set(#status"Stopping Bot....""Global")
        }
    }
}
define statusupdate(#text) {
    if($comparison(#stop"!=""true")) {
        then {
            set(#status#text"Global")
        }
    }
}

 

 

 

 

 

I hope this is helpful for some of you.

 

Cheers

Dan

  • Like 3
Link to post
Share on other sites

thanks Dan, i had someone using a program i made, and i couldn't believe the amount of times they kept clicking the button. anyway it broke, and this is very handy cheers mate.

Link to post
Share on other sites
  • 4 weeks later...

Hey Dan, 

I'll be using your code now in a lot of my bots. LOL 
I like the UI Stop/start way better then the bot's own Start/stop. 

I'm new, and might need help. Got a way to Multi thread it by chance? 

I just injected the threading like so, and it worked.. lol 

ui drop down("Threads", "1,2,3,4,5,6,7,8,9,10", #Threads)
ui stat monitor("Status", #status)
on load("Bot Loaded") {
    set(#running, "false", "Global")
    set(#stop, "true", "Global")
}
ui button("Start") {
    if($comparison(#running, "=", "true")) {
        then {
            alert("Task is already running. Please wait.")
        }
        else {
            set(#running, "true", "Global")
            set(#stop, "false", "Global")
            statusupdate("Starting Bot....")
            loop while($comparison(#stop, "=", "false")) {
                set(#threads to run, #Threads, "Global")
                set(#used threads, 0, "Global")
                loop(#Threads) {
                    loop while($comparison(#used threads, ">=", #threads to run)) {
                        wait(1)
                    }
                    comment("Increment Opens a new thread")
                    thread {
                        in new browser {
                            navigate("google.com", "Wait")
                            decrement(#used threads)
                        }
                    }
                }
                set(#waitcounter, 5, "Global")
                loop(#waitcounter) {
                    statusupdate("Waiting:  {#waitcounter}")
                    wait(1)
                    decrement(#waitcounter)
                }
            }
            set(#status, "Bot stopped.", "Global")
            set(#running, "false", "Global")
        }
    }
}
ui button("Stop") {
    if($comparison(#stop, "!=", "true")) {
        then {
            set(#stop, "true", "Global")
            set(#status, "Stopping Bot....", "Global")
        }
    }
}
define statusupdate(#text) {
    if($comparison(#stop, "!=", "true")) {
        then {
            set(#status, #text, "Global")
        }
    }
}

Anyway to connect the "Start" to a UI HTML panel? (SSUB V6.0 by chance) Having trouble figuring that part out.


Thanks, 
Jake


EDITED: I keep answering my own questions after I post them LOL. Thought I would share to anyone who needs this information, The threading works perfect, if you have another way please let me know. 
I just took the code from Button Start and Button Stop and put them in a define, then made SSUB V6 define start and stop to the define's I made. :) Now works like that. Just hoping nothing breaks as I keep moving forward. 


EDIT: The first code was incorrect for threading with the button. 
It would keep looping out and adding a thread every loop. 
I had to take out the Loop While, due to it would be 60+ seconds before the threads opened. 
The correct code is down below, can add in monitor's threw out your code. "Making account, captcha, etc" 

 

ui drop down("Threads", "1,2,3,4,5,6,7,8,9,10", #Threads)
ui stat monitor("Status", #status)
on load("Bot Loaded") {
    set(#running, "false", "Global")
    set(#stop, "true", "Global")
}
ui button("Start") {
    if($comparison(#running, "=", "true")) {
        then {
            alert("Task is already running. Please wait.")
        }
        else {
            set(#running, "true", "Global")
            set(#stop, "false", "Global")
            set(#threads to run, #Threads, "Global")
            set(#used threads, 0, "Global")
            statusupdate("Starting Bot....")
            loop(#Threads) {
                loop while($comparison(#used threads, ">=", #threads to run)) {
                    wait(1)
                }
                increment(#used threads)
                thread {
                    in new browser {
                        navigate("google.com", "Wait")
                        decrement(#used threads)
                    }
                }
            }
            set(#status, "Bot stopped.", "Global")
            set(#running, "false", "Global")
        }
    }
}
ui button("Stop") {
    if($comparison(#stop, "!=", "true")) {
        then {
            set(#stop, "true", "Global")
            set(#status, "Stopping Bot....", "Global")
        }
    }
}
define statusupdate(#text) {
    if($comparison(#stop, "!=", "true")) {
        then {
            set(#status, #text, "Global")
        }
    }
}
Edited by HaHaItsJake
Link to post
Share on other sites
  • 6 months later...
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...