Jump to content
Sign in to follow this  
Impact

Scripting waypoints

Recommended Posts

Hello, I want to spawn a group of soldiers, and give them a waypoint to go to. This is my code:

Blufor_Inf1 = Creategroup WEST;
_Leader="USMC_Soldier_TL" createUnit [getMarkerPos "Blufor_Inf1", Blufor_Inf1, "Blufor_Inf1=this",1,"Sergeant"];
_Unit2="USMC_Soldier_SL" createUnit [getMarkerPos "Blufor_Inf1", Blufor_Inf1, "Blufor_Inf1=this",1,"Corporal"];
_Unit3="USMC_Soldier_MG" createUnit [getMarkerPos "Blufor_Inf1", Blufor_Inf1, "Blufor_Inf1=this",1,"Private"];
_Unit4="USMC_Soldier_Medic" createUnit [getMarkerPos "Blufor_Inf1", Blufor_Inf1, "Blufor_Inf1=this",1,"Private"];
_Unit5="USMC_Soldier" createUnit [getMarkerPos "Blufor_Inf1", Blufor_Inf1, "Blufor_Inf1=this",1,"Private"];
_Unit6="USMC_Soldier_SL" createUnit [getMarkerPos "Blufor_Inf1", Blufor_Inf1, "Blufor_Inf1=this",1,"Corporal"];
_Unit7="USMC_Soldier_LAT" createUnit [getMarkerPos "Blufor_Inf1", Blufor_Inf1, "Blufor_Inf1=this",1,"Private"];
_Unit8="USMC_Soldier_GL" createUnit [getMarkerPos "Blufor_Inf1", Blufor_Inf1, "Blufor_Inf1=this",1,"Private"];
_Unit9="USMC_Soldier" createUnit [getMarkerPos "Blufor_Inf1", Blufor_Inf1, "Blufor_Inf1=this",1,"Private"];

Blufor_Inf1_WP = Blufor_Inf1 addWaypoint [getMarkerPos "Blufor_Inf1_WP",0];
exit

The units are already spawning, but the waypoint doesn't seem to be set up. Help me, please!

Share this post


Link to post
Share on other sites

Hi mate... try it this way.....

Blufor_Inf1 = Creategroup WEST;

"USMC_Soldier_TL" createUnit [getMarkerPos "Blufor_Inf1", Blufor_Inf1, "_Leader=this",1,"Sergeant"];
"USMC_Soldier_SL" createUnit [getMarkerPos "Blufor_Inf1", Blufor_Inf1, "_Unit2=this",1,"Corporal"];
//blah...blah...blah.... other units spawn here

Blufor_Inf1_WP = Blufor_Inf1 addWaypoint [getMarkerPos "Blufor_Inf1_WP",0];

Edited by twirly
Correction to code

Share this post


Link to post
Share on other sites

Thanks! This works now. But now I got a different problem, I wanna check if a group is still alive, but it seems that you can only check for individual units. Is that correct or is there another way?

Share this post


Link to post
Share on other sites

you can check with alive _x - foreach group etc - but this will only check those already alive in your group.

could try making an array either by naming those in the group or by adding those of the specified group to an array- then check the array.

Share this post


Link to post
Share on other sites

With "units" I get an array of "Blufor_Inf1", right?

ForEach doesn't have any return value, so I can't use it as condition.

That is why this won't work.

	if ({alive _x} forEach units group Blufor_Inf1) then
{
	hint "alive";
}	
else
{
	hint "not alive";
};

Ah nevermind, got the error. The "group" is too much. It works now.

Edited by Impact

Share this post


Link to post
Share on other sites

This should work just as well.

if ({alive _x} count units Blufor_Inf1  == 0) then   {  hint "not alive";  } else {  hint "alive";  };  

Share this post


Link to post
Share on other sites

I just tried to add some armor groups to the battlefield, are those working different to infantry units? I can't seem to spawn any vehicles with this:

Blufor_Sup1 = Creategroup WEST;
"LAV25" createUnit [getMarkerPos "Blufor_Sup1", Blufor_Sup1, "_Leader=this",1,"Sergeant"];
"LAV25" createUnit [getMarkerPos "Blufor_Sup1", Blufor_Sup1, "_Unit2=this",1,"Sergeant"];
"LAV25" createUnit [getMarkerPos "Blufor_Sup1", Blufor_Sup1, "_Unit3=this",1,"Sergeant"];
"LAV25" createUnit [getMarkerPos "Blufor_Sup1", Blufor_Sup1, "_Unit4=this",1,"Sergeant"];

