Jump to content
Sign in to follow this  
michel87

Realistic insurgents. pick up weapon and fire..

Recommended Posts

Glad to help :)

For the record there are still a few flaws in the ones above. The groups don't necessarily get deleted so you will quickly run out and have problems (I think, it seems theoretically possible for that to happen but I haven't verified it). Also I was having problems with using waypointPosition because of the reassigned groups not necessarily having the same wppos 0 as their original group. I'm not sure which of these things were causing issues, but in a larger scale test I was having a lot of trouble getting people to reliably rebel even with a 100% chance (a few would just stand around). I think that pathing issues can be a culprit with some groups with faraway/difficult to reach caches. In any case both of those bugs are gone now, and I added a crude road bomb after a few seconds (position may or may not end up making sense or damaging anything but it can be pretty effective most of the time). With _grpsBomb set to 3 as below, when the ambush goes off if three or more civilian groups "rebel", then the bomb will attempt to be created. If fewer than 3 rebel, no bomb will be computed. Thus you can set _grpsBomb to whatever you like to disable or change the operation of the bomb.

Here is also an init.sqf which simplifies setting it up.

init.sqf:

_civsAvail = [civ, civ_1, civ_2, civ_3, civ_4, civ_5, civ_6, civ_7, civ_8, civ_9, civ_10, civ_11];
{{_x setSkill (0.25 + (random 0.5));} forEach units group _x;} forEach _civsAvail;
{[_x, 5] execVM "wrangle.sqf";} forEach _civsAvail;

ambush.sqf:

_civsAvail = [civ, civ_1, civ_2, civ_3, civ_4, civ_5, civ_6, civ_7, civ_8, civ_9, civ_10, civ_11];
_wpcsAvail = [wpc, wpc_1, wpc_2, wpc_3];
_chanceAmbush = 0.4;
_grpsBomb = 3;
_man = _this select 0;
_victim = vehicle _man;
_parmArr = [];
_countWpcs = count _wpcsAvail;
_xWpc = nil;

{if (_x getVariable "hasRebelled") then
   {_civsAvail = _civsAvail - [_x];}} forEach _civsAvail;
{if ((random 1) < _chanceAmbush) then {
   _xWpc = _wpcsAvail select (floor (random _countWpcs));
   _parmArr = _parmArr + [[_x, _xWpc]];};} forEach _civsAvail;
{_x execVM "rebel.sqf";} forEach _parmArr;
if ((count _parmArr) >= _grpsBomb) then {
  sleep (1 + (random 4));
  _velX = abs (velocity _victim select 0);
  _velY = abs (velocity _victim select 1);
  _vel = sqrt ((_velX * _velX) + (_velY * _velY));
  _timerBomb = 1.5 + (random 3.5);
  _radBomb = _vel * 3;
  _rBomb = (0.9 + (random 0.2)) * _radBomb;
  _theta = 90 - (getDir _victim);
  _compX = (_rBomb * (cos _theta));
  _compY = (_rBomb * (sin _theta));
  _bombPos = [(getPos _victim select 0) + _compX, (getPos _victim select 1) + _compY, getPos _victim select 2];
  _bombAltPosList = nil;
  "F_40mm_White" createVehicle [_bombPos select 0, _bombPos select 1, (_bombPos select 2) + 0.0125];
  if ((count (_bombPos nearRoads 20)) == 0) then {
     _bombAltPosList = _bombPos nearRoads 30;
     if ((count _bombAltPosList) != 0) then {
           _bombPos = position (_bombAltPosList select 0);} else 
    {_bombPos = [0,0,0];};};
  sleep (1.25 + (random 2.75));
  _bombIntvls = [0.125];
  {sleep _x; "M_Stinger_AA" createVehicle _bombPos;} forEach _bombIntvls;};

rebel.sqf:

_grpLdr = _this select 0;
_wpnCache = _this select 1;
_grpThis = group _grpLdr;
_mgznMen = """10x_303""";
_wpnMen = """LeeEnfield""";
_mgznLdr = """75Rnd_545x39_RPK""";
_wpnLdr = """RPK_74""";

