Jump to content
Sign in to follow this  
hogmason

random house pos in certain distance for spawned units

Recommended Posts

hey im trying to set a random house position within 300 meters of said marker for my units that i spawn i could work it out if i wasnt using

  for "_i" from 0 to 30 do 
       {

        };

but that loop just throws me out of my comfort zone.

any way this is my spawn units code

_rebelArray = [];

  for "_i" from 0 to 30 do 
       {
        _random = floor(random 6);
        _spawn = getMarkerPos "E_Patrol";
        _group = floor(random 8);




   switch (_group) do
   	{
        case 0: {_units = ["TK_INS_Soldier_Sniper_EP1"];};
        case 1: {_units = ["TK_INS_Soldier_AT_EP1"];};
        case 2: {_units = ["TK_INS_Soldier_MG_EP1"];};
        case 3: {_units = ["TK_INS_Soldier_AA_EP1"];};	
        case 4: {_units = ["TK_INS_Soldier_Sniper_EP1"];};
        case 5: {_units = ["TK_INS_Soldier_TL_EP1"];};
        case 6: {_units = ["TK_INS_Soldier_4_EP1"];};
        case 7: {_units = ["TK_INS_Bonesetter_EP1"];};			 
       };


       [color="#FF0000"]_spawngroup = [getMarkerPos "E_Patrol", EAST, _units, [],[],[],[],[1,1]] call BIS_fnc_spawnGroup;[/color]

       // Add the created group to an array of groups so we can reference them later
       _rebelArray set[(count _rebelArray), _spawngroup];
       //[_spawngroup,300,3] execVM "missions\scripts\pow_positions.sqf"; 
       [leader _spawngroup,"E_Patrol","spawned","nowait","nofollow","nomove"] execVM "scripts\upsmon.sqf"; //"randomup" 

       };


and this is the code im trying to implement

_rebelArray = [];

  for "_i" from 0 to 30 do 
       {
        _random = floor(random 6);
        _spawn = getMarkerPos "E_Patrol";
        _group = floor(random 8);




   switch (_group) do
   	{
        case 0: {_units = ["TK_INS_Soldier_Sniper_EP1"];};
        case 1: {_units = ["TK_INS_Soldier_AT_EP1"];};
        case 2: {_units = ["TK_INS_Soldier_MG_EP1"];};
        case 3: {_units = ["TK_INS_Soldier_AA_EP1"];};	
        case 4: {_units = ["TK_INS_Soldier_Sniper_EP1"];};
        case 5: {_units = ["TK_INS_Soldier_TL_EP1"];};
        case 6: {_units = ["TK_INS_Soldier_4_EP1"];};
        case 7: {_units = ["TK_INS_Bonesetter_EP1"];};			 
       };


       _spawngroup = [getMarkerPos "E_Patrol", EAST, _units, [],[],[],[],[1,1]] call BIS_fnc_spawnGroup;


[color="#FF0000"]        _radius = 300;
       _minBuildingPos = 5;
       _randomPos = [(getpos _spawngroup select 0) + _radius*0.5 - (random _radius), (getpos _spawngroup select 1) + _radius*0.5 - (random _radius), 0];
       _houseArray = nearestObjects [_randomPos, ["House"], _radius];
       sleep 1;
       _houseNumber = count _houseArray;
	_x = 0;
	while {_x <= _houseNumber} do
        {
          _house = _houseArray select _x;
          waitUntil {! isNil "_house"};
          if (format ["%1", _house buildingPos _minBuildingPos] != "[0,0,0]") exitWith {_y = 0; while { format ["%1", _house buildingPos _y] != "[0,0,0]" } do {_y = _y + 1}; _y = _y - 1; _obj setPos (_house buildingpos (ceil random _y));};
          _x = _x +1;
          sleep 0.1;
        };[/color]

       // Add the created group to an array of groups so we can reference them later
       _rebelArray set[(count _rebelArray), _spawngroup];
       //[_spawngroup,300,3] execVM "missions\scripts\pow_positions.sqf"; 
       [leader _spawngroup,"E_Patrol","spawned","nowait","nofollow","nomove"] execVM "scripts\upsmon.sqf"; //"randomup" 

       };