Blufor_Sup1_WP = Blufor_Sup1 addWaypoint [getMarkerPos "Blufor_Sup1_WP",0];

exit

Share this post


Link to post
Share on other sites

But in the wiki I read that you can create all the units that are in CfgVehicles, and all the vehicles are part of that. So I have to add crew too, lots of work...

Share this post


Link to post
Share on other sites

You can use the BIS Functions to spawn vehicles.... and infantry for that matter.

It's always going to be a lot of work my friend. You will get out of Arma 2 only what you put into it!

Share this post


Link to post
Share on other sites

Hello,

This is a city to city patrol script I made a few years back that you can use, as it has waypoints spawn bis groups in it allready, or just read it and copy what bits work for you :)

//////////////////////////////////////////////////////////////////
// Function file for [ARMA2/Combined Ops]
// Created by: [(AEF) Odin]
//////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////
// Function file for ARMA2
// Created by: Odin aka (AEF)Odin
// Visit http://www.aef-hq.com.au/aef3 
// USAGE ==>
//
// Create a rectangle marker and name it what you like.
// Add a function module.
// Add a "CityCenter" Logic.
// Be sure to add a Russian rifleman somewhere on the map (set probabilaty of presence to 0),
// Or change the units side to represent the patrol groups side.
// YOU MUST have at these lines in you init.sqf
//
// if (!isServer) exitWith{};
// waitUntil {!isNil "bis_fnc_init"};
//
// To call this script you must include the "MarkerName" and one of  the 6 different groups.
// "INF"
// "MOTO"
// "MECH"
// "TANK"
// "AIR"
// "2GROUPS"
// Now add this line to your init
// call{["MarkerName","YourChoiceOfGroup"] execVM "CityToCityPatrol.sqf"};
// EXAMPLE ==>
// call{["pat","AIR"] execVM "CityFlatPatrol.sqf"};
//
// This script has been set up to spawn East groups, if you want another group uncomment the desired
// side and re add comment "//" to previous Group
// To change from East to West EXAMPLE==>
//	_InfGrp = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "RU" >> "Infantry" >> "RU_InfSquad")] call BIS_fnc_spawnGroup;	
//	//_InfGrp = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "INS" >> "Infantry" >> "INS_InfSquad")] call BIS_fnc_spawnGroup;	
//	//_InfGrp = [_zone_pos, west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Infantry" >> "USMC_InfSquad")] call BIS_fnc_spawnGroup;				
//	//_InfGrp = [getMarkerPos _zone, west, (configFile >> "CfgGroups" >> "West" >> "CDF" >> "Infantry" >> "CDF_InfSquad")] call BIS_fnc_spawnGroup;				
//	//_InfGrp = [_zone_pos, resistance, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Infantry" >> "GUE_InfSquad")] call BIS_fnc_spawnGroup;				
//	//_InfGrp = [_zone_pos, civilian, (configFile >> "CfgGroups" >> "Civilian" >> "CIV" >> "Infantry" >> "CIV_Crowd")] call BIS_fnc_spawnGroup;	
// 
// Would look like this
//
//	//_InfGrp = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "RU" >> "Infantry" >> "RU_InfSquad")] call BIS_fnc_spawnGroup;	
//	//_InfGrp = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "INS" >> "Infantry" >> "INS_InfSquad")] call BIS_fnc_spawnGroup;	
//	_InfGrp = [_zone_pos, west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Infantry" >> "USMC_InfSquad")] call BIS_fnc_spawnGroup;				
//	//_InfGrp = [getMarkerPos _zone, west, (configFile >> "CfgGroups" >> "West" >> "CDF" >> "Infantry" >> "CDF_InfSquad")] call BIS_fnc_spawnGroup;				
//	//_InfGrp = [_zone_pos, resistance, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Infantry" >> "GUE_InfSquad")] call BIS_fnc_spawnGroup;				
//	//_InfGrp = [_zone_pos, civilian, (configFile >> "CfgGroups" >> "Civilian" >> "CIV" >> "Infantry" >> "CIV_Crowd")] call BIS_fnc_spawnGroup;	
// 
// Use the Included ClassName refernce list "GroupClasses.txt" to change the GroupClasses.
//
//////////////////////////////////////////////////////////////////

if (!isServer) exitWith{};
Private ["_start","_zone","_zone_size","_zone_size_x","_zone_size_y","_type"];

_start = false;