{_x allowFleeing 0;} forEach units _grpThis;
sleep (2 + (random 6));
_grpLdr setVariable ["hasRebelled", true];
_grpNew = createGroup (side _grpLdr);
_wptRegroup = _grpNew addWaypoint [position _grpLdr, 0];
_wptArm = _grpNew addWaypoint [position _wpnCache, 0];
_wptDummy = _grpNew addWaypoint [position _wpnCache, 5];
_wptRegroup setWaypointType "MOVE";
_wptRegroup setWaypointBehaviour "SAFE";
_wptRegroup setWaypointSpeed "NORMAL";
_wptArm setWaypointCompletionRadius 2.5;
_wptArm setWaypointType "MOVE";
_wptArm setWaypointBehaviour "AWARE";
_wptArm setWaypointStatements ["true", format 
 ["_grpOlde = group this; _grpOPFOR = createGroup east; 
   _wptSecure = _grpOPFOR addWaypoint [position this, 2.5];
   _wptSecure setWaypointCombatMode ""RED"";
   _wptSecure setWaypointBehaviour ""COMBAT"";
   _wptSecure setWaypointType ""SAD"";
   _grpOPFOR setCurrentWaypoint _wptSecure;	
   (units group this) joinSilent _grpOPFOR;
   {_dude = _x; {_dude addMagazine %1;} forEach [1,2,3,4];
   _x addWeapon %2;} forEach ((units _grpOPFOR) - [leader _grpOPFOR]);
   {(leader _grpOPFOR) addMagazine %3;} forEach [1,2,3,4];
   (leader _grpOPFOR) addWeapon %4;
   deleteGroup _grpOlde;", _mgznMen, _wpnMen, _mgznLdr, _wpnLdr]];
_wptDummy setWaypointType "SAD";
_wptDummy setWaypointCombatMode "RED";
{[_x] join _grpNew} forEach units (group _grpLdr);
_grpNew setCurrentWaypoint _wptRegroup;
deleteGroup _grpThis;

wrangle.sqf:

_man = _this select 0;
_distMax = _this select 1;
_distRet = _distMax * 0.85;
_posStart = getPos _man;
_man setVariable ["hasRebelled", false];

while {!(_man getVariable "hasRebelled")} do {
  _compX = abs ((position _man select 0) - (_posStart select 0));
  _compY = abs ((position _man select 1) - (_posStart select 1));
  _distCurr = (sqrt ((_compX * _compX) + (_compY * _compY)));
  if (_distCurr >= _distMax) then {
     _grpOld = group _man;
     _grpNew = createGroup (side _man);
     _wptReturn = _grpNew addWaypoint [_posStart, 0];
     _wptDismiss = _grpNew addWaypoint [waypointPosition _wptReturn, 0];
     _wptReturn setWaypointType "MOVE";
     _wptReturn setWaypointSpeed "LIMITED";
     _wptDismiss setWaypointType "DISMISS";
     _wptDismiss setWaypointSpeed "NORMAL";
     _wptReturn setWaypointCompletionRadius _distRet;
     _wptDismiss setWaypointCompletionRadius _distRet;
     _grpNew setCurrentWaypoint _wptReturn;
     {[_x] join _grpNew} forEach units (group _man);
     deleteGroup _grpOld;
  };
  sleep (4 + (random 2));
};

So now all you have to do is create a trigger to

nul = [personInVehicle/vehicleName] execVM "ambush.sqf";

And this is assuming 12 groups of civilians numbered civ, civ_1, . . ., civ_11, and 4 caches, wpc, wpc_1, wpc_2, and wpc_3. Change the arrays in ambush.sqf and init.sqf if you want that to be different. The vehicleName (or person in the vehicle) is the one that will get blown up.

Edited by dwringer
Tweaked bomb position finding algorithm so if no suitable position is found it puts the bomb at [0,0,0] (lazy, i know)

Share this post


Link to post
Share on other sites

I actually made a mission without the whole run to cache thing, just pull out weapon and fire, but also getting some sitting still, even when running Zeus AI and getting them on UPSMON (using the "spawned" parameter too, since they were both spawned and weren't on east side from the start of the mission). Oh well, I think they'll be annoying enough even if some of them stand still for the whole mission, but it would be nice if there was a solution for that.

I doubt it has something to do with the wp0, since afaik UPSMON removes all waypoints.

Share this post


Link to post
Share on other sites

Hrm, I guess sometimes civilians are just stupid, haha. One thing I was having problems with at first was that as soon as some civilians would arm themselves and become opfor, those that had not yet switched would become afraid of them and refuse to do anything else. Make sure civs are friendly to opfor, or everyone. I think they still have a tendency to go brain dead, though, for sure.

The mission I've been playing around with now does seem to have all of them following the script MOST of the time. I hesitate to say almost all the time, because the times in the past I've been trying to debug this they have been extremely frustrating to understand. I cannot tell how to reproduce the anomaly very well, and every time I find a good way, and fix it, I just find them do something else stupid and unpredictable. Lol.

Share this post


Link to post
Share on other sites

Well I think the question about suddenly giving them a weapon has been answered. Regarding the RPG, I wouldn't know how to do it with an RPG but you could always use JTD's Mine and IED pack, thats what I use to simulate that sort of stuff in missions, works a treat.

---------- Post added at 05:50 PM ---------- Previous post was at 05:47 PM ----------

Glad to help :)

For the record there are still a few flaws in the ones above. The groups don't necessarily get deleted so you will quickly run out and have problems (I think, it seems theoretically possible for that to happen but I haven't verified it). Also I was having problems with using waypointPosition because of the reassigned groups not necessarily having the same wppos 0 as their original group. I'm not sure which of these things were causing issues, but in a larger scale test I was having a lot of trouble getting people to reliably rebel even with a 100% chance (a few would just stand around). I think that pathing issues can be a culprit with some groups with faraway/difficult to reach caches. In any case both of those bugs are gone now, and I added a crude road bomb after a few seconds (position may or may not end up making sense or damaging anything but it can be pretty effective most of the time). With _grpsBomb set to 3 as below, when the ambush goes off if three or more civilian groups "rebel", then the bomb will attempt to be created. If fewer than 3 rebel, no bomb will be computed. Thus you can set _grpsBomb to whatever you like to disable or change the operation of the bomb.

Here is also an init.sqf which simplifies setting it up.

init.sqf:

_civsAvail = [civ, civ_1, civ_2, civ_3, civ_4, civ_5, civ_6, civ_7, civ_8, civ_9, civ_10, civ_11];
{{_x setSkill (0.25 + (random 0.5));} forEach units group _x;} forEach _civsAvail;
{[_x, 5] execVM "wrangle.sqf";} forEach _civsAvail;

ambush.sqf:

_civsAvail = [civ, civ_1, civ_2, civ_3, civ_4, civ_5, civ_6, civ_7, civ_8, civ_9, civ_10, civ_11];
_wpcsAvail = [wpc, wpc_1, wpc_2, wpc_3];
_chanceAmbush = 0.4;
_grpsBomb = 3;
_man = _this select 0;
_victim = vehicle _man;
_parmArr = [];
_countWpcs = count _wpcsAvail;
_xWpc = nil;

{if (_x getVariable "hasRebelled") then
   {_civsAvail = _civsAvail - [_x];}} forEach _civsAvail;
{if ((random 1) < _chanceAmbush) then {
   _xWpc = _wpcsAvail select (floor (random _countWpcs));
   _parmArr = _parmArr + [[_x, _xWpc]];};} forEach _civsAvail;
{_x execVM "rebel.sqf";} forEach _parmArr;
if ((count _parmArr) >= _grpsBomb) then {
  sleep (1 + (random 4));
  _velX = abs (velocity _victim select 0);
  _velY = abs (velocity _victim select 1);
  _vel = sqrt ((_velX * _velX) + (_velY * _velY));
  _timerBomb = 1.5 + (random 3.5);
  _radBomb = _vel * 3;
  _rBomb = (0.9 + (random 0.2)) * _radBomb;
  _theta = 90 - (getDir _victim);
  _compX = (_rBomb * (cos _theta));
  _compY = (_rBomb * (sin _theta));
  _bombPos = [(getPos _victim select 0) + _compX, (getPos _victim select 1) + _compY, getPos _victim select 2];
  _bombAltPosList = nil;
  "F_40mm_White" createVehicle [_bombPos select 0, _bombPos select 1, (_bombPos select 2) + 0.0125];
  if ((count (_bombPos nearRoads 20)) == 0) then {
     _bombAltPosList = _bombPos nearRoads 30;
     if ((count _bombAltPosList) != 0) then {
           _bombPos = position (_bombAltPosList select 0);} else 
    {_bombPos = [0,0,0];};};
  sleep (1.25 + (random 2.75));
  _bombIntvls = [0.125];
  {sleep _x; "M_Stinger_AA" createVehicle _bombPos;} forEach _bombIntvls;};

rebel.sqf:

_grpLdr = _this select 0;
_wpnCache = _this select 1;
_grpThis = group _grpLdr;
_mgznMen = """10x_303""";
_wpnMen = """LeeEnfield""";
_mgznLdr = """75Rnd_545x39_RPK""";
_wpnLdr = """RPK_74""";

{_x allowFleeing 0;} forEach units _grpThis;
sleep (2 + (random 6));
_grpLdr setVariable ["hasRebelled", true];
_grpNew = createGroup (side _grpLdr);
_wptRegroup = _grpNew addWaypoint [position _grpLdr, 0];
_wptArm = _grpNew addWaypoint [position _wpnCache, 0];
_wptDummy = _grpNew addWaypoint [position _wpnCache, 5];
_wptRegroup setWaypointType "MOVE";
_wptRegroup setWaypointBehaviour "SAFE";
_wptRegroup setWaypointSpeed "NORMAL";
_wptArm setWaypointCompletionRadius 2.5;
_wptArm setWaypointType "MOVE";
_wptArm setWaypointBehaviour "AWARE";
_wptArm setWaypointStatements ["true", format 
 ["_grpOlde = group this; _grpOPFOR = createGroup east; 
   _wptSecure = _grpOPFOR addWaypoint [position this, 2.5];
   _wptSecure setWaypointCombatMode ""RED"";
   _wptSecure setWaypointBehaviour ""COMBAT"";
   _wptSecure setWaypointType ""SAD"";
   _grpOPFOR setCurrentWaypoint _wptSecure;	
   (units group this) joinSilent _grpOPFOR;
   {_dude = _x; {_dude addMagazine %1;} forEach [1,2,3,4];
   _x addWeapon %2;} forEach ((units _grpOPFOR) - [leader _grpOPFOR]);
   {(leader _grpOPFOR) addMagazine %3;} forEach [1,2,3,4];
   (leader _grpOPFOR) addWeapon %4;
   deleteGroup _grpOlde;", _mgznMen, _wpnMen, _mgznLdr, _wpnLdr]];
_wptDummy setWaypointType "SAD";
_wptDummy setWaypointCombatMode "RED";
{[_x] join _grpNew} forEach units (group _grpLdr);
_grpNew setCurrentWaypoint _wptRegroup;
deleteGroup _grpThis;

wrangle.sqf:

_man = _this select 0;
_distMax = _this select 1;
_distRet = _distMax * 0.85;
_posStart = getPos _man;
_man setVariable ["hasRebelled", false];

while {!(_man getVariable "hasRebelled")} do {
  _compX = abs ((position _man select 0) - (_posStart select 0));
  _compY = abs ((position _man select 1) - (_posStart select 1));
  _distCurr = (sqrt ((_compX * _compX) + (_compY * _compY)));
  if (_distCurr >= _distMax) then {
     _grpOld = group _man;
     _grpNew = createGroup (side _man);
     _wptReturn = _grpNew addWaypoint [_posStart, 0];
     _wptDismiss = _grpNew addWaypoint [waypointPosition _wptReturn, 0];
     _wptReturn setWaypointType "MOVE";
     _wptReturn setWaypointSpeed "LIMITED";
     _wptDismiss setWaypointType "DISMISS";
     _wptDismiss setWaypointSpeed "NORMAL";
     _wptReturn setWaypointCompletionRadius _distRet;
     _wptDismiss setWaypointCompletionRadius _distRet;
     _grpNew setCurrentWaypoint _wptReturn;
     {[_x] join _grpNew} forEach units (group _man);
     deleteGroup _grpOld;
  };
  sleep (4 + (random 2));
};

So now all you have to do is create a trigger to

nul = [personInVehicle/vehicleName] execVM "ambush.sqf";

And this is assuming 12 groups of civilians numbered civ, civ_1, . . ., civ_11, and 4 caches, wpc, wpc_1, wpc_2, and wpc_3. Change the arrays in ambush.sqf and init.sqf if you want that to be different. The vehicleName (or person in the vehicle) is the one that will get blown up.

That is a very detailed way of doing things... My answer, JTD Mine and IED pack. :P

Share this post


Link to post
Share on other sites

Well my entire goal was to simulate the IED without manually placing an object at a specific location in the editor. Set up a somewhat variable condition for the trigger, and you will never know when or where the bomb is going to be. For the most part, the bomb will be in the road or just off the shoulder. If you charge into a corner at high speed. you could get the bomb to appear pretty far off into a field or house or something (up to 20 yards from the center of a road segment), but if its too far the script tries to find a road within an additional 10 yards and places the bomb there. IF that still fails, then the bomb won't happen, but I have only seen that once so far.

If you have lots of little triggers that each call the ambush script with a relatively low chance of actually happening, or a wide area trigger with a randomized timeout on it, you can have a very dynamic ambush situation.

EDIT: but I have not checked out fully the other scripting options available for such things. It has taken me a very long time to start to understand how to do a lot of what's possible in scripting, lol.

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  

×