Asoter 3 Posted March 28, 2017 Share Posted March 28, 2017 Hello, I'm trying to change my Botbase(in Plugin) from Party bot to another. I found somethink like this: Products.DisposeProduct(); Products.LoadProducts("Automaton"); After this trying additional Products.ProductRestart(); etc but it dosen't work. Bot stopped or freezed? Any1 know how to do this? Link to comment https://wrobot.eu/forums/topic/5507-changing-botbase/ Share on other sites More sharing options...
reapler 154 Posted March 28, 2017 Share Posted March 28, 2017 Hello, i tried this also by a plugin but i have figured out that it's abit difficult. You need to create your own thread because if you dispose product your plugin also stop working(maybe there's another method to do it but i haven't found it yet). Here's an example how do you create your own thread: public static bool _isLaunched1; public static bool AllowAbort; Dictionary<string, Thread> threadDict = new Dictionary<string, Thread>(); public void Initialize() { MemoryBool(true); Thread th1 = new Thread(() => Thread1()); th1.Name = Convert.ToString(TableID); th1.Start(); threadDict.Add("Thread1", th1); Logging.Write("Thread started."); } public void Dispose() { if (!MemoryBool()) { Logging.Write("Abort thread."); SwitchProduct(StartedRotationName()); if (AllowAbort) { threadDict["Thread1"].Abort(); } } } public void Settings() { } public void Thread1() { Logging.Write("Initialize thread."); _isLaunched1 = true; var timer = new Timer(1500); timer.ForceReady(); while (_isLaunched1) { try { if (Conditions.ProductIsStartedNotInPause && timer.IsReady //&& !ObjectManager.Me.IsDead //optional ) { Pulse1(); timer.Reset(); } } catch { } Thread.Sleep(65); } } //may change address if not available or use System.Runtime.Caching.MemoryCache or write settings public bool MemoryBool() { if (Memory.WowMemory.Memory.ReadInt32((uint) GetWoWBase() + 0x7322CA) == 1) { return true; } return false; } public void Pulse1(); { Logging.Write("Tick"); } and the key to switch products: //Need own thread to work //=> Products.ProductStop();/Products.DisposeProduct(); aborts the main thread and method has nothing to continue public void SwitchProduct(string name) { if (Products.ProductName != name && Products.IsStarted) { Logging.Write("Switch to " + name); MemoryBool(true); Products.ProductStop(); Products.LoadProducts(name); Logging.Write("stop & load product"); Thread.Sleep(200); Products.ProductStart(); Logging.Write("product start & abort old"); MemoryBool(false); Thread.Sleep(1500); threadDict["Thread1"].Abort(); //abort of current thread } } if you need support, feel free to pm me Link to comment https://wrobot.eu/forums/topic/5507-changing-botbase/#findComment-25219 Share on other sites More sharing options...
Asoter 3 Posted March 29, 2017 Author Share Posted March 29, 2017 Thanks mate for reply! When I back to home then I test this :) Link to comment https://wrobot.eu/forums/topic/5507-changing-botbase/#findComment-25223 Share on other sites More sharing options...
reapler 154 Posted March 29, 2017 Share Posted March 29, 2017 ah forget the complicated code, i've found a better way to do it for e.g: public void Initialize() { Logging.Write("Plugin started."); Thread.Sleep(7000); SwitchProduct("Grinder"); } public void Dispose() { Logging.Write("Disposed"); } public void Settings() { } public void SwitchProduct(string name) { if (Products.ProductName != name && Products.IsStarted) { var t = Task.Run(async delegate { await Task.Delay(500); Logging.Write("Switch to " + name); Products.ProductStop(); Products.LoadProducts(name); Logging.Write("stop & load product"); Thread.Sleep(200); Products.ProductStart(); Logging.Write("product start"); Thread.Sleep(1500); }); t.Wait(); } } I think it's better ;) Edit: using System.Threading.Tasks; is also needed Link to comment https://wrobot.eu/forums/topic/5507-changing-botbase/#findComment-25237 Share on other sites More sharing options...
Asoter 3 Posted March 29, 2017 Author Share Posted March 29, 2017 Works perfectly! Thanks! Link to comment https://wrobot.eu/forums/topic/5507-changing-botbase/#findComment-25246 Share on other sites More sharing options...
Jasabi 38 Posted March 29, 2017 Share Posted March 29, 2017 9 hours ago, reapler said: ah forget the complicated code, i've found a better way to do it for e.g: public void Initialize() { Logging.Write("Plugin started."); Thread.Sleep(7000); SwitchProduct("Grinder"); } public void Dispose() { Logging.Write("Disposed"); } public void Settings() { } public void SwitchProduct(string name) { if (Products.ProductName != name && Products.IsStarted) { var t = Task.Run(async delegate { await Task.Delay(500); Logging.Write("Switch to " + name); Products.ProductStop(); Products.LoadProducts(name); Logging.Write("stop & load product"); Thread.Sleep(200); Products.ProductStart(); Logging.Write("product start"); Thread.Sleep(1500); }); t.Wait(); } } I think it's better ;) Edit: using System.Threading.Tasks; is also needed @reaperl as a novice at this, would you say its best to run most plugins as async or on other threads? Link to comment https://wrobot.eu/forums/topic/5507-changing-botbase/#findComment-25248 Share on other sites More sharing options...
reapler 154 Posted March 29, 2017 Share Posted March 29, 2017 @Jasabi For plugins there's no best. It depends on the situation. Most of the time you won't need it anyway for plugins because it's not so complex and stucks don't happen that often while running. I think also that every plugin run anyway on it's own thread. For e.g. if you use async with a method it will run independent (it doesn't block the main thread on its own processing) so other stuff can continue and the second one what you have mention is multithreading. The both are "almost" the same but with multithreading you have your seperate thread which can execute its own code. Link to comment https://wrobot.eu/forums/topic/5507-changing-botbase/#findComment-25250 Share on other sites More sharing options...
saleh 13 Posted May 19, 2022 Share Posted May 19, 2022 hello i cant` understand this code i need to switch to party after quest is finish ? Link to comment https://wrobot.eu/forums/topic/5507-changing-botbase/#findComment-65647 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now