Jump to content
Sign in to follow this  
SRBuckey5266

Why doesn't this work?....

Recommended Posts

_h1 = "Mi24_V" createVehicle (_pos); _p_1_1 = "RU_Soldier_Pilot" createUnit [_pos, group player]; _p_1_1 moveInDriver _h1;

Any idea why the AI doesn't get in the heli?

Share this post


Link to post
Share on other sites

The () are unnecessary for createVehicle. Second, do you get any error?

Also I'd try using

_p_1_1 assignAsDriver _h1;

before the moveInDriver command.

Share this post


Link to post
Share on other sites

There often needs to be a small sleep between creating a helicopter and moving any unit inside it. Obviously, this will require the code to be executed in a script or spawn but it would appear you're doing that anyways. Something like this:

[] spawn {
private ["_pos"];
_pos = your_position_here;

private ["_h1", "_p_1_1"];
_h1 = createVehicle ["Mi24_V", _pos, [], 0, "NONE"];
_p_1_1 = group player createUnit ["RU_Soldier_Pilot", [10,10,0], [], 0, "NONE"];

sleep 0.05;

_p_1_1 moveInDriver _h1;
};

Note that I've also changed createUnit and createVehicle to their array variants (createVehicle array createUnit array). The benefit of this is mainly in case you are wanting to start the Mi-24 already flying with its engine on. Just replace the last element of the createVehicle array with "FLY".

Hope that helps!

Share this post


Link to post
Share on other sites

When we're already at the createVehicle array stuff, is it really faster than the regular createVehicle performance-wise?

Share this post


Link to post
Share on other sites

something like 10x quicker? or maybe I read that about getposatl or something.

Share this post


Link to post
Share on other sites
The () are unnecessary for createVehicle. Second, do you get any error?

Also I'd try using

_p_1_1 assignAsDriver _h1;

before the moveInDriver command.

Thanks for the tip. :p

There often needs to be a small sleep between creating a helicopter and moving any unit inside it. Obviously, this will require the code to be executed in a script or spawn but it would appear you're doing that anyways. Something like this:

[] spawn {
private ["_pos"];
_pos = your_position_here;

private ["_h1", "_p_1_1"];
_h1 = createVehicle ["Mi24_V", _pos, [], 0, "NONE"];
_p_1_1 = group player createUnit ["RU_Soldier_Pilot", [10,10,0], [], 0, "NONE"];

sleep 0.05;

_p_1_1 moveInDriver _h1;
};

Note that I've also changed createUnit and createVehicle to their array variants (createVehicle array createUnit array). The benefit of this is mainly in case you are wanting to start the Mi-24 already flying with its engine on. Just replace the last element of the createVehicle array with "FLY".

Hope that helps!

Ah thanks, I had a feeling that the units might get created too soon. Thanks for the tip.

Also, with the array, yeah. I usually tend to avoid that as it's a lot of extra typing, but I guess I'll break that lazy habit. :yay:

However, it seems the problem still persists. I have this test code:

onMapSingleClick{
if(_shift) then {
	hint "a";

	_upos = ([(_pos select 0)+7,(_pos select 1),(_pos select 2)]);
	_h1 = "Mi24_V" createVehicle (_pos);
		sleep 0.1;
		_p_1_1 = "RU_Soldier_Pilot" createUnit [_upos, group player]; _p_1_1 moveInDriver _h1;
		_p_1_2 = "RU_Soldier_Pilot" createUnit [_upos, group player]; _p_1_2 moveInGunner _h1;
	_h2 = "Mi24_V" createVehicle ([(_pos select 0)+14,(_pos select 1),(_pos select 2)]);
		sleep 0.1;
		_p_2_1 = "RU_Soldier_Pilot" createUnit [_upos, group player]; _p_2_1 moveInDriver _h2;
		_p_2_2 = "RU_Soldier_Pilot" createUnit [_upos, group player]; _p_2_2 moveInGunner _h2;
	_h3 = "Mi24_V" createVehicle ([(_pos select 0)+28,(_pos select 1),(_pos select 2)]);
		sleep 0.1;
		_p_3_1 = "RU_Soldier_Pilot" createUnit [_upos, group player]; _p_3_1 moveInDriver _h3;
		_p_3_2 = "RU_Soldier_Pilot" createUnit [_upos, group player]; _p_3_2 moveInGunner _h3;

	_t1 = "T72_RU" createVehicle ([(_pos select 0),(_pos select 1)-28,(_pos select 2)]);
		sleep 0.1;
		_c_1_1 = "RU_Soldier_Crew" createUnit [_upos, group player]; _c_1_1 moveInDriver _t1;
		_c_1_2 = "RU_Soldier_Crew" createUnit [_upos, group player]; _c_1_2 moveInGunner _t1;
		_c_1_3 = "RU_Soldier_Crew" createUnit [_upos, group player]; _c_1_3 moveInCommander _t1;
	_t2 = "T72_RU" createVehicle ([(_pos select 0)+14,(_pos select 1)-28,(_pos select 2)]);
		sleep 0.1;
		_c_2_1 = "RU_Soldier_Crew" createUnit [_upos, group player]; _c_2_1 moveInDriver _t2;
		_c_2_2 = "RU_Soldier_Crew" createUnit [_upos, group player]; _c_2_2 moveInGunner _t2;
		_c_2_3 = "RU_Soldier_Crew" createUnit [_upos, group player]; _c_2_3 moveInCommander _t2;
	_t3 = "T72_RU" createVehicle ([(_pos select 0)+28,(_pos select 1)-28,(_pos select 2)]);
		sleep 0.1;
		_c_3_1 = "RU_Soldier_Crew" createUnit [_upos, group player]; _c_3_1 moveInDriver _t3;
		_c_3_2 = "RU_Soldier_Crew" createUnit [_upos, group player]; _c_3_2 moveInGunner _t3;
		_c_3_3 = "RU_Soldier_Crew" createUnit [_upos, group player]; _c_3_3 moveInCommander _t3;
	_t4 = "T90" createVehicle ([(_pos select 0)+14,(_pos select 1)-14,(_pos select 2)]);
		sleep 0.1;
		_c_4_1 = "RU_Soldier_Crew" createUnit [_upos, group player]; _c_4_1 moveInDriver _t4;
		_c_4_2 = "RU_Soldier_Crew" createUnit [_upos, group player]; _c_4_2 moveInGunner _t4;
		_c_4_3 = "RU_Soldier_Crew" createUnit [_upos, group player]; _c_4_3 moveInCommander _t4;

	//BODY GUARDS
	_c_1_1 = "MVD_Soldier_MG" createUnit [_upos, group player];
	"MVD_Soldier_MG" createUnit [_upos, group player];
	"MVD_Soldier_Marksman" createUnit [_upos, group player];
	"MVD_Soldier_Marksman" createUnit [_upos, group player];
	"RU_Soldier_HAT" createUnit [_upos, group player];
	"RU_Soldier_HAT" createUnit [_upos, group player];
	"RU_Soldier_AA" createUnit [_upos, group player];
	"RU_Soldier_AA" createUnit [_upos, group player];

	player setPos _pos;
	hint "d";
}
}

All the units/vehicles spawn, but the units still don't get in the vehicles. Argh!

Edited by SRBuckey5266

Share this post


Link to post
Share on other sites

When you introduce sleeps, the code needs to be executed in a script or a spawn. onMapSingleClick only calls the code. That, however, is now unnecessary. After debugging the issue, it appears to be down to your code not using createUnit array. I would imagine the two variants are handled slightly differently. Remove the sleeps, change your code so that it uses createUnit array and it will work, or feel free to use this rewritten version I wrote to test it:

