Jump to content
greywolf907

Random tasks\objectives

Recommended Posts

Test run results\ everything works as to units spawning and moving along the waypoints but once all enemy in AO are dead the task never flips tower task works great. Also have some questions about how to add in the armor, mechanized, vehicle, and air patrols? But one thing at a time.

Share this post


Link to post
Share on other sites

You ask and you shall recieve :D:

New call line (ensures all this stuff is ran on the server instead of on the clients):

[[[_centerPos,200,5,3,2,2,1,EAST],"JSHK_patrols.sqf"],"BIS_fnc_execVM",false,false,false] call BIS_fnc_MP;

And the new code and parameters:

/* //////////////////////////////////////////////
Author: J.Shock

File: JSHK_patrols.sqf

Description: Creates randomly positioned and sized patrols throughout a defined radius of an AO
            using a marker as the center position.

Parameters: 
       1- Center position: (array) (default: empty array)
       2- Radius to spawn units: (integer) (default: 300)
       3- Number of foot patrol groups: (integer) (default: 5)
	4- Number of vehicle patrol groups: (integer) (default: 3)
	5- Number of mechanized patrol groups: (integer) (default: 2)
	6- Number of armor patrol groups: (integer) (default: 2)
	7- Number of air patrol groups: (integer) (default: 1)
       8- Side: (side) (default: EAST)

Return: Spawned units.

Example Call line: ["mrkName",200,5,3,2,2,1,EAST] execVM "JSHK_patrols.sqf";

*///////////////////////////////////////////////
private ["_configGrps","_AOmarker","_radius","_numPatrols","_units","_center"];

_AOmarker = [_this, 0, [], [[]]] call BIS_fnc_param;
_radius = [_this, 1, 300, [0]] call BIS_fnc_param;
_numFootPatrols = [_this, 2, 5, [0]] call BIS_fnc_param;
_numVehPatrols = [_this, 3, 3, [0]] call BIS_fnc_param;
_numArmorPatrols = [_this, 4, 2, [0]] call BIS_fnc_param;
_numMechPatrols = [_this, 5, 2, [0]] call BIS_fnc_param;
_numAirPatrols = [_this, 6, 1, [0]] call BIS_fnc_param;
_side = [_this, 7, EAST, [WEST]] call BIS_fnc_param;

_footUnits = ["OIA_InfSentry", "OIA_InfTeam", "OIA_InfTeam_AT", "OIA_InfTeam_AA"];
_vehUnits = ["O_MRAP_02_hmg_F","O_MRAP_02_gmg_F"];
_armorUnits = ["O_MBT_02_cannon_F"];
_mechUnits = ["O_APC_Wheeled_02_rcws_F","O_APC_Tracked_02_cannon_F"];
_airUnits = ["O_Heli_Attack_02_black_F"];

_center = createCenter _side;

_units = [];

if (_numFootPatrols > 0) then
{
for "_i" from 1 to (_numFootPatrols) step 1 do 
{
	_configGrp = _footUnits call BIS_fnc_selectRandom;
	_rndPos = [[[_AOmarker, _radius], []], ["water", "out"]] call BIS_fnc_randomPos;
	_grp = [_rndPos, _center, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> (_configGrp))] call BIS_fnc_spawnGroup;
	[_grp, (_AOmarker), (random(50)+75)] call BIS_fnc_taskPatrol;
	{_units pushBack _x} forEach units _grp;
	sleep 0.05;
};
};	

if (_numVehPatrols > 0) then
{
for "_i" from 1 to (_numVehPatrols) step 1 do 
{
	_rndVeh = _vehUnits call BIS_fnc_selectRandom;
	_rndPos = [_AOmarker,50,_radius,5,0,0.5,0,[],[]] call BIS_fnc_findSafePos;
	_veh = [_rndPos,random(359),_rndVeh,_center] call BIS_fnc_spawnVehicle;
	[(_veh select 2),(_AOmarker),(random(50)+100)] call BIS_fnc_taskPatrol;
	{_units pushBack _x} forEach ((_veh select 1) + (_veh select 0));
	sleep 0.05;
};
};

