Jump to content
Sign in to follow this  
-Snafu-

High Dispersion by Script

Recommended Posts

I was looking for a high dispersion script from way back by GeneralCoder but all the links I found were dead.

I did, however, find this post on ofpec (you need to scroll to the last post).

I have the first piece of code in my init. I have the .sqf file itself in my mission folder and I run the eventHandler in the init of the enemy group leader (how can I execute it for the whole group?). The problem is I get an error at the top of the screen each time he fires.

The init.sqs

myTAG_dispersion = preprocessFile "dispersion.sqf"

The eventHandler:

this addEventHandler ["fired",{_bul = (nearestObject [(vehicle this), _this select 4)]; [_this select 0,_bul,(velocity _bul),(speed _bul)] call myTAG_dispersion}]

The dispersion.sqf:

private ["_sht","_prj","_vel","_spd","_dispA","_dispB"];

_sht = _this select 0; 
_prj = _this select 1;
_vel = _this select 2;
_spd = _this select 3;

_dispA = (_spd*(0.03-(skill _sht)/100));
_dispB = _dispA*2;

_prj setVelocity [(_vel select 0) - _disp + random(_dispB),(_vel select 1) - _disp + random(_dispB),(_vel select 2) - _disp + random(_dispB)];

Share this post


Link to post
Share on other sites

Thank you very much for your help. Hopefully I'll get to test it out this evening.

Share this post


Link to post
Share on other sites

No errors with either eventhandler, it appears to work well, will do further testing tomorrow. Thanks again!

Share this post


Link to post
Share on other sites

I have a question

some time ago I tried to write a similar script, but when I tested it, it worked fine for the first 10-15 shots and then it stopped. from what I could tell, after 10 or so shots, the script wasn't even executing anymore. every time I reloaded the mission, it worked great again for another 10 shots and stopped again.

was it because I executed a script instead of a function from the eventHandler?

Share this post


Link to post
Share on other sites

Actually a (function) call can be scheduled as well, it just depends from which context you called it.

Eventhandler execution is not scheduled - everything executed within an eventhandler (directly or by call), will complete before moving on.

Spawn and execVM'ed code will be scheduled - and then all bets are off.

For that reason it is recommended to only spawn/execVM from eventhandlers at the latest needed moment, e.g process all time sensitive stuff in call, and then spawn once you need a longer running loop across time - e.g until the lifetime of a projectile has been reached.

The spawned code will be subject to scheduling again - and all scripts have to share scheduler resources - which can be a real problem depending on your needs.

A few workarounds exist, for instance implemented and available in CBA, we call it delayLess processing - but due to not being subjected to the scheduler means you have to be very careful what code you execute, as it can have a direct effect on FPS.

Edited by Sickboy

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×