Jump to content
gameboi

Gunner has to aim to a new sector

Recommended Posts

First I'll post the script, then I'll ask the question:

//Random location fire script. Place code below in the "ON ACT" field of the trigger after placing a number of named markers on the map for that specific trigger.
//nul = [Gun1,[marker1, <marker2>, <marker3...>],60] execVM "randomfire.sqf";

//In ON ACT.:
/*
markerArray = ["t1", "t2", "t3"];          
nul = [Mk1, markerArray, 6000] execVM "randomfire.sqf";
*/

private ["_gunname","_markerArray","_fortime", "_gunnername", "_targetToFireAt"];

if (!isServer) exitWith {};
_gunname = _this select 0;

//Maybe the gunner needs to come from elsewhere to man it first. So wait until it has manned the gun.
waitUntil {!isNull gunner _gunname};
_gunnername = gunner _gunname;

_markerArray = _this select 1; //where to shoot at?
_fortime = _this select 2; //how long does the gun fire?

while {_fortime > 0} do
{
    if (!alive _gunnername) exitwith {};
    
    _targetToFireAt = _markerArray call BIS_fnc_selectRandom;    
    _gunname doWatch (getmarkerpos _targetToFireAt);
    _gunname action ["useWeapon", _gunname, _gunnername, 1];
    sleep ceil(random 3); //At 0 the gunner doesn't seem to shoot. Or he shoots only once.
    _fortime = _fortime - 1;
    _gunname setvehicleammo 1;
};

Now here's the scenario:

a) team walks into a sector. Enemy gunner far away shoots at markers in that sectors. Trigger based when arriving in a sector.

B) team runs away from fire but enter a new sector. Same gunner should aim at new markers in that new sector.

c) Script is set to fire for 30 seconds with unlimited ammo.

 

Problem:

Only the first trigger for the first sector works. Trigger is set to "repeatedly". But when the 30 seconds are over, triggering the second sector which calls the same script as above, doesn't do anything. Besides that, even when the 30 seconds aren't over (because in the final release the gunner will fire indefinetly), I want the gunner to switch markers when the second trigger is triggered. How the heck do I do that? So basically:

d) Abort shooting and aim at new marker-set.

e) shoot there according to the script above.

And so forth.

 

Bascially, each time a team runs into a new sector, a new trigger is triggered to aim at that sector.

Cheers!

 

Share this post


Link to post
Share on other sites

OK, I have simplified the mission. The triggers aren't synced to anytihng now. Just a bunch of triggers calling the above script. In ON ACT it looks like this:

nearAAF = nearestObjects [Mk1, ["I_soldier_base_F"], 50] ;      
if(count nearAAF > 0 ) then {nearAAF select 0 assignAsGunner Mk1; nearAAF orderGetIn true };                          
 markerArray = ["t1", "t2", "t3"];        
nul =  [Mk1, markerArray, 600]  execVM "randomfire.sqf";

Now here's the weird thing. The gunner shoots at every marker in when triggered. So initially it shoots at t1, t2 and t3. If I trigger another area, the gunner shoots at t4 AND... the previous three triggers! It seems as if mutliple scriptinstances are running at the same time! I don't want to. The gunner at Mk1 needs to aim at the new sets of marker(s).

Share this post


Link to post
Share on other sites

Check out this video, seems to answer and supply the script you're after!

LOL, it's not. In fact, I improved that very script.

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

×