if (_numArmorPatrols > 0) then
{
for "_i" from 1 to (_numArmorPatrols) step 1 do 
{
	_rndVeh = _armorUnits call BIS_fnc_selectRandom;
	_rndPos = [_AOmarker,50,_radius,5,0,0.5,0,[],[]] call BIS_fnc_findSafePos;
	_veh = [_rndPos,random(359),_rndVeh,_center] call BIS_fnc_spawnVehicle;
	[(_veh select 2),(_AOmarker),(random(50)+100)] call BIS_fnc_taskPatrol;
	{_units pushBack _x} forEach ((_veh select 1) + (_veh select 0));
	sleep 0.05;
};
};

if (_numMechPatrols > 0) then
{
for "_i" from 1 to (_numMechPatrols) step 1 do 
{
	_rndVeh = _mechUnits call BIS_fnc_selectRandom;
	_rndPos = [_AOmarker,50,_radius,5,0,0.5,0,[],[]] call BIS_fnc_findSafePos;
	_veh = [_rndPos,random(359),_rndVeh,_center] call BIS_fnc_spawnVehicle;
	[(_veh select 2),(_AOmarker),(random(50)+100)] call BIS_fnc_taskPatrol;
	{_units pushBack _x} forEach ((_veh select 1) + (_veh select 0));
	sleep 0.05;
};
};

if (_numAirPatrols > 0) then
{
for "_i" from 1 to (_numAirPatrols) step 1 do 
{
	_rndVeh = _airUnits call BIS_fnc_selectRandom;
	_rndPos = [_AOmarker,50,_radius,5,0,0.5,0,[],[]] call BIS_fnc_findSafePos;
	_veh = createVehicle [_rndVeh,_rndPos,[],0,"FLY"];
	createVehicleCrew _veh;
	[(group _veh),(_AOmarker),(random(50)+100)] call BIS_fnc_taskPatrol;
	{_units pushBack _x} forEach (crew _veh pushBack _veh);
	sleep 0.05;
};
};

_units;  

Edited by JShock

Share this post


Link to post
Share on other sites

looks good JShock, may be you could put your building garrison and defend scripts too for randomness, say 40% units do that..... :)

Hey, and you do have skills....script errors just happen.

I guess you could add another "footDefend" code.... well just using your work anyways.... and with your garrison just add another such as...

if (_numFootPatrols > 0) then

{

for "_i" from 1 to (_numFootDefend) step 1 do

{

_configGrp = _footUnits call BIS_fnc_selectRandom;

_rndPos = [[[_AOmarker, _radius], []], ["water", "out"]] call BIS_fnc_randomPos;

_grp = [_rndPos, _center, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> (_configGrp))] call BIS_fnc_spawnGroup;

[_grp, (_AOmarker), (random(50)+75)] call BIS_fnc_taskDefend

{_units pushBack _x} forEach units _grp;

sleep 0.05;

};

};

Edited by JAndrews1

Share this post


Link to post
Share on other sites
... and with your garrison just add another such as...

No, if you include the necessary files for SBGF, all you would do in this script (somewhere) is the function spawn line:

_garrisonedUnits = [_centerPos,_side,_radius,0.4,["O_Soldier_F","O_Soldier_AR_F"],-1] spawn SBGF_fnc_garrison; 
{_units pushBack _x} forEach _garrisonedUnits;

And I've never had luck with BIS_fnc_taskDefend, last time I remember using it, the units spawned, and did nothing....but that was a while back so....well, re-reading the wiki on it, it just doesn't give the effect I'm looking for when I think "defend".

Edited by JShock

Share this post


Link to post
Share on other sites
No, if you include the necessary files for SBGF, all you would do in this script (somewhere) is the function spawn line:

_garrisonedUnits = [_centerPos,_side,_radius,0.4,["O_Soldier_F","O_Soldier_AR_F"],-1] spawn SBGF_fnc_garrison; 
{_units pushBack _x} forEach _garrisonedUnits;

And I've never had luck with BIS_fnc_taskDefend, last time I remember using it, the units spawned, and did nothing....but that was a while back so....well, re-reading the wiki on it, it just doesn't give the effect I'm looking for when I think "defend".

always something with BIS fnc... well regarding the taskDefend anyways (may be they do something once they get shot) don't know, but kinda got the garrison bit.... was just throwing it out there....

So would you consider placing that in a separate line or include it with everything else? I would probably do the group command vs units BTW. I will go back and look at your garrison stuff again, am at work, dodging back and forth.

Bare with me for below but for example:

_groupGarrison = ["OIA_InfSentry", "OIA_InfTeam", "OIA_InfTeam_AT", "OIA_InfTeam_AA"];

