Jump to content
Sign in to follow this  
Flens

Why won't these vehicles move when spawned?

Recommended Posts

I'm trying to spawn a convoy of POW's, so far it's working fine EXCEPT FOR THE PART WHERE THE VEHICLES MOVE TO THEIR WAYPOINT.

Why is this?

if (isServer) then {
   private ["_randomSpawn","_randomDestination","_convoyGroup","_convoyWP","_BurgerTankGroup","_unit","_index"];
   while {true} do {
       _randomSpawn = getMarkerPos (["spawn","spawn_1","spawn_2"] call BIS_fnc_selectRandom);
       _randomDestination = getMarkerPos (["destination","destination_1","destination_2"] call BIS_fnc_selectRandom);
       if (_randomSpawn distance _randomDestination < 250) exitWith {};
   };

   _convoyGroup = createGroup opfor;
   _convoyWP = _convoyGroup addWaypoint [_randomDestination, 0];
   _convoyWP setWaypointType "MOVE";
   _convoyWP  setWaypointSpeed "NORMAL";
   _convoyWP  setWaypointFormation "COLUMN";

   ifrit1 = [_randomSpawn, 0, "O_MRAP_02_hmg_F", _convoyGroup] call BIS_fnc_spawnVehicle;
   sleep 8;

   truck1 = [_randomSpawn, 0, "O_Truck_02_covered_F", _convoyGroup] call BIS_fnc_spawnVehicle;
   truck1 = truck1 select 0;
   {
       _unit = _x select 0;
       _index = _x select 1;
       _unit assignascargo truck1; _unit moveincargo [truck1, _index]; _unit setcaptive true; removeHeadgear _unit; removeallassigneditems _unit;
   } forEach [[p1,13], [p2,14], [p3,15], [p4,5], [p5,7], [p6,8], [p7,9], [p8,10], [p9,11], [p10,12]];

   sleep 8;
   truck2 = [_randomSpawn, 0, "O_Truck_02_covered_F", _convoyGroup] call BIS_fnc_spawnVehicle;
   truck2 = truck2 select 0;
   {
       _unit = _x select 0;
       _index = _x select 1;
       _unit assignascargo truck2; _unit moveincargo [truck2, _index]; _unit setcaptive true; removeHeadgear _unit; removeallassigneditems _unit;
   } forEach [[p11,5], [p12,7], [p13,8], [p14,9], [p15,10], [p16,11], [p17,12], [p18,13], [p19,14], [p20,15]];

   sleep 8;
   ifrit2 = [_randomSpawn, 0, "O_MRAP_02_hmg_F", _convoyGroup] call BIS_fnc_spawnVehicle;
};

Share this post


Link to post
Share on other sites

The group count for _convoyGroup was 0 when you set the waypoint. That may be the problem. Try creating the waypoint after the vehicles are created.

Share this post


Link to post
Share on other sites

I don't think he created a Center East for it to work correctly.

_eastHQ = createCenter east;
_group_east_1 = createGroup _eastHQ;

Share this post


Link to post
Share on other sites

Yeah I was just offering another possibility and excluded that from my post as you already said that in post #2.

Share this post


Link to post
Share on other sites

Why would I need to create "center east" first?

What is it?

What does it do?

How do I incorporate it here properly? (STEP BY STEP)

Share this post


Link to post
Share on other sites

To create a group in a script file you need declare a center. The centers are west, east, resistance, and civilian. Then you have to create a group that is assigned to one of those centers like the code I posted above. Then from there you can create a unit that is assigned to one of those groups.

_eastHQ = createCenter east;

// group _group_east_1
_group_east_1 = createGroup _eastHQ;
// begin _obj_0, part of group _group_east_1
if (true) then
{
_obj_0 = _group_east_1 createUnit ["O_Soldier_SL_F", [6173.377, 5947.5308, 0], [], 0 ,"NONE"];
_obj_0 setDir 75.229202;
_obj_0 setUnitAbility 0.5;
_obj_0 setRank "SERGEANT";
if(true) then { _group_east_1 selectLeader _obj_0; };
};

