Findeh 34 Posted July 15, 2019 Share Posted July 15, 2019 I've got a plugin, that checks if something specific have happened (in a complicated way, like different teleports, continent change, gm checks and so on) The idea is, i do my quest profile, while plugin is working at background. When plugin got triggered i need to stop current quest profile and load new one, totally different, for another continent and so on. The point i've stuck at. Stop quester and load anoter profile. Basicly when i stop quester product, bot brakes (stop / pouse buttons are inactive anymore, it only can be closed after that) and quest log looks like this: 18:27:30.883 - [Quester] Started 18:27:30.886 - 111111111111111111111111111111 18:27:31.886 - 222222222222222222222222222222 18:27:31.965 - [Quester] Stopped 18:27:32.489 - [Quester] Stopped 18:27:32.489 - [Quester] Closed 18:27:32.721 - Session statistics: Elapsed time: 00h:00m:04s XP/HR: 0 - 0 min Kills: 0 (0/hr) Deaths: 0 (0/hr) Stucks: 0 (0/hr) Farms: 0 (0/hr) Loots: 0 (0/hr) Money/HR: 0 G 00 S 00 C (0 G 00 S 00 C) Code i use: if (condition) { Logging.Write("111111111111111111111111111111"); Thread.Sleep(1000); Logging.Write("222222222222222222222222222222"); Products.DisposeProduct(); Logging.Write("333333333333333333333333333333"); Thread.Sleep(1000); ArgsParser.Product = "Quester"; Thread.Sleep(1000); ArgsParser.Profile = "MyProfile.xml"; Thread.Sleep(1000); Products.LoadProducts("Quester"); } So my guess is, when i stop quester product, it also stop all plugins and, as a result, my plugin can't start quester with another profile. There also may be some problems after "33333333" message, but i don't get there yet. So the question is, how do i do "condition based quester profile change"? I don't need to change product (atleast yet) only the profile. It should be able triger with a condition and should do it multiple times per run if needed. Maybe my code is wrong? Or maybe i should do it not with a plugin but how then? This is probably the hardest one of my "stucks" with a wrobot so far, because i can't see workaround, even the bad ones, so any advics are much appreciated. Thank you in advance. Link to comment https://wrobot.eu/forums/topic/11503-stop-current-quest-profile-and-start-another-one/ Share on other sites More sharing options...
Matenia 630 Posted July 15, 2019 Share Posted July 15, 2019 Spawn a new thread. Your plugin thread gets killed when you dispose the product because it's originally spawned by wRobot. Findeh 1 Link to comment https://wrobot.eu/forums/topic/11503-stop-current-quest-profile-and-start-another-one/#findComment-54997 Share on other sites More sharing options...
Findeh 34 Posted July 15, 2019 Author Share Posted July 15, 2019 I'm sorry, but how do i do that? Plugin itself decides when to kill process and what to do next. If it also got killed, no other thread will know what to do next. Do you mean that if i do it something like: private BackgroundWorker backgroundThread; blah-blah-blah public void Start() { backgroundThread = new BackgroundWorker(); backgroundThread.DoWork += Pulse; backgroundThread.RunWorkerAsync(); } blah-blah-blah And do all the stuff inside the Pulse method, then this thread will not be killed together with the plugin thread? Link to comment https://wrobot.eu/forums/topic/11503-stop-current-quest-profile-and-start-another-one/#findComment-54998 Share on other sites More sharing options...
Matenia 630 Posted July 15, 2019 Share Posted July 15, 2019 Basically. Or you can just start a new thread like new Thread(() => { stuff here;}).Start(); Those threads won't be killed because they belong to the wRobot.exe process but aren't spawned like plugins/products inside the wRobot framework Findeh 1 Link to comment https://wrobot.eu/forums/topic/11503-stop-current-quest-profile-and-start-another-one/#findComment-55000 Share on other sites More sharing options...
Findeh 34 Posted July 15, 2019 Author Share Posted July 15, 2019 Thanks a lot. Will try it tomorrow Link to comment https://wrobot.eu/forums/topic/11503-stop-current-quest-profile-and-start-another-one/#findComment-55011 Share on other sites More sharing options...
Findeh 34 Posted July 16, 2019 Author Share Posted July 16, 2019 Edited. Nevermind, solved. Link to comment https://wrobot.eu/forums/topic/11503-stop-current-quest-profile-and-start-another-one/#findComment-55030 Share on other sites More sharing options...
Findeh 34 Posted July 17, 2019 Author Share Posted July 17, 2019 All that thing causes another problem. When i create separate thread, it kills quester thread and. as a result, my plugin thread. Then it starts the quester again. Quester starts the plugin. Plugin starts new separate thread, that is killing quester again aaaaaaand down to the endles cycle we go. So befor createon of a new thread within the plugin, i need to check isn't there already that thread running, left by a previous plugin. But i can't do it from within current plugin thread, because it's a separate thread from the thread created by a previous plugin copy ))))) Is there any way to check for a status of a separate running thread? Maybe by it's name? Like wrobot.exe/MyThread? Or maybe i can create a variable that will be stored not in my plugin but in wrobot.exe thread? Then i'll be able to set it false after the wrobot.exe start, and set it true after the first thread start. Link to comment https://wrobot.eu/forums/topic/11503-stop-current-quest-profile-and-start-another-one/#findComment-55057 Share on other sites More sharing options...
Matenia 630 Posted July 17, 2019 Share Posted July 17, 2019 If you want to store something in wRobot, use Var.SetVar("x", "value") and Var.GetVar("x"), see if that does the trick. Otherwise look into C# Mutex Findeh 1 Link to comment https://wrobot.eu/forums/topic/11503-stop-current-quest-profile-and-start-another-one/#findComment-55060 Share on other sites More sharing options...
Findeh 34 Posted July 17, 2019 Author Share Posted July 17, 2019 That's great, didn't know it exist. I don't even need a value, so Exist() will do just fine. Thank you. Link to comment https://wrobot.eu/forums/topic/11503-stop-current-quest-profile-and-start-another-one/#findComment-55061 Share on other sites More sharing options...
Marsbar 228 Posted July 18, 2019 Share Posted July 18, 2019 (edited) 13 hours ago, Findeh said: That's great, didn't know it exist. I don't even need a value, so Exist() will do just fine. Thank you. Not sure which of the suggestions you're talking about but if it's mutex remember that its PC wide and if you have multiple wrobot instances its best to name your mutex (in wdiscord i use the charname as the unique identifier) eg. if (!Mutex.TryOpenExisting(myName, out mut)) { mut = new Mutex(true, myName); _ = DiscordBot.RunBotAsync(); } edit: thinking about it i should probably change that to my plugin name + the char name in case other ppl use mutexs.. Edited July 18, 2019 by Marsbar Findeh 1 Link to comment https://wrobot.eu/forums/topic/11503-stop-current-quest-profile-and-start-another-one/#findComment-55071 Share on other sites More sharing options...
Findeh 34 Posted July 20, 2019 Author Share Posted July 20, 2019 On 7/18/2019 at 10:58 AM, Marsbar said: Not sure which of the suggestions you're talking about but if it's mutex remember that its PC wide and if you have multiple wrobot instances its best to name your mutex (in wdiscord i use the charname as the unique identifier) I was actually need only a true/false trigger that will not die with my process but will die wit a wrobot process. Inbuild Var class did the trick (atleast for now, will need to coplete the code first to be sure). But thank you anyway. Link to comment https://wrobot.eu/forums/topic/11503-stop-current-quest-profile-and-start-another-one/#findComment-55136 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