if (_numgroupGarrison > 0) then 
{ 
   for "_i" from 1 to (_numgroupGarrison) step 1 do  
{
_configGrp = _groupGarrison call BIS_fnc_selectRandom;
_rndPos = [[[_AOmarker, _radius], []], ["water", "out"]] call BIS_fnc_randomPos;
_garrisonedUnits = [this,"mrkName",200] spawn SBGF_fnc_groupGarrison;   <------Not sure if 0= would still be used or _garrisonedunits =
{_units pushBack _x} forEach _groupGarrison;
sleep 0.05;
};
};

Fyi, https://community.bistudio.com/wiki/BIS_fnc_taskDefend

Group will man nearby static defenses within a 100 metre radius of the defense position and guard the position. Some units will man weapons, others will patrol and the remainder will sit on the ground.

I have seen them patrol and sit with this....so may be its working.... I can test...

to be honest JShock this could turn in to something really nice and easy and be to your credit. If there is a way to define the garrisoned units/groups with the other defined units and add taskdefend it would be used by many that want more randomness and more ease to use.

And be used for several different AO's as needed like

[[[_centerPos,200,5,3,2,2,1,EAST],"JSHK_patrols.sqf"],"BIS_fnc_execVM",false,false,false] call BIS_fnc_MP;

[[[_centerPos,200,5,3,2,2,1,EAST],"JSHK_patrols1.sqf"],"BIS_fnc_execVM",false,false,false] call BIS_fnc_MP;

[[[_centerPos,200,5,3,2,2,1,EAST],"JSHK_patrols2.sqf"],"BIS_fnc_execVM",false,false,false] call BIS_fnc_MP;

AND.... would call BIS_fnc_MP; work in trigger? or just use...

["mrkName",200,5,3,2,2,1,EAST] execVM "JSHK_patrols.sqf";

Edited by JAndrews1

Share this post


Link to post
Share on other sites

I don't see the need for all the different call lines for seperate AO's?

And yes you can use the whole BIS_fnc_MP line in a trigger's onAct if you wanted to.

Share this post


Link to post
Share on other sites

Awesome man thanks going to give this a test run right now. Since we didn't change anything in the objectiveInit.sqf the AO task will still not be completed once all enemy are dead still right?

Share this post


Link to post
Share on other sites

Correct, I will get a working version of that out later today, a little busy atm (on my phone). I was hoping that I could get the scripted trigger working properly, but now it's just going to be a while loop (like it should have been in the first place :p).

Edited by JShock

Share this post


Link to post
Share on other sites

No worries man I really appreciate all you foot work. tasting now error on line 66 in the patrol script so far.

Share this post


Link to post
Share on other sites
No worries man I really appreciate all you foot work. tasting now error on line 66 in the patrol script so far.

I think I may know what it is, will look at it when I get back, but so you can further test all the stuff just comment out all the lines that look similar to the following:

{_units pushBack _x} forEach blah...

Share this post


Link to post
Share on other sites

LOL tasting taste great woops ha ha. Testing now K will do.

---------- Post added at 01:15 PM ---------- Previous post was at 12:44 PM ----------

K so tested just throwing up a lan game and on tophes dedicated tool strange all the tanks and vehicles will start off on the patrols then they all get stuck still trying to drive but cant move some were stuck in the ground and some not but they all stop moving.

Share this post


Link to post
Share on other sites
I don't see the need for all the different call lines for seperate AO's?

And yes you can use the whole BIS_fnc_MP line in a trigger's onAct if you wanted to.

The thinking behind the different call lines was to have different defined groups/#'s to have in AO's that's all, thinking also they could be called from different triggers in game to have spawned at a different location or time.

In this garrision code would I use 0 = or _garrisonunits = for this group, in your garrison script for groups you have 0 = blah, blah, blah, with individual units you have something different.

if (_numgroupGarrison > 0) then 
{ 
   for "_i" from 1 to (_numgroupGarrison) step 1 do  
{
_configGrp = _groupGarrison call BIS_fnc_selectRandom;
_rndPos = [[[_AOmarker, _radius], []], ["water", "out"]] call BIS_fnc_randomPos;
_garrisonedUnits = [this,"mrkName",200] spawn SBGF_fnc_groupGarrison;  <------Not sure if 0= would still be used or _garrisonedunits =
{_units pushBack _x} forEach _groupGarrison;
sleep 0.05;
};
};

Share this post