Edited by Johnson11B2P
posted example

Share this post


Link to post
Share on other sites

In A3 I don't think createcenter is needed, I tried the above script and it works as it should, AI spawn at a random position and move to random destination.

Share this post


Link to post
Share on other sites
In A3 I don't think createcenter is needed, I tried the above script and it works as it should, AI spawn at a random position and move to random destination.

Then why on earth doesn't it work for me?

[Edit:] I think I found part of the problem, there was a < instead of an > in the script so no destination was assigned. The ifrits however will spawn stuck in the ground and cannot move, causing a pileup, and neither spawn nor destination are selected at random.

Edited by Flens

Share this post


Link to post
Share on other sites
... causing a pileup ...

It's probably because you're creating the vehicles at the same position. And why the loop at the beginning? Can't you just do away with that and call some random positions? Instead of the loop and exitWith.

Edited by Iceman77

Share this post


Link to post
Share on other sites

The loop is what was suggested to me, I've tried a couple different methods of creating a random spawn location and a random destination but none have worked.

If you have a better alternative I'd be very happy to hear it.

The pileup is not caused by the vehicles spawning in the same location, an 8 second wait in between spawns should be plenty to clear the area before the next vehicle pops in. The ifrits are just getting stuck in the ground.

So far the only problem I've found a satisfactory solution to is spawning the players in the trucks as POW's. The rest I still need help with.

Share this post


Link to post
Share on other sites

The waypoint only works if it's less than 250 meters away, I did see one pile up as AI can mess about if the waypoint is behind them.

A waituntil and distance check should fix that or use the a safeplace function.

Share this post


Link to post
Share on other sites

I've already adressed that problem.

Ifrits are still getting stuck in the ground

Convoy is not spawning at a random location

Waypoints are not set at a random location

HOW DO I FIX THIS?

Share this post


Link to post
Share on other sites

I'm not entirely sure why your script isn't working. This is how I would do it:

Example Mission

if (!isServer) exitWith {};

private ["_randomSpawn","_randomDestination","_convoyGroup","_convoyWP","_BurgerTankGroup","_unit","_index","_gap","_hPad","_newPos","_veh"];
_randomSpawn = ["area1","area2","area3"] call BIS_fnc_selectRandom;
_randomDestination = ["des1","des2","des3"] call BIS_fnc_selectRandom;
_convoyGroup = createGroup OPFOR;
_gap = 0;
_newPos = getMarkerPos _randomSpawn;

{
_veh = [_newPos, 0, _x, _convoyGroup] call BIS_fnc_spawnVehicle;
(_veh select 0) setDir markerDir _randomSpawn;
(_veh select 0) setPosATL [getPosATL (_veh select 0) select 0, getPosATL (_veh select 0) select 1, 0];
   _gap = _gap - 15;	
_newPos = (_veh select 0) modelToWorld [0, _gap ,0];

if (typeOf (_veh select 0) == "O_Truck_02_covered_F") then {
	{
		_unit = _convoyGroup createUnit [_x, [0,0,0], [], 0, "NONE"];
		_unit moveInCargo (_veh select 0);
		_unit assignascargo (_veh select 0);  
		_unit setcaptive true; 
		removeHeadgear _unit; 
		removeallassigneditems _unit;
	} foreach ["O_Soldier_F","O_Soldier_F","O_Soldier_F","O_Soldier_F","O_Soldier_F","O_Soldier_F","O_Soldier_F","O_Soldier_F","O_Soldier_F","O_Soldier_F"];
};				
} forEach [
"O_MRAP_02_hmg_F",
"O_Truck_02_covered_F",
"O_Truck_02_covered_F",
"O_MRAP_02_hmg_F"
];

_convoyWP = _convoyGroup addWaypoint [getMarkerPos _randomDestination, 0];
_convoyWP setWaypointType "MOVE";
_convoyWP  setWaypointSpeed "NORMAL";
_convoyWP  setWaypointFormation "COLUMN";

