nyolc8 Posted January 16, 2015 Share Posted January 16, 2015 Hello all, I'm asking if asynchronous tasks are possible in GTA4 scripthook? Is it supported? Link to comment Share on other sites More sharing options...
nyolc8 Posted January 18, 2015 Author Share Posted January 18, 2015 Is there a trick or way to run multiple tasks somehow? The methods I tried just made my game hang when the asynchronous method got started (screen frozen into a static image, sound stopped). Link to comment Share on other sites More sharing options...
InfamousSabre Posted January 19, 2015 Share Posted January 19, 2015 Certain things you can't do asynchronously as they (as you've noticed) make the game hang. I'm using ScriptHook .Net and I try to avoid anything involving GTA.Script, GTA.Game, GTA.World, or GTA.Native Classes. Usually fairly easy to work around, however. Haven't had any issues using anything in GTA.Ped or GTA.Vehicle classes, but GTA.Script.Exists() and GTA.Game.Exists() make the game hang, of course, so you'll have to check for existence some other way. Link to comment Share on other sites More sharing options...
byteMe420 Posted January 23, 2015 Share Posted January 23, 2015 whatever you need to do with GTA you do in your script, anything else can run in another thread which can set flags that tell your script what to do... you can muti thread just have to use threads to tell your script what to do... as long as you dont use waits in your script then it can respond accordingly in a tick InfamousSabre 1 Link to comment Share on other sites More sharing options...
nyolc8 Posted January 29, 2015 Author Share Posted January 29, 2015 I tried making multithread in c# (VS 2013 community edition) but it just doesn't work. Can you show an example for this? Because I read multiple solutions and commands to achive this but none of them worked for me. Link to comment Share on other sites More sharing options...
Jitnaught Posted January 29, 2015 Share Posted January 29, 2015 I tried making multithread in c# (VS 2013 community edition) but it just doesn't work. Can you show an example for this? Because I read multiple solutions and commands to achive this but none of them worked for me. System.Threading.Thread thread = new System.Threading.Thread(() => { }); thread.IsBackground = true; thread.Start(); ? Link to comment Share on other sites More sharing options...
nyolc8 Posted January 29, 2015 Author Share Posted January 29, 2015 Thanks, I didn't tried this, I'll look into it Link to comment Share on other sites More sharing options...
nyolc8 Posted January 31, 2015 Author Share Posted January 31, 2015 (edited) System.Threading.Thread thread = new System.Threading.Thread(() => { }); thread.IsBackground = true; thread.Start(); So I tried this, and got an "error in script" message, then the script stopped for a few seconds (I think while the wait() command paused it), then the game got hang. Can I use "Wait(XX);" in the new thread? (that would be the whole point for me in this multithreading question) edit: yes, the game hangs after the wait command, and when it should continue. edit2: used "Thread.Sleep();" instead of "Wait();" and looks like it works nicely. Edited January 31, 2015 by nyolc8 Link to comment Share on other sites More sharing options...
Jitnaught Posted January 31, 2015 Share Posted January 31, 2015 Yeah you have to use Thread.Sleep Link to comment Share on other sites More sharing options...
formel117 Posted February 21, 2015 Share Posted February 21, 2015 You can also use Tasks, https://msdn.microsoft.com/en-us/library/system.threading.tasks.task%28v=vs.110%29.aspx. I've used them multiple times, mostly for HTTP GET/POST in the backgrounds, but they also work with the ScriptHook.NET functions. Link to comment 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