Link to post
Share on other sites
In this garrision code would I use 0 = or _garrisonunits = for this group, in your garrison script for groups you have 0 = blah, blah, blah, with individual units you have something different.

With the SBGF_fnc_groupGarrison the only thing returned is if the function has been completed, it's not the same as the SBGF_fnc_garrison, which returns all of the spawned units, so in light of that you would just use "0= [] spawn SBGF_fnc_groupGarrison;".

---------- Post added at 17:13 ---------- Previous post was at 17:08 ----------

K so tested just throwing up a lan game and on tophes dedicated tool strange all the tanks and vehicles will start off on the patrols then they all get stuck still trying to drive but cant move some were stuck in the ground and some not but they all stop moving.

Hmmm, not sure if that's an issue I can fix or if it's a problem with BIS_fnc_findSafePos, or if it's just AI being stupid, idk :p.

Share this post


Link to post
Share on other sites

Hhhmm well I hope its a fixable problem. If not once we can get the AO task to complete and flip the next AO objective I can most likely combine your patrol script and DAC to create the same result I would just have your patrol script handle the infantry and DAC handle all the rest of the vehicles, I would rather just use your script for everything much cleaner hope you can figure it out thanks.

Share this post


Link to post
Share on other sites

Test update\ So I threw my test mission on our server we rent and tried it the vehicles move around like they should but the chopper just sits in one spot until you fire at it or are spotted by enemy so maybe the script acts differently when on a personal multiplayer or with Tophe's dedi tool not sure need to test a bit more. Can you give me a run down off what the different numbers represent in the group lines within the patrol script as in

_AOmarker = [_this, 0, [], [[]]] call BIS_fnc_param;

_radius = [_this, 1, 300, [0]] call BIS_fnc_param;

_numFootPatrols = [_this, 2, 5, [0]] call BIS_fnc_param;

_numVehPatrols = [_this, 3, 3, [0]] call BIS_fnc_param;

_numArmorPatrols = [_this, 4, 2, [0]] call BIS_fnc_param;

_numMechPatrols = [_this, 5, 2, [0]] call BIS_fnc_param;

_numAirPatrols = [_this, 6, 1, [0]] call BIS_fnc_param;

_side = [_this, 7, EAST, [WEST]] call BIS_fnc_param;

Share this post


Link to post
Share on other sites

Hhhm k what I was after is exactly what those parameter numbers are calling from the patrol script to adjust certain numbers of waypoints, area to patrol etc...

Share this post


Link to post
Share on other sites

I'm kinda confused on what your asking, at the top of the script (all the commented out stuff) is a short description of what each parameter entails in the body of the script:

1- Center position: (array) (default: empty array)

2- Radius to spawn units: (integer) (default: 300)

3- Number of foot patrol groups: (integer) (default: 5)

4- Number of vehicle patrol groups: (integer) (default: 3)

5- Number of mechanized patrol groups: (integer) (default: 2)

6- Number of armor patrol groups: (integer) (default: 2)

7- Number of air patrol groups: (integer) (default: 1)

8- Side: (side) (default: EAST)

So your first parameter is your center position, the second is your radius away from that position you want all this stuff to be spawned at (your AO size basically), and then all the _numBlahPatrols are how many groups of each type (foot soldiers, tanks, APCs, helicopters, etc.) you want to spawn in the AO, and side is just the side you want these units to be apart of when spawned.

Share this post


Link to post
Share on other sites

Lol sorry man didn't read that since the edited versions you gave me got it thanks. On a side note though just retested in editor and then on our server with second player and myself everything is working fine except for a random flipped over vehicle that spawns on a rock or whatever . Not sure why they got stuck yesterday may have been on my end.

Share this post


Link to post
Share on other sites

From this example from page #3, could I/you reduce the amount of code by doing something like this? I basically removed all code to "spawn enemy" and replaced with JShockpatrol.sqf.

if (!isServer) exitWith {}; // Server only

// set false the side1 so side finder will not execute this mission again
side1 = false;

sleep 200;

// find center of AO...looking for gamelogic location which created before in editor
_sidepos = [city1, city2, city3, city4, city5, city6, city7, city8, city9, city10] call BIS_fnc_selectRandom;

// add marker on AO/target
_marker = createMarker ["side_area", _sidepos];
_marker setMarkerType "hd_destroy";
_marker setMarkerColor "ColorRed";
_marker setMarkerText " Destroy jet";
_marker setMarkerSize [1,1];