Kind Regards,

Iceman77

Edited by Iceman77

Share this post


Link to post
Share on other sites

Ok what you posted works, but the trucks must be named. How do I get the one to be truck1 and the other to be truck2?

If you just moveincargo the POW's then they'll appear in the front seats, so those seats either need to be occupied by opfor or seats 3 and 5 have to be excluded from the POW seating.

Edited by Flens

Share this post


Link to post
Share on other sites
Ok what you posted works, but the trucks must be named. How do I get the one to be truck1 and the other to be truck2?
As above use setVehicleVarName and set the global variable with missionNameSpace.
If you just moveincargo the POW's then they'll appear in the front seats, so those seats either need to be occupied by opfor or seats 3 and 5 have to be excluded from the POW seating.
Just change Iceman's code to how you did it before, by passing a cargo index to add the units to. btw 0 and 1 are the front two seats, and index 6 is currently broken as it tries to place the unit in the cab at the same position as index 0.

if (!isServer) exitWith {};

private ["_randomSpawn","_randomDestination","_convoyGroup","_convoyWP","_BurgerTankGroup","_unit","_index","_gap","_hPad","_newPos","_veh"];
_randomSpawn = ["area1","area2","area3"] call BIS_fnc_selectRandom;
_randomDestination = ["des1","des2","des3"] call BIS_fnc_selectRandom;
_convoyGroup = createGroup opfor;
_gap = 0;
_newPos = getMarkerPos _randomSpawn;

{
_vehType = _x select 0;
_vehName = _x select 1;
_veh = [_newPos, 0, _vehType, _convoyGroup] call BIS_fnc_spawnVehicle;
if (_vehName != "") then {
	(_veh select 0) setVehicleVarName _vehName;
	missionNamespace setVariable [_vehName, (_veh select 0)];
};
(_veh select 0) setDir markerDir _randomSpawn;
(_veh select 0) setPosATL [getPosATL (_veh select 0) select 0, getPosATL (_veh select 0) select 1, 0];
_gap = _gap - 15;    
_newPos = (_veh select 0) modelToWorld [0, _gap ,0];

if (_vehType == "O_Truck_02_covered_F") then {
	{
		_unit = _convoyGroup createUnit [(_x select 0), [0,0,0], [], 0, "NONE"];
		_index = (_x select 1);
		_unit assignAsCargoIndex [(_veh select 0), _index];
		_unit moveInCargo [(_veh select 0), _index];  
		_unit setCaptive true; 
		removeHeadgear _unit; 
		removeAllAssignedItems _unit;
	} forEach [
		["O_Soldier_F",2],
		["O_Soldier_F",3],
		["O_Soldier_F",4],
		["O_Soldier_F",5],
		["O_Soldier_F",7],
		["O_Soldier_F",8],
		["O_Soldier_F",9],
		["O_Soldier_F",10],
		["O_Soldier_F",11],
		["O_Soldier_F",12]
	];
};                
} forEach [
["O_MRAP_02_hmg_F", ""],
["O_Truck_02_covered_F", "truck1"],
["O_Truck_02_covered_F", "truck2"],
["O_MRAP_02_hmg_F", ""]
];

_convoyWP = _convoyGroup addWaypoint [getMarkerPos _randomDestination, 0];
_convoyWP setWaypointType "MOVE";
_convoyWP  setWaypointSpeed "NORMAL";
_convoyWP  setWaypointFormation "COLUMN";  

Share this post


Link to post
Share on other sites

This is excellent but how do I exclude markers from being picked as the destination if they're within x meters of the spawn?

Share this post


Link to post
Share on other sites

Goddamnit the script I had earlier at least had a working destination exclusion thing going on but I can't get it to play nice with this new one.

Share this post


Link to post
Share on other sites

if (!isServer) exitWith {};

private ["_spawns","_randomSpawn","_destinations","_posFound","_randomDestination","_convoyGroup","_convoyWP","_BurgerTankGroup","_unit","_index","_gap","_hPad","_newPos","_veh","_vehType","_vehName"];