_zone = _this select 0;
//_zone_pos = getMarkerPos _zone;
_zone_size = MarkerSize _zone;
_zone_size_x = (_zone_size select 0);
_zone_size_y = (_zone_size select 1);

sleep 0.05;
_start = true;

  _type = _this select 1;

  if (_start) then
  {

Private ["_init","_search","_zone_pos","_InfGrp","_MotoGrp","_MechGrp","_TankGrp","_AirGrp","_Grp1","_Grp2","_UnitLeader","_list","_typeVar","_neighbors","_name","_x","_wp1","_wp2","_wp3","_wp4","_wp5","_wp6","_wp7","_cond1","_cond2"];
_init = switch (_type) do {

	case "INF": {

		_search = createMarker ["_spawn",getMarkerPos _zone];
		_search setMarkerType "Empty";
		_search setMarkerColor "Default";
		_search setMarkerSize [0.5, 0.5];
		sleep 0.001;
		_search setMarkerPos [(getMarkerPos _search select 0)+ Random _zone_size_x,(getMarkerPos _search select 1)- Random _zone_size_x];
		_zone_pos = getMarkerPos _search;			

 		_InfGrp = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "RU" >> "Infantry" >> "RU_InfSquad")] call BIS_fnc_spawnGroup;	
 		//_InfGrp = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "INS" >> "Infantry" >> "INS_InfSquad")] call BIS_fnc_spawnGroup;	
		//_InfGrp = [_zone_pos, west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Infantry" >> "USMC_InfSquad")] call BIS_fnc_spawnGroup;				
		//_InfGrp = [_zone_pos, west, (configFile >> "CfgGroups" >> "West" >> "CDF" >> "Infantry" >> "CDF_InfSquad")] call BIS_fnc_spawnGroup;				
	 	//_InfGrp = [_zone_pos, resistance, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Infantry" >> "GUE_InfSquad")] call BIS_fnc_spawnGroup;				
		//_InfGrp = [_zone_pos, civilian, (configFile >> "CfgGroups" >> "Civilian" >> "CIV" >> "Infantry" >> "CIV_Crowd")] call BIS_fnc_spawnGroup;							_UnitLeader = leader _InfGrp; 

		_UnitLeader = leader _InfGrp; 
		_list = ["CityCenter",[getMarkerPos _zone,_zone_size_y],true] call bis_fnc_locations;
			while {true} do {

					{
					sleep 0.02;
					_typeVar = _x getVariable "type";
					_neighbors = _x getVariable "neighbors";
					_name = _x getVariable "name";
					sleep 0.02;

					_wp1 =  _InfGrp addWaypoint [getpos _x, 0];
					[_InfGrp, 1] setWaypointBehaviour "COMBAT";
					[_InfGrp, 1] setWaypointSpeed "FULL";
					[_InfGrp, 1] setWaypointType "MOVE";
 						 waitUntil{currentWaypoint _InfGrp != 1};
  						sleep 0.2;
  						deleteWaypoint _wp1; 
			} forEach _list;
	};
		};  
	case "MOTO": {

		_search = createMarker ["_spawn1",getMarkerPos _zone];
		_search setMarkerType "Empty";
		_search setMarkerColor "Default";
		_search setMarkerSize [0.5, 0.5];
		sleep 0.001;
		_search setMarkerPos [(getMarkerPos _search select 0)+ Random _zone_size_x,(getMarkerPos _search select 1)- Random _zone_size_x];
		_zone_pos = getMarkerPos _search;			

		_MotoGrp = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "RU" >> "Motorized" >> "RU_MotInfSquad")] call BIS_fnc_spawnGroup;	
		//_MotoGrp = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "INS" >> "Motorized" >> "INS_MotInfSquad")] call BIS_fnc_spawnGroup;	
		//_MotoGrp = [_zone_pos, west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Motorized" >> "USMC_MotInfSection")] call BIS_fnc_spawnGroup;	
		//_MotoGrp = [_zone_pos, west, (configFile >> "CfgGroups" >> "West" >> "CDF" >> "Motorized" >> "CDF_MotInfSquad")] call BIS_fnc_spawnGroup;	
		//_MotoGrp = [_zone_pos, resistance, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Motorized" >> "GUE_MotInfSection")] call BIS_fnc_spawnGroup;				

		_UnitLeader = leader _MotoGrp; 
		_list = ["CityCenter",[getMarkerPos _zone,_zone_size_y],true] call bis_fnc_locations;
			while {true} do {

					{
					sleep 0.02;
					_typeVar = _x getVariable "type";
					_neighbors = _x getVariable "neighbors";
					_name = _x getVariable "name";
					sleep 0.02;

					_wp2 =  _MotoGrp addWaypoint [getpos _x, 0];
					[_MotoGrp, 1] setWaypointBehaviour "COMBAT";
					[_MotoGrp, 1] setWaypointSpeed "FULL";
					[_MotoGrp, 1] setWaypointType "MOVE";
 						 waitUntil{currentWaypoint _MotoGrp != 1};
  						sleep 0.2;
  						deleteWaypoint _wp2; 
			} forEach _list;
	};
		};
	case "MECH": {

		_search = createMarker ["_spawn2",getMarkerPos _zone];
		_search setMarkerType "Empty";
		_search setMarkerColor "Default";
		_search setMarkerSize [0.5, 0.5];
		sleep 0.001;
		_search setMarkerPos [(getMarkerPos _search select 0)+ Random _zone_size_x,(getMarkerPos _search select 1)- Random _zone_size_x];
		_zone_pos = getMarkerPos _search;	

		_MechGrp = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "RU" >> "Mechanized" >> "RU_MechInfSquad_1")] call BIS_fnc_spawnGroup;	
		//_MechGrp = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "INS" >> "Mechanized" >> "INS_MechInfSquad")] call BIS_fnc_spawnGroup;	
		//_MechGrp = [_zone_pos, west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Mechanized" >> "USMC_MechInfSquad")] call BIS_fnc_spawnGroup;	
		//_MechGrp = [_zone_pos, west, (configFile >> "CfgGroups" >> "West" >> "CDF" >> "Mechanized" >> "CDF_MechInfSquad")] call BIS_fnc_spawnGroup;	
		//_MechGrp = [_zone_pos, resistance, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Mechanized" >> "GUE_MechInfSection")] call BIS_fnc_spawnGroup;	

		_UnitLeader = leader _MechGrp; 
		_list = ["CityCenter",[getMarkerPos _zone,_zone_size_y],true] call bis_fnc_locations;
			while {true} do {

					{
					sleep 0.02;
					_typeVar = _x getVariable "type";
					_neighbors = _x getVariable "neighbors";
					_name = _x getVariable "name";
					sleep 0.02;

					_wp3 =  _MechGrp addWaypoint [getpos _x, 0];
					[_MechGrp, 1] setWaypointBehaviour "COMBAT";
					[_MechGrp, 1] setWaypointSpeed "FULL";
					[_MechGrp, 1] setWaypointType "MOVE";
 						 waitUntil{currentWaypoint _MechGrp != 1};
  						sleep 0.2;
  						deleteWaypoint _wp3; 
			} forEach _list;
	};
		}; 			

	case "TANK": {

		_search = createMarker ["_spawn3",getMarkerPos _zone];
		_search setMarkerType "Empty";
		_search setMarkerColor "Default";
		_search setMarkerSize [0.5, 0.5];
		sleep 0.001;
		_search setMarkerPos [(getMarkerPos _search select 0)+ Random _zone_size_x,(getMarkerPos _search select 1)- Random _zone_size_x];
		_zone_pos = getMarkerPos _search;

		_TankGrp = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "RU" >> "Armored" >> "RU_TankPlatoon")] call BIS_fnc_spawnGroup;	
		//_TankGrp = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "INS" >> "Armored" >> "INS_TankSection")] call BIS_fnc_spawnGroup;	
		//_TankGrp = [_zone_pos, west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Armored" >> "USMC_TankPlatoon")] call BIS_fnc_spawnGroup;	
		//_TankGrp = [_zone_pos, west, (configFile >> "CfgGroups" >> "West" >> "CDF" >> "Armored" >> "CDF_TankPlatoon")] call BIS_fnc_spawnGroup;	
		//_TankGrp = [_zone_pos, resistance, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Armored" >> "GUE_TankSection")] call BIS_fnc_spawnGroup;	

		_UnitLeader = leader _TankGrp; 
		_list = ["CityCenter",[getMarkerPos _zone,_zone_size_y],true] call bis_fnc_locations;
			while {true} do {

					{
					sleep 0.02;
					_typeVar = _x getVariable "type";
					_neighbors = _x getVariable "neighbors";
					_name = _x getVariable "name";
					sleep 0.02;

					_wp4 =  _TankGrp addWaypoint [getpos _x, 0];
					[_TankGrp, 1] setWaypointBehaviour "COMBAT";
					[_TankGrp, 1] setWaypointSpeed "FULL";
					[_TankGrp, 1] setWaypointType "MOVE";
 						 waitUntil{currentWaypoint _TankGrp != 1};
  						sleep 0.2;
  						deleteWaypoint _wp4; 
			} forEach _list;
	};
		}; 

	case "AIR": {

		_search = createMarker ["_spawn4",getMarkerPos _zone];
		_search setMarkerType "Empty";
		_search setMarkerColor "Default";
		_search setMarkerSize [0.5, 0.5];
		sleep 0.001;
		_search setMarkerPos [(getMarkerPos _search select 0)+ Random _zone_size_x,(getMarkerPos _search select 1)- Random _zone_size_x];
		_zone_pos = getMarkerPos _search;	

		_AirGrp = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "RU" >> "Air" >> "RU_Mi24VSquadron")] call BIS_fnc_spawnGroup;	
		//_AirGrp = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "INS" >> "Air" >> "INS_Mi8Squadron")] call BIS_fnc_spawnGroup;	
		//_AirGrp = [_zone_pos, west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Air" >> "USMC_UH1YSquadron")] call BIS_fnc_spawnGroup;	
		//_AirGrp = [_zone_pos, west, (configFile >> "CfgGroups" >> "West" >> "CDF" >> "Air" >> "CDF_Mi24DSquadron")] call BIS_fnc_spawnGroup;	

		_UnitLeader = leader _AirGrp; 
		_list = ["CityCenter",[getMarkerPos _zone,_zone_size_y],true] call bis_fnc_locations;
			while {true} do {

					{
					sleep 0.02;
					_typeVar = _x getVariable "type";
					_neighbors = _x getVariable "neighbors";
					_name = _x getVariable "name";
					sleep 0.02;

					_wp5 =  _AirGrp addWaypoint [getpos _x, 0];
					[_AirGrp, 1] setWaypointBehaviour "COMBAT";
					[_AirGrp, 1] setWaypointSpeed "FULL";
					[_AirGrp, 1] setWaypointType "MOVE";
 						 waitUntil{currentWaypoint _AirGrp != 1};
  						sleep 0.2;
  						deleteWaypoint _wp5; 
			} forEach _list;
	};
		}; 

	case "2GROUPS": {

		_search = createMarker ["_spawn5",getMarkerPos _zone];
		_search setMarkerType "Empty";
		_search setMarkerColor "Default";
		_search setMarkerSize [0.5, 0.5];
		sleep 0.001;
		_search setMarkerPos [(getMarkerPos _search select 0)+ Random _zone_size_x,(getMarkerPos _search select 1)- Random _zone_size_x];
		_zone_pos = getMarkerPos _search;				

		_Grp1 = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "RU" >> "Motorized" >> "RU_MotInfSquad")] call BIS_fnc_spawnGroup;
		sleep 1;
		_Grp2 = [_zone_pos, east, (configFile >> "CfgGroups" >> "East" >> "RU" >> "Infantry" >> "RU_InfSquad")] call BIS_fnc_spawnGroup; 

		_UnitLeader = leader _Grp1;						 
		_list = ["CityCenter",[getMarkerPos _zone,_zone_size_y],true] call bis_fnc_locations;
			while {true} do {

				{

				sleep 0.02;
				_typeVar = _x getVariable "type";
				_neighbors = _x getVariable "neighbors";
				_name = _x getVariable "name";
				sleep 0.02;

				_wp6 =  _Grp1 addWaypoint [getpos _x, 0];
				[_Grp1, 1] setWaypointBehaviour "COMBAT";
				[_Grp1, 1] setWaypointSpeed "FULL";
				[_Grp1, 1] setWaypointType "MOVE";

				_wp7 =  _Grp2 addWaypoint [getpos _x, 0];
				[_Grp2, 1] setWaypointBehaviour "COMBAT";
				[_Grp2, 1] setWaypointSpeed "FULL";
				[_Grp2, 1] setWaypointType "MOVE";

 					 waitUntil{
   				_cond1 =currentWaypoint _Grp1 != 1;
   				_cond2 =currentWaypoint _Grp2 != 0;
  	   				_cond1 && _cond2
    	   				};
  					sleep 0.2;
  					deleteWaypoint _wp6;
  					deleteWaypoint _wp7; 
			} forEach _list;
		};			
	};
	};
};
Sleep 0.1;

Or this is the link to a newer version that supports ACE with a demo mission

http://www.armaholic.com/page.php?id=10292

Hope that helps.

Odin

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  

×