// spawn target
jet = createVehicle ["vehicle_name", _sidepos, [], 0, "CAN_COLLIDE"]; 
jet lock true;
jet setdir random(360);

// Add task
//Task ID-Task name-Task description and some other options
["Task1","Destroy jet","Seek and destroy Jet",true,["Destroy jet",getmarkerpos "side_area"]] call SHK_Taskmaster_add ;

// spawn enemy

[[[_sidepos,300,5,5,5,5,3,2,2,1,EAST],"JSHK_patrols.sqf"],"BIS_fnc_execVM",false,false,false] call BIS_fnc_MP;  <----- my modified version :), needs some fixing BTW.

// WAIT UNTIL objective destroy
   waitUntil { (!alive jet) };

// task complete hint
["Task1","succeeded"] call SHK_Taskmaster_upd;

// delete AO marker and target
deleteMarker "side_area";
sleep 10;
deletevehicle jet;

// remove mans/vehicles/air/static "optional"
sleep 30;
{if (!(isplayer _x)) then {deleteVehicle _x;};} foreach nearestobjects [_sidepos,[
   "air","StaticWeapon","Landvehicle"
   ],2000]; 
sleep 10;
{if (!(isplayer _x)) then {deleteVehicle _x;};} foreach nearestobjects [_sidepos,[
   "man"
   ],2000]; 

sleep 5;

// go for next side mission
if (isserver) then { null=[]execVM "side_finder.sqf"; };

if(true)exitWith{};

Edited by JAndrews1

Share this post


Link to post
Share on other sites
Did you try this out how did it work?

This should work like this. still testing. spawns vehicles, now debugging objectives and trying to get JSHK.patrols to kick in.

if (!isServer) exitWith {}; // Server only

// set false the side1 so side finder will not execute this mission again
side1 = false;

sleep 200;

// find center of AO...looking for gamelogic location which created before in editor
_sidepos = [city1, city2, city3, city4, city5, city6, city7, city8, city9, city10] call BIS_fnc_selectRandom;

// add marker on AO/target
_marker = createMarker ["side_area", _sidepos];
_marker setMarkerType "hd_destroy";
_marker setMarkerColor "ColorRed";
_marker setMarkerText " Destroy jet";
_marker setMarkerSize [1,1];

// spawn target
jet = createVehicle ["vehicle_name", _sidepos, [], 0, "CAN_COLLIDE"]; 
jet lock true;
jet setdir random(360);

// Add task
//Task ID-Task name-Task description and some other options
["Task1","Destroy jet","Seek and destroy Jet",true,["Destroy jet",getmarkerpos "side_area"]] call SHK_Taskmaster_add ;

// spawn enemy

[_sidepos,300,5,5,5,5,3,2,2,1,EAST],"JSHK_patrols.sqf";  <----- should work this way. still testing. spawns vehicles, now debugging objectives and trying to get JSHK.patrols to kick in.

// WAIT UNTIL objective destroy
   waitUntil { (!alive jet) };

// task complete hint
["Task1","succeeded"] call SHK_Taskmaster_upd;

// delete AO marker and target
deleteMarker "side_area";
sleep 10;
deletevehicle jet;

// remove mans/vehicles/air/static "optional"
sleep 30;
{if (!(isplayer _x)) then {deleteVehicle _x;};} foreach nearestobjects [_sidepos,[
   "air","StaticWeapon","Landvehicle"
   ],2000]; 
sleep 10;
{if (!(isplayer _x)) then {deleteVehicle _x;};} foreach nearestobjects [_sidepos,[
   "man"
   ],2000]; 

sleep 5;

// go for next side mission
if (isserver) then { null=[]execVM "side_finder.sqf"; };

if(true)exitWith{};

Share this post


Link to post
Share on other sites

Hey JShock could you verify that this code will call your scripts. As it stands, the side mission spawns but this script does not.

[_sidepos,300,5,5,5,5,3,2,2,1,EAST],"JSHK_patrols.sqf"; <---- vs the default

Share this post


Link to post
Share on other sites

It will not, you need to execVM it:

[_sidepos,300,5,5,5,5,3,2,2,1,EAST] execVM "JSHK_patrols.sqf";

Share this post


Link to post
Share on other sites
It will not, you need to execVM it:

[_sidepos,300,5,5,5,5,3,2,2,1,EAST] execVM "JSHK_patrols.sqf";

am such a noob

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

×