Jump to content
Sign in to follow this  
J. Schmidt

Generate Objective in Random Position

Recommended Posts

I've been working on this script for a good 8 hours (including searching the web and BI forums) to create an objective in a random position using the "selectBestPlaces" command. I've been able to get a marker to show up (most of the time not in the same spot) :cool:, unfortunately I haven't been able to get the group to spawn. :confused: If anyone can help me with this it'll be greatly appreciated.

Here is what I have so far for the script, and I would like to use either "BIS_taskPatrol.sqf" or "BIN_taskPatrol.sqf" so the group will patrol the area they spawn at. In the long run I would like to create several types of side and main mission scripts using what I have so far. (I've already looked into shk_Pos and may use that if I can get my friends to agree to this as well. But they've insisted on trying to create a script system ourselves.)

Test.sqf

private ["_centerPos", "_bestPlace", "_pos01", "_pos02", "_mrkr01", "_US_INF_groups"];
_centerPos = getArray (configFile >> "cfgWorlds" >> worldName >> "centerPosition");
_bestPlace = selectBestPlaces [_centerPos, 5000, "(1 - forest) * (0.5 + trees) * (0.75 + meadow) * (0.75 + houses)", 10, 1];
_rndPos = _bestplace select 0;
_objPos = _rndPos select 0;

_mrkr01 = createMarker ["mrkr01", _objPos];
"mrkr01" setMarkerShape "ICON";
"mrkr01" setMarkerType "b_inf";

_US_INF_groups = ["US_Team", "US_TeamMG", "US_TeamAT", "US_TeamSupport", "US_SniperTeam"];
_grp1 = [_mrkr01, West, (configFile >> "CfgGroups" >> "West" >> "BIS_US" >> "Infantry" >> (_US_INF_groups select (floor(random(count _US_INF_groups)))))] call BIS_fnc_spawnGroup;

Edited by JSF 82nd Reaper

Share this post


Link to post
Share on other sites

Place an ammo box on the map and name it box1

Place 9 markers on the map

Group the markers with the box

Every time the mission starts, the box will start either in it’s original position or on one of the markers.

ie: it will start at one of 10 places at random

Use 19 markers and you get 20 places at random

Name yourself blue 1. In your init: blue1 setPos (getPos box1)

Every time the mission starts your character starts on the box.

To position other members adjacent to an object

= = = = = = = = = = = = = = = = = = = = = = = = =

You don’t want all your team starting on the box. You need to position them to the left or right of the box and in front of or behind the box

In this example soldier blue2 starts 20 meters from a box named box1

blue2 setPos [(getPos box1 select 0) +20, (getPos box1 select 1) +10, (getPos box1 select 2) +0];

+20 = right side

-20 = left side

+10 = in front of

-10 = behind

Using this formula the soldier is positioned 20 meters to the right of the box and 10 meters in front of the box.

In this way you can position every man in the squad relative to the box.

Once you have learnt this works, change the box for a small object. Small objects can be hard to see and when the mission starts you will not notice it.

Edited by Joe98

Share this post


Link to post
Share on other sites

Could the ammo box be a Game Logic so it is entirely invisible?

Also how do you "synch" an item to a marker? Dragging a synch line from an object to a marker does nothing.

Edited by eegore

Share this post


Link to post
Share on other sites

Oops I meant "group" instead of "synch". I have now edited the post above.

I am not familiar with Game Logic. I have used very small objects. In grass they are invisible and on a hard surface you would not notice unless you looked for it.

Share this post


Link to post
Share on other sites

@Joe98 Thanks for the information, that may become handy once I get to the spawning of objects, vehicles, fortifications, crates, and etc. I was finally able to get the script to work with spawning AI, now I'm just testing "BIN_taskPatrol.sqf" out.

test.sqf

private ["_centerPos", "_bestPlace", "_objPos01", "_objPos02", "_mrkr01", "_markerPos", "_US_INF_groups", "_grp01"];
_centerPos = getArray (configFile >> "cfgWorlds" >> worldName >> "centerPosition");
_bestPlace = selectBestPlaces [_centerPos, 5000, "(1 - forest) * (0.5 + trees) * (0.5 + meadow) * (0.5 + houses)", 10, 1];
_objPos01 = _bestPlace select 0;
_objPos02 = _objPos01 select 0;

_mrkr01 = createMarker ["mrkr01", _objPos02];
"mrkr01" setMarkerShape "ICON";
"mrkr01" setMarkerType "b_inf";

_markerPos = getMarkerPos "mrkr01";
_US_INF_groups = ["US_Team", "US_TeamMG", "US_TeamAT", "US_TeamSupport"];
_grp01 = [_markerPos, West, (configFile >> "CfgGroups" >> "West" >> "BIS_US" >> "Infantry" >> (_US_INF_groups select (floor(random(count _US_INF_groups)))))] call BIS_fnc_spawnGroup;
null = [_grp01, (_markerPos), 75, 1] execVM "scripts\BIN_taskPatrol.sqf";

Edited by JSF 82nd Reaper

Share this post


Link to post
Share on other sites

Ahh yeah Grouping works great.

For the OP I have used the Urban Patrol Script (UPS) to get spawned units to run patrols with various parameters.

This is the code given to me, you will of course have to modify it slightly, maybe where you have "execVM "scripts\BIN_taskPatrol.sqf"; you can replace it with:

execVM 'ups.sqf'",0.2,"SERGEANT"];

_spawnPos = getMarkerPos "marker_1";
_group = createGroup West;
"Goat" createUnit [(_spawnPos), _group, "",0.1,"PRIVATE"];
"Goat" createUnit [(_spawnPos), _group, "",0.1,"PRIVATE"];
"Goat" createUnit [(_spawnPos), _group, "nul = [this, 'marker_1','nofollow'] execVM 'ups.sqf'",0.2,"SERGEANT"];

Share this post


Link to post
Share on other sites

@eegore I was able to get the BIN_taskPatrol.sqf to work, thanks for looking though. Now I just have to start scripting objects, vehicles, fortifications, and etc within what I have so far. I'm just a little burnt out right now, but in the next couple of days I should have more in the script along with more "Trial & Error".

Share this post


Link to post
Share on other sites

nul=[group this, position this, number] call BIS_fnc_taskPatrol;

https://community.bistudio.com/wiki/BIS_fnc_taskPatrol

If use SHK_pos for random spawn;"examples"

// SELECT RANDOM STATIC
_static = [
"M2StaticMG","DSHKM_CDF","ZU23_CDF"
] call BIS_fnc_selectRandom;
_ran_post = [ (getmarkerPos "area1"), random 300, random 359, true, [0, 0]] call SHK_pos;	
_position = "HeliHEmpty" createVehicle (_ran_post);  
_static_spawn = [(getpos _position), (getdir _position), (_static), west] call BIS_fnc_spawnVehicle;

// SELECT RANDOM VEHICLE
_vehicle = [
"AAV","LAV25","M1A1","HMMWV_M2","HMMWV_MK19","HMMWV_TOW","BMP2_CDF","BRDM2_CDF","BRDM2_ATGM_CDF",
"M1A2_TUSK_MG"
] call BIS_fnc_selectRandom;
_ran_post = [ (getmarkerPos "area1"), 300, random 359, true, [1, 300]] call SHK_pos;	
_position = "HeliHEmpty" createVehicle (_ran_post);  
_veh_patrol_1 = [(getpos _position), (getdir _position), (_vehicle), west] call BIS_fnc_spawnVehicle;
ran_veh_ups_1 = _veh_patrol_1 select 0;
ran_veh_ups_1 setVehicleInit "nul = [this, 'area1','nofollow','delete:',500] execVM 'Initialization\ups.sqf'";
processInitCommands;

* ran_veh_ups_1 is ur vehicle name.

// NORMAL PATROL 
_patrolgrp = [(getmarkerPos "area2"),west,[
"USMC_Soldier_SL","USMC_Soldier_TL","USMC_Soldier_HAT","USMC_Soldier_AT","USMC_Soldier_AR","USMC_Soldier_Medic","USMC_Soldier_GL","USMC_Soldier_MG",
"USMC_Soldier","USMC_Soldier2","USMC_Soldier_LAT","USMC_SoldierS_Sniper","USMC_SoldierS","USMC_SoldierS_SniperH","FR_Assault_GL",
"FR_Assault_R","FR_Cooper","FR_Corpsman","FR_Sapper","FR_AC","FR_AR","FR_Marksman"],[],[],[],[],[2,0.2]] call bis_fnc_spawngroup;
[leader _patrolgrp,"area2","nofollow","delete:",500] execVM "Initialization\ups.sqf";

* [2,0.2] in normal patrol means 100% spawn 2 first units in array which are squad leader and team leader and 20% chance to spawn rest units in same group.This give u a random units in groups.

*Change classnames for others factions.

Edited by Persian MO

Share this post


Link to post
Share on other sites

@Persian MO Wow, those are some impressive examples, if I use SHK_pos can it generate a random marker somewhere on the map, which then spawns patrols and etc at that marker? If not am I able to use the script that I've started work on to generate random markers, which then SHK_pos can use? I'm trying create a mission system in which I don't have to put any markers on the map, and if it's currently impossible then I'll go ahead and use markers.

Share this post


Link to post
Share on other sites

About find a position on map and put a marker,

- Put a game logic in map center.Name it: Centertown

Select a random positions on hills !

//gamelogic in center map
_gamelogic = centertown;
// collect all hills in map
_towns = nearestLocations [getPosATL _gamelogic, ["Hill"], 25000]; 
// select a random hill
_RandomTownPosition = position (_towns select (floor (random (count _towns)))); 
// create a marker at hill
_marker = createMarker ["marker_1", _RandomTownPosition];
_marker setMarkerType "hd_destroy";
_marker setMarkerColor "ColorRed";
_marker setMarkerText " my random pos";
_marker setMarkerSize [1,1];

Select a random positions at towns !

_gamelogic = centertown;
_towns = nearestLocations [getPosATL _gamelogic, ["NameVillage","NameCity","NameCityCapital"], 25000]; 
_RandomTownPosition = position (_towns select (floor (random (count _towns)))); 

https://community.bistudio.com/wiki/ArmA_2:_CfgLocationTypes

Edited by Persian MO

Share this post


Link to post
Share on other sites

@Persian MO Thanks for the post, that's 10 times easier then what I was trying to do. Do you know if I would be able to combine the script I have above to select a position that'll spawn the gamelogic via script if I take out the "bestPlace"?

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  

×