onMapSingleClick {
if (_shift) then {
	hint "a";

	// Create Hinds
	private ["_xDist"];
	_xDist = 0;

	for "_i" from 0 to 2 do {
		private ["_veh"];
		_veh = createVehicle [
			"Mi24_V",
			[
				(_pos select 0) + _xDist,
				_pos select 1,
				_pos select 2
			],
			[],
			0,
			"FORM"
		];

		// Start the Hind's simulation
		_veh setVelocity [0,0,-1];

		// Increase distance for next Hind
		_xDist = _xDist + 14;

		for "_i" from 0 to 1 do {
			private ["_unit"];
			_unit = group player createUnit [
				"RU_Soldier_Pilot",
				[10,10,10],
				[],
				0,
				"FORM"
			];

			// Move into the Hinds
			if (_veh emptyPositions "Gunner" > 0) then {
				_unit moveInGunner _veh;
			} else {
				_unit moveInDriver _veh;
			};
		};
	};

	// Create T-72s
	_xDist = 0;

	for "_i" from 0 to 3 do {
		private ["_veh"];
		_veh = createVehicle [
			"T72_RU",
			[
				(_pos select 0) + _xDist,
				(_pos select 1) - 28,
				_pos select 2
			],
			[],
			0,
			"FORM"
		];

		// Increase distance for next T-72
		_xDist = _xDist + 14;

		// Start the T-72's simulation
		_veh setVelocity [0,0,-1];

		// Create crew
		for "_i" from 0 to 2 do {
			private ["_unit"];
			_unit = group player createUnit [
				"RU_Soldier_Crew",
				[10,10,10],
				[],
				0,
				"FORM"
			];

			// Move into the T-72s
			if (_veh emptyPositions "Commander" > 0) then {
				_unit moveInCommander _veh;
			} else {
				if (_veh emptyPositions "Gunner" > 0) then {
					_unit moveInGunner _veh;
				} else {
					_unit moveInDriver _veh;
				};
			};
		};
	};

	// Create T-90
	private ["_veh"];
	_veh = createVehicle [
		"T90",
		[
			(_pos select 0) + 14,
			(_pos select 1) - 14,
			_pos select 2
		],
		[],
		0,
		"NONE"
	];

	// Start the T-90's simulation
	_veh setVelocity [0,0,-1];

	// Create crew
	for "_i" from 0 to 2 do {
		private ["_unit"];
		_unit = group player createUnit [
			"RU_Soldier_Crew",
			[10,10,10],
			[],
			0,
			"FORM"
		];

		// Move into the T-72s
		if (_veh emptyPositions "Commander" > 0) then {
			_unit moveInCommander _veh;
		} else {
			if (_veh emptyPositions "Gunner" > 0) then {
				_unit moveInGunner _veh;
			} else {
				_unit moveInDriver _veh;
			};
		};
	};

	// Create bodyguards
	private ["_upos"];
	_upos = [
		(_pos select 0) + 7,
		_pos select 1,
		_pos select 2
	];

	for "_i" from 0 to 7 do {
		private ["_unit"];
		_unit = group player createUnit [
			if (_i < 1) then {
				"MVD_Soldier_MG"
			} else {
				if (_i < 3) then {
					"MVD_Soldier_Marksman"
				} else {
					if (_i < 5) then {
						"RU_Soldier_HAT"
					} else {
						"RU_Soldier_AA"
					}
				}
			},
			_upos,
			[],
			0,
			"FORM"
		];
	};

	player setPos _pos;
	hint "d";
};
};

Share this post


Link to post
Share on other sites
When you introduce sleeps, the code needs to be executed in a script or a spawn. onMapSingleClick only calls the code. That, however, is now unnecessary. After debugging the issue, it appears to be down to your code not using createUnit array. I would imagine the two variants are handled slightly differently. Remove the sleeps, change your code so that it uses createUnit array and it will work, or feel free to use this rewritten version I wrote to test it:

onMapSingleClick {
if (_shift) then {
	hint "a";

	// Create Hinds
	private ["_xDist"];
	_xDist = 0;

	for "_i" from 0 to 2 do {
		private ["_veh"];
		_veh = createVehicle [
			"Mi24_V",
			[
				(_pos select 0) + _xDist,
				_pos select 1,
				_pos select 2
			],
			[],
			0,
			"FORM"
		];

		// Start the Hind's simulation
		_veh setVelocity [0,0,-1];

		// Increase distance for next Hind
		_xDist = _xDist + 14;

		for "_i" from 0 to 1 do {
			private ["_unit"];
			_unit = group player createUnit [
				"RU_Soldier_Pilot",
				[10,10,10],
				[],
				0,
				"FORM"
			];

			// Move into the Hinds
			if (_veh emptyPositions "Gunner" > 0) then {
				_unit moveInGunner _veh;
			} else {
				_unit moveInDriver _veh;
			};
		};
	};

	// Create T-72s
	_xDist = 0;

	for "_i" from 0 to 3 do {
		private ["_veh"];
		_veh = createVehicle [
			"T72_RU",
			[
				(_pos select 0) + _xDist,
				(_pos select 1) - 28,
				_pos select 2
			],
			[],
			0,
			"FORM"
		];

		// Increase distance for next T-72
		_xDist = _xDist + 14;

		// Start the T-72's simulation
		_veh setVelocity [0,0,-1];

		// Create crew
		for "_i" from 0 to 2 do {
			private ["_unit"];
			_unit = group player createUnit [
				"RU_Soldier_Crew",
				[10,10,10],
				[],
				0,
				"FORM"
			];

			// Move into the T-72s
			if (_veh emptyPositions "Commander" > 0) then {
				_unit moveInCommander _veh;
			} else {
				if (_veh emptyPositions "Gunner" > 0) then {
					_unit moveInGunner _veh;
				} else {
					_unit moveInDriver _veh;
				};
			};
		};
	};

	// Create T-90
	private ["_veh"];
	_veh = createVehicle [
		"T90",
		[
			(_pos select 0) + 14,
			(_pos select 1) - 14,
			_pos select 2
		],
		[],
		0,
		"NONE"
	];

	// Start the T-90's simulation
	_veh setVelocity [0,0,-1];

	// Create crew
	for "_i" from 0 to 2 do {
		private ["_unit"];
		_unit = group player createUnit [
			"RU_Soldier_Crew",
			[10,10,10],
			[],
			0,
			"FORM"
		];

		// Move into the T-72s
		if (_veh emptyPositions "Commander" > 0) then {
			_unit moveInCommander _veh;
		} else {
			if (_veh emptyPositions "Gunner" > 0) then {
				_unit moveInGunner _veh;
			} else {
				_unit moveInDriver _veh;
			};
		};
	};

	// Create bodyguards
	private ["_upos"];
	_upos = [
		(_pos select 0) + 7,
		_pos select 1,
		_pos select 2
	];

	for "_i" from 0 to 7 do {
		private ["_unit"];
		_unit = group player createUnit [
			if (_i < 1) then {
				"MVD_Soldier_MG"
			} else {
				if (_i < 3) then {
					"MVD_Soldier_Marksman"
				} else {
					if (_i < 5) then {
						"RU_Soldier_HAT"
					} else {
						"RU_Soldier_AA"
					}
				}
			},
			_upos,
			[],
			0,
			"FORM"
		];
	};

	player setPos _pos;
	hint "d";
};
};

Ah, glad you could find out the reason. And thank you for the sample code, I guess I really should have used for loops, heh.

The AI is successfully put into the vehicles, but it seemed like all the units decided to attack each other....hah.

Updated code:

onMapSingleClick{
if(_shift) then {
	_numHelis = 7;
	_numTanks = 4;

	_upos = ([(_pos select 0)+7,(_pos select 1),(_pos select 2)]);

	//helis
	_c = 0;
	for "_x" from 0 to _numHelis do {
		_heli = createVehicle ["Mi24_V", [(_pos select 0)+(_c * 16),(_pos select 1),(_pos select 2)], [], 0, "FLY"];

		_pilot = group player createUnit ["RU_Soldier_Pilot", _upos, [], 0, "FORM"]; _pilot moveInDriver _heli;
		_gunner = group player createUnit ["RU_Soldier_Pilot", _upos, [], 0, "FORM"]; _gunner moveInGunner _heli;

		_c = _c + 1;
	};

	_c = 0;
	for "_x" from 0 to _numTanks do {
		if(_c == 0) then {
			_tank = createVehicle ["T90", [(_pos select 0)+((_numTank * 7)/2),(_pos select 1)-28,(_pos select 2)], [], 0, "NONE"];
		}else{
			_tank = createVehicle ["T72_RU", [(_pos select 0)+(_c * 7),(_pos select 1)-28,(_pos select 2)], [], 0, "NONE"];
		};

		_driver = group player createUnit ["RU_Soldier_Crew", _upos, [], 0, "FORM"]; _driver moveInDriver _t1;
		_gunner = group player createUnit ["RU_Soldier_Crew", _upos, [], 0, "FORM"]; _gunner moveInGunner _t1;
		_commander = group player createUnit ["RU_Soldier_Crew", _upos, [], 0, "FORM"]; _commander moveInCommander _t1;

		_c = _c + 1;
	};

	player setPos _upos;
}
}

Share this post


Link to post
Share on other sites

I think you need them to join a group the units to the player.

[_pilot,_gunner] join group player;

[_driver,_gunner,_commander] join group player;

also you have an issue with tanks, you create tank called _tank and then move them init _t1 which won't work.

You will also need to make _t1 private private ["_t1"];

Also ad you joining so many they may be hostile until joined, it would be better to create them in there own group on the side you require and then join the player if that's what your after.

Share this post


Link to post
Share on other sites

You should use it because _t1 vehicle is created within the if scope but later you try and move the units into _t1 vehicles but they don't know what it is.

I also took the code out of the onmapclick and run it as normal code using this

onMapSingleClick { if (_shift) then { [_pos] execvm "spawnstuff.sqf"}};

save as "spawnstuff.sqf"

private ["_t1"];

	_numHelis = 7;
	_numTanks = 4;
	_pos = _this select 0;


	_t1 = temp;
	_upos = ([(_pos select 0)+7,(_pos select 1),(_pos select 2)]);

	//helis
	_c = 0;
	for "_x" from 0 to _numHelis do {

		_heli = createVehicle ["Mi24_V", [(_pos select 0)+(_c * 16),(_pos select 1),(_pos select 2)], [], 0, "FLY"];

		_pilot = group player createUnit ["RU_Soldier_Pilot", _upos, [], 0, "FORM"]; _pilot moveInDriver _heli;
		_gunner = group player createUnit ["RU_Soldier_Pilot", _upos, [], 0, "FORM"]; _gunner moveInGunner _heli;
		[_pilot,_gunner] join group player;
		_c = _c + 1;
	};

	_c = 0;
	for "_x" from 0 to _numTanks do {
		if(_c == 0) then {
			hint "90";
			_t1 = createVehicle ["T90", [(_pos select 0)+(_c * 7),(_pos select 1)-28,(_pos select 2)], [], 0, "NONE"];

		}else{
			_t1 = createVehicle ["T72_RU", [(_pos select 0)+(_c * 7),(_pos select 1)-28,(_pos select 2)], [], 0, "NONE"];

		};
		_driver = group player createUnit ["RU_Soldier_Crew", _upos, [], 0, "FORM"]; _driver moveInDriver _t1;
		_gunner = group player createUnit ["RU_Soldier_Crew", _upos, [], 0, "FORM"]; _gunner moveInGunner _t1;
		_commander = group player createUnit ["RU_Soldier_Crew", _upos, [], 0, "FORM"]; _commander moveInCommander _t1;
		[_driver,_gunner,_commander] join group player;
		_c = _c + 1;

};