_spawns = ["area1","area2","area3"];
_posFound = false;
while {!_posFound} do {
_randomSpawn = _spawns call BIS_fnc_selectRandom;
_destinations = ["des1","des2","des3"];
while { !_posFound } do {
	_randomDestination = _destinations call BIS_fnc_selectRandom;
	if ( (getMarkerPos _randomSpawn) distance (getMarkerPos _randomDestination) < 250 ) exitWith {_posFound = true;};
	_destinations = _destinations - [_randomDestination];
	if (count _destinations == 0) exitWith {};
};
_spawns = _spawns - [_randomSpawn];
if (count _spawns == 0) exitWith {};
};

if (_posFound) then {
_convoyGroup = createGroup opfor;
_gap = 0;
_newPos = getMarkerPos _randomSpawn;

{
	 _vehType = _x select 0;
	 _vehName = _x select 1;
	 _veh = [_newPos, 0, _vehType, _convoyGroup] call BIS_fnc_spawnVehicle;
	 if (_vehName != "") then {
		  (_veh select 0) setVehicleVarName _vehName;
		  missionNamespace setVariable [_vehName, (_veh select 0)];
	 };
	 (_veh select 0) setDir markerDir _randomSpawn;
	 (_veh select 0) setPosATL [getPosATL (_veh select 0) select 0, getPosATL (_veh select 0) select 1, 0];
	 _gap = _gap - 15;
	 _newPos = (_veh select 0) modelToWorld [0, _gap ,0];

	 if (_vehType == "O_Truck_02_covered_F") then {
		  {
				_unit = _convoyGroup createUnit [(_x select 0), [0,0,0], [], 0, "NONE"];
				_index = (_x select 1);
				_unit assignAsCargoIndex [(_veh select 0), _index];
				_unit moveInCargo [(_veh select 0), _index];
				_unit setCaptive true;
				removeHeadgear _unit;
				removeAllAssignedItems _unit;
		  } forEach [
				["O_Soldier_F",2],
				["O_Soldier_F",3],
				["O_Soldier_F",4],
				["O_Soldier_F",5],
				["O_Soldier_F",7],
				["O_Soldier_F",8],
				["O_Soldier_F",9],
				["O_Soldier_F",10],
				["O_Soldier_F",11],
				["O_Soldier_F",12]
		  ];
	 };
} forEach [
	 ["O_MRAP_02_hmg_F", ""],
	 ["O_Truck_02_covered_F", "truck1"],
	 ["O_Truck_02_covered_F", "truck2"],
	 ["O_MRAP_02_hmg_F", ""]
];

_convoyWP = _convoyGroup addWaypoint [getMarkerPos _randomDestination, 0];
_convoyWP setWaypointType "MOVE";
_convoyWP  setWaypointSpeed "NORMAL";
_convoyWP  setWaypointFormation "COLUMN";
};

Will pick a random spawn position and then check each destination at random, if it finds a destination that is within 250m of the spawn position then it will spawn your vehicles, if it runs out of destinations then it will pick a new spawn position and check against all destinations again. It will check all possible combinations until it runs out of positions then it will exit the script without spawning anything. Unlikely to happen if your specifying the positions but...

Edited by Larrow

Share this post


Link to post
Share on other sites

Pretty much have to do it this way since some of the spawn locations are also supposed to have a random chance of being destinations instead if the convoy spawns at another end of the map.

Without having the exclusion check I would be limited to very few possible spawns and the mission wouldn't have the replayability I'm shooting for, if I can get this to work I can essentially have infinite spawns and destinations to select from.

Tested and it's working, many thanks.

The only question mark now is how to get the ai to not crash into everything lining the road side.

Edited by Flens

Share this post


Link to post
Share on other sites

Hello! I know this old, but I like this idea! Any setup instructions that someone can provide? I would like to mess around with this and see what trouble I can get into.

 

update: nevermind I have it working. Thanks Larrow for sharing. I heavily modified it and it is awesome!

 

dubl

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  

×