got me beat any ideas.

even if i could have it as a seperate sqf i.e

private ["_obj","_radius","_minBuildingPos","_randomPos","_houseArray","_houseNumber","_x","_house","_y"];

_obj = _this select 0;
_radius = _this select 1;
_minBuildingPos = _this select 2;
_randomPos = [(getpos _obj select 0) + _radius*0.5 - (random _radius), (getpos _obj select 1) + _radius*0.5 - (random _radius), 0];
_houseArray = nearestObjects [_randomPos, ["House"], _radius];

sleep 1;

_houseNumber = count _houseArray;

_x = 0;

while {_x <= _houseNumber} do
{
_house = _houseArray select _x;
waitUntil {! isNil "_house"};
if (format ["%1", _house buildingPos _minBuildingPos] != "[0,0,0]") exitWith {_y = 0; while { format ["%1", _house buildingPos _y] != "[0,0,0]" } do {_y = _y + 1}; _y = _y - 1; _obj setPos (_house buildingpos (ceil random _y));};
_x = _x +1;
sleep 0.1;
};


and some how call it from inside the spawn loop

i.e

_spawngroup = [getMarkerPos "E_Patrol", EAST, _units, [],[],[],[],[1,1]] call BIS_fnc_spawnGroup;
[_spawngroup ,300,3] execVM "missions\scripts\pow_positions.sqf";

i know that will not work as is becouse the _spawngroup is a group not an object i.e a specific unit but as i used the spawn loop i have no idea how to use a single unit to call the code. lol i dont even know if thats correct but thats my limit of knowledge lol ;)

Share this post


Link to post
Share on other sites

This might help, I use it all the time to put guys in buildings

example :

//spawn group
_grpbuild1 = [getmarkerpos "xx", RESISTANCE, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Infantry" >> "GUE_InfSquad")] call BIS_fnc_spawnGroup;

//Place in buildings
_grpbuild1 execVM "PlaceInBuilding.sqf";

That will then place them in random Buildings you can change the _check_distance to what you like

PlaceInBuilding.sqf

/*
================================================== ========================
Place infantry groups in buildings script

Place group leader near building of choice, then:
syntax for scripts:
group execVM "PlaceInBuilding.sqf"

syntax for init field for the leader of the desired group:
_script = group this execVM "PlaceInBuilding.sqf"

Extra info:
- Removes hand grenades, otherwise dumb infantry try and throw a grenade from inside a building and frag themselves
- Will delete group if no building position is found
- Buildings id being searched near group leader's position
- All members of the group are each joined into another newly created groups to prevent them from getting back into formation
- You can change _check_distance variable to change search distance for entrable buildings
================================================== ========================
================================================== ========================
*/
if (isServer) then
{	
_mode = ["YELLOW", "RED"] call BIS_fnc_selectRandom;
_grp setBehaviour "AWARE";
_grp setCombatMode _mode;

};

_group = _this;

_leader = leader _group;

_check_distance = 100; // Change this to tweak building searching distance

_arr_buildings = nearestObjects [_leader, ["HOUSE"], _check_distance];
_buildingcount = count _buildings;

_arr_positions = [];
{
_i = 0;
_positions_checked = FALSE;
while {not _positions_checked} do {
_position = _x buildingPos _i;
_coord_x = _position select 0;
_coord_y = _position select 1;
_coord_z = _position select 2;
_coord_sum = _coord_x + _coord_y + _coord_z;
if (_coord_sum == 0) then {
_positions_checked = TRUE;
} else {
_arr_positions = _arr_positions + [_position];
_i = _i + 1;
};
};
} foreach _arr_buildings;

{
_newgroup = createGroup side _leader;

[_x] join _newgroup;

if (count _arr_positions == 0) then {
deleteVehicle _x;
};

_position = _arr_positions select random count _arr_positions;

_x setPos _position;
_x setDir random 360;

_x removeWeapon "HandGrenade_East"; _x removeMagazines "HandGrenade_East";
_x removeWeapon "HandGrenade_West"; _x removeMagazines "HandGrenade_West";
_x removeWeapon "HandGrenade"; _x removeMagazines "HandGrenade";
_x setUnitPos "UP";
} foreach units _group;

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  

×