player setPos _upos;

This should also work, well it does up to a point. For some reason the units won't respond. You may need a function module on the map.

 waituntil {!isnil "bis_fnc_init"}; 
if (!isServer) exitWith {}; 

// private ["_t1"];
_numHelis = 7;
_numTanks = 4;
_pos = _this select 0;
_height = 50;
_dir = 90;
_side = east;

 _upos = ([(_pos select 0)+7,(_pos select 1),(_pos select 2)]);

    createcenter _side;

//HELIS

for  [{_i = 0},{_i < _numtanks},{_i = _i + 1}] do {
    _heli = [[(_pos select 0)+(_i * 40),_pos select 1,_height],_dir,"Mi24_V",_side] call bis_fnc_spawnvehicle;
           [_heli select 2 ] join group player;
};

//TANKS

for [{_i = 0},{_i < _numtanks},{_i = _i + 1}] do {
   if(_i == 0) then {			      
        _t1 = [[(_pos select 0)+(_i * 14),(_pos select 1)-28,(_pos select 2)],_dir,   "T90",_side] call bis_fnc_spawnvehicle;
	    } else {
        _t1 = [[(_pos select 0)+(_i * 14),(_pos select 1)-28,(_pos select 2)],_dir,"T72_RU",_side] call bis_fnc_spawnvehicle;
};

     [_t1 select 2 ] join group player;


};

player setPos _upos;

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Does anyone have a clue as to way when trying to use the second script vehicles created are not responding to my commands even though they are in my group.

They will engage the enemy but they just won't move.

Share this post


Link to post
Share on other sites

Give the following a shot.

waituntil {!isnil "bis_fnc_init"};
//if (!isServer) exitWith {}; OnMapclick is executed locally. The only time the local unit  is the server is when the player executing the script is the server. (Impossible on dedicated server).

// private ["_t1"];
_numHelis = 7;
_numTanks = 4;
_pos = _this select 0;
_height = 50;
_dir = 90;
_side = east;

_upos = ([(_pos select 0)+7,(_pos select 1),(_pos select 2)]);
createcenter _side;

//HELIS
for "_i" from 0 to (_numHelis - 1) do {
_array = [[(_pos select 0)+(_i * 40),_pos select 1,_height],_dir,"Mi24_V",group player] call bis_fnc_spawnvehicle;
//_heli = _array select 0; this is not needed but I kept to show index correction. 

};
//TANKS
for "_i" from 0 to (_numTanks - 1) do {
_type = if(_i == 0) then {"T90"}else{"T72_RU"};
_array = [[(_pos select 0)+(_i * 14),(_pos select 1)-28,(_pos select 2)],_dir,_type,group player] call bis_fnc_spawnvehicle;
//_t1 = _array select 0; see above
};
player setPos _upos;  

Edited by Kempco

Share this post


Link to post
Share on other sites
Does anyone have a clue as to way when trying to use the second script vehicles created are not responding to my commands even though they are in my group.

They will engage the enemy but they just won't move.

F2K, won't you need to join the units of the group to the player group, not group join group...

_heligrp = _heli select 2;

{_x join group player} forEach units _heligrp;

Share this post


Link to post
Share on other sites
F2K, won't you need to join the units of the group to the player group, not group join group...

_heligrp = _heli select 2;

{_x join group player} forEach units _heligrp

Group to join is defined as the last index in the bis_fnc_spawnvehicle.

_array = [[(_pos select 0)+(_i * 40),_pos select 1,_height],_dir,"Mi24_V",group player] call bis_fnc_spawnvehicle;

Share this post


Link to post
Share on other sites

Ah yes, forgot, but that's not how F2K had it scripted...Both should work. Of course easier to just join on creation via bis_fnc_spawnvehicle like you mentioned

Share this post


Link to post
Share on other sites

Thanks guys that was bugging me and I just couldn't see it.

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  

×