Jump to content
  • 0

[HELP] Random Building placer


Phyrstorm

Question

I am working on a script that will on server start randomly place (from an array of options) several buildings on the map.  I am currently testing with a few buildings on the southern coast of Chernarus and they themselves will spawn from the normal sqf file but when I try to take their classnames, coords, and setdir and put them into an array I can't seem to call them properly.  Any assistance would be appreciated.  The code I have so far and the error I am getting in my rpt file are below.

 

 

Code

/*
    Random Building Spawn for Chernarus - By Phyrstorm
    Usage [building,coords,dir]
    Building is the Building class name
    Coords are the coords from your custom mission file
    direction is the setDir from your mission file
*/

private ["_building","_coords","_dir","_count","_buildarray"];

if (!isServer) exitWith {};

_building = "Land_Mil_Barracks_i";
_coords = [3363.9216, 2167.3716, 2.3841858e-006];
_dir = -132.08899;
_count = 3;
//_buildarray usage [building,coords,dir]

_buildarray = [
    ["Land_Mil_Barracks_i",[3363.9216, 2167.3716, 2.3841858e-006],-132.08899],
    ["Land_Mil_Barracks_i",[3370.8013, 2173.6431, 6.1988831e-006],-132.08899],
    ["Land_Mil_Barracks_i",[3377.9146, 2180.3911, 9.5367432e-007],-132.08899],
    ["Land_Mil_Barracks_i",[3385.0901, 2186.7957, 6.6757202e-006],-132.08899],
    ["Land_Mil_Barracks_i",[3392.9038, 2194.2275, 6.1988831e-006],-132.08899],
    ["Land_Mil_Barracks_i",[3400.0671, 2200.752, 4.2915344e-006],-132.08899]
];

for "_x" from 1 to _count do {
    
    _buildrand = _buildarray call BIS_fuc_selectRandom;
    _buildarray = _buildarray - _buildrand;
    _building = _buildrand select 0;
    _coords = _buildrand select 1;
    _dir = _buildrand select 2;
    
    _vehicle = objNull;
    if (true) then
    {
    _this = createVehicle [_building, _coords, [], 0, "CAN_COLLIDE"];
    _vehicle = _this;
    _this setDir _dir;
    _this setPos _coords;
    };
    diag_log text format ["%1 spawned at %2 facing %3.",_building,_coords,_dir];
};

 

RPT grab

23:59:30 Error in expression <cle = objNull;if (true) then
{
_this = createVehicle [_building, _coords, [], 0>
23:59:30 Error position: <createVehicle [_building, _coords, [], 0>
23:59:30 Error Type Any, expected String
23:59:30 File mpmissions\DayZ_OverPoch_1.Chernarus\buildings\randtest.sqf, line 39
23:59:30 any spawned at any facing any.
23:59:30 Error in expression <cle = objNull;
if (true) then
{
_this = createVehicle [_building, _coords, [], 0>
23:59:30 Error position: <createVehicle [_building, _coords, [], 0>
23:59:30 Error Type Any, expected String
23:59:30 File mpmissions\DayZ_OverPoch_1.Chernarus\buildings\randtest.sqf, line 39
23:59:30 any spawned at any facing any.
23:59:30 Error in expression <cle = objNull;
if (true) then
{
_this = createVehicle [_building, _coords, [], 0>
23:59:30 Error position: <createVehicle [_building, _coords, [], 0>
23:59:30 Error Type Any, expected String
23:59:30 File mpmissions\DayZ_OverPoch_1.Chernarus\buildings\randtest.sqf, line 39
23:59:30 any spawned at any facing any.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

If you create each one as it's own .sqf file then this will work, it will select between 1 and X scripts and load up a random number of them.

 

Full credit goes to Axe Cop for the code :)

private ["_bases","_baseCount","_base"];

// list of possible base scripts
_bases = ["Base_1.sqf","Base_2.sqf","Base_3.sqf"];

// how many do you want, can also be a static number of course
_baseCount = floor (random (count _bases)); // will be a random number between 0 and the the amount of base scripts in the list above
// if you want at least 1 or 2 change it to this maybe
// _baseCount = 1 + floor (random ((count _bases) - 1)); // at least 1 base will be chosen

// repeat for _baseCount times
for "_i" from 1 to _baseCount do {
    // chose one at random and remove it from the bases list (so it won't be chosen twice)
    _base = _bases call BIS_fnc_selectRandom;
    _bases = _bases - [_base];
    // execute the script
    execVM _base;
};
Link to comment
Share on other sites

  • 0

I've actually got something like that setup already for small locations with 2 barracks and a guard house.  I have that one setup to only choose a single file.  Each file has 5 or 6 locations in it on the map.  I just didn't want to have to make 40+ individual file for single barracks locations.

 

 

 

_buildlist = ["random1.sqf","random2.sqf","random3.sqf","random4.sqf","random5.sqf","random6.sqf","random7.sqf","random8.sqf","random9.sqf]; // Random Custom buildings
_randbuild = _buildlist select floor(random(count _buildlist)); // Random Custom buildings
[] execVM format ["buildings\random\%1",_randbuild]; // Random Custom buildings

EDIT:

 

I've got it close to working now.  I am just getting a Cannot create non-ai vehicle error now.  If I spawn the buildings normally through the mission file they load so I have no idea why it won't come up now.

/*
Random Building Spawn for Chernarus - By Phyrstorm
Usage [building,coords,dir]
Building is the Building class name
Coords are the coords from your custom mission file
direction is the setDir from your mission file
*/

private ["_building","_coords","_dir","_count","_buildarray"];

if (!isServer) exitWith {};

_building = "Land_Mil_Barracks_i";
_coords = [3363.9216, 2167.3716, 2.3841858e-006];
_dir = -132.08899;
_count = 3;
//_buildarray usage [building,coords,dir]

_buildarray = [
["""Land_Mil_Barracks_i""","[3363.9216, 2167.3716, 2.3841858e-006]","-132.08899"],
["""Land_Mil_Barracks_i""","[3370.8013, 2173.6431, 6.1988831e-006]","-132.08899"],
["""Land_Mil_Barracks_i""","[3377.9146, 2180.3911, 9.5367432e-007]","-132.08899"],
["""Land_Mil_Barracks_i""","[3385.0901, 2186.7957, 6.6757202e-006]","-132.08899"],
["""Land_Mil_Barracks_i""","[3392.9038, 2194.2275, 6.1988831e-006]","-132.08899"],
["""Land_Mil_Barracks_i""","[3400.0671, 2200.752, 4.2915344e-006]","-132.08899"]
];

for "_x" from 1 to _count do {

_randcount = floor (random (count _buildarray));
diag_log format ["%1",_randcount];
_buildrand = _buildarray select _randcount;
diag_log format ["%1",_buildrand];
_building = _buildrand select 0;
diag_log format ["%1",_building];
_coords = _buildrand select 1;
diag_log format ["%1",_coords];
_dirs = _buildrand select 2;
diag_log format ["%1",_dirs];
_dir = parseNumber _dirs;
diag_log format ["%1",_dir];
_buildarray set [_randcount,-1];
diag_log format ["%1",_buildarray];
_buildarray = _buildarray - [-1];
diag_log format ["%1",_buildarray];

_vehicle_1 = objNull;
if (true) then
{
_this = createVehicle [_building, getMarkerPos _coords, [], 0, "CAN_COLLIDE"];
_vehicle_1 = _this;
_this setDir _dir;
_this setPos getMarkerPos _coords;
};
diag_log format ["%1, %2, %3, %4, %5",_buildrand,_buildarray,_building,_coords,_dir];
diag_log text format ["%1 spawned at %2 facing %3.",_building,_coords,_dir];
};

RPT file with debug logs.

11:46:36 "3"
11:46:36 "[""Land_Mil_Barracks_i"","[3385.0901, 2186.7957, 6.6757202e-006]","-132.08899"]"
11:46:36 ""Land_Mil_Barracks_i""
11:46:36 "[3385.0901, 2186.7957, 6.6757202e-006]"
11:46:36 "-132.08899"
11:46:36 "-132.089"
11:46:36 "[[""Land_Mil_Barracks_i"","[3363.9216, 2167.3716, 2.3841858e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3370.8013, 2173.6431, 6.1988831e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3377.9146, 2180.3911, 9.5367432e-007]","-132.08899"],-1,[""Land_Mil_Barracks_i"","[3392.9038, 2194.2275, 6.1988831e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3400.0671, 2200.752, 4.2915344e-006]","-132.08899"]]"
11:46:36 "[[""Land_Mil_Barracks_i"","[3363.9216, 2167.3716, 2.3841858e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3370.8013, 2173.6431, 6.1988831e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3377.9146, 2180.3911, 9.5367432e-007]","-132.08899"],[""Land_Mil_Barracks_i"","[3392.9038, 2194.2275, 6.1988831e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3400.0671, 2200.752, 4.2915344e-006]","-132.08899"]]"
11:46:36 Cannot create non-ai vehicle "Land_Mil_Barracks_i",
11:46:36 "[""Land_Mil_Barracks_i"","[3385.0901, 2186.7957, 6.6757202e-006]","-132.08899"], [[""Land_Mil_Barracks_i"","[3363.9216, 2167.3716, 2.3841858e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3370.8013, 2173.6431, 6.1988831e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3377.9146, 2180.3911, 9.5367432e-007]","-132.08899"],[""Land_Mil_Barracks_i"","[3392.9038, 2194.2275, 6.1988831e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3400.0671, 2200.752, 4.2915344e-006]","-132.08899"]], "Land_Mil_Barracks_i", [3385.0901, 2186.7957, 6.6757202e-006], -132.089"
11:46:36 "Land_Mil_Barracks_i" spawned at [3385.0901, 2186.7957, 6.6757202e-006] facing -132.089.
11:46:36 "2"
11:46:36 "[""Land_Mil_Barracks_i"","[3377.9146, 2180.3911, 9.5367432e-007]","-132.08899"]"
11:46:36 ""Land_Mil_Barracks_i""
11:46:36 "[3377.9146, 2180.3911, 9.5367432e-007]"
11:46:36 "-132.08899"
11:46:36 "-132.089"
11:46:36 "[[""Land_Mil_Barracks_i"","[3363.9216, 2167.3716, 2.3841858e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3370.8013, 2173.6431, 6.1988831e-006]","-132.08899"],-1,[""Land_Mil_Barracks_i"","[3392.9038, 2194.2275, 6.1988831e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3400.0671, 2200.752, 4.2915344e-006]","-132.08899"]]"
11:46:36 "[[""Land_Mil_Barracks_i"","[3363.9216, 2167.3716, 2.3841858e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3370.8013, 2173.6431, 6.1988831e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3392.9038, 2194.2275, 6.1988831e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3400.0671, 2200.752, 4.2915344e-006]","-132.08899"]]"
11:46:36 Cannot create non-ai vehicle "Land_Mil_Barracks_i",
11:46:36 "[""Land_Mil_Barracks_i"","[3377.9146, 2180.3911, 9.5367432e-007]","-132.08899"], [[""Land_Mil_Barracks_i"","[3363.9216, 2167.3716, 2.3841858e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3370.8013, 2173.6431, 6.1988831e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3392.9038, 2194.2275, 6.1988831e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3400.0671, 2200.752, 4.2915344e-006]","-132.08899"]], "Land_Mil_Barracks_i", [3377.9146, 2180.3911, 9.5367432e-007], -132.089"
11:46:36 "Land_Mil_Barracks_i" spawned at [3377.9146, 2180.3911, 9.5367432e-007] facing -132.089.
11:46:36 "2"
11:46:36 "[""Land_Mil_Barracks_i"","[3392.9038, 2194.2275, 6.1988831e-006]","-132.08899"]"
11:46:36 ""Land_Mil_Barracks_i""
11:46:36 "[3392.9038, 2194.2275, 6.1988831e-006]"
11:46:36 "-132.08899"
11:46:36 "-132.089"
11:46:36 "[[""Land_Mil_Barracks_i"","[3363.9216, 2167.3716, 2.3841858e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3370.8013, 2173.6431, 6.1988831e-006]","-132.08899"],-1,[""Land_Mil_Barracks_i"","[3400.0671, 2200.752, 4.2915344e-006]","-132.08899"]]"
11:46:36 "[[""Land_Mil_Barracks_i"","[3363.9216, 2167.3716, 2.3841858e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3370.8013, 2173.6431, 6.1988831e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3400.0671, 2200.752, 4.2915344e-006]","-132.08899"]]"
11:46:36 Cannot create non-ai vehicle "Land_Mil_Barracks_i",
11:46:36 "[""Land_Mil_Barracks_i"","[3392.9038, 2194.2275, 6.1988831e-006]","-132.08899"], [[""Land_Mil_Barracks_i"","[3363.9216, 2167.3716, 2.3841858e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3370.8013, 2173.6431, 6.1988831e-006]","-132.08899"],[""Land_Mil_Barracks_i"","[3400.0671, 2200.752, 4.2915344e-006]","-132.08899"]], "Land_Mil_Barracks_i", [3392.9038, 2194.2275, 6.1988831e-006], -132.089"
11:46:36 "Land_Mil_Barracks_i" spawned at [3392.9038, 2194.2275, 6.1988831e-006] facing -132.089.

Edited by Phyrstorm
Link to comment
Share on other sites

  • 0

Here is the working code.  thanks to some help from SchwEde on opendayz.net.

/*
	Random Building Spawn for Chernarus - By Phyrstorm
	Usage [building,coords,dir]
	Building is the Building class name
	Position are the coords from your custom mission file
	direction is the setDir from your mission file
*/

private ["_building","_position","_dir","_count","_buildarray"];

if (!isServer) exitWith {};

_building = [];
_coords = [];
_dir = [];
_count = 3;
//_buildarray usage [building,position,dir]

_buildarray = [
	["Land_Mil_Barracks_i",[3363.9216, 2167.3716, 2.3841858e-006],-132.08899],
	["Land_Mil_Barracks_i",[3370.8013, 2173.6431, 6.1988831e-006],-132.08899],
	["Land_Mil_Barracks_i",[3377.9146, 2180.3911, 9.5367432e-007],-132.08899],
	["Land_Mil_Barracks_i",[3385.0901, 2186.7957, 6.6757202e-006],-132.08899],
	["Land_Mil_Barracks_i",[3392.9038, 2194.2275, 6.1988831e-006],-132.08899],
	["Land_Mil_Barracks_i",[3400.0671, 2200.752, 4.2915344e-006],-132.08899]
];

for "_x" from 1 to _count do {

	_randcount = floor (random (count _buildarray));
	//diag_log format ["%1",_randcount];
	_buildrand = _buildarray select _randcount;
	//diag_log format ["%1",_buildrand];
	_building = _buildrand select 0;
	//diag_log format ["%1",_building];
	_position = _buildrand select 1;
	//diag_log format ["%1",_position];
	_dir = _buildrand select 2;
	//diag_log format ["%1",_dir];
	_buildarray set [_randcount,-1];
	//diag_log format ["%1",_buildarray];
	_buildarray = _buildarray - [-1];
	//diag_log format ["%1",_buildarray];

	_vehicle_1 = objNull;
	if (true) then
	{
		_this = createVehicle [_building, _position, [], 0, "CAN_COLLIDE"];
		_vehicle_1 = _this;
		_this setDir _dir;
		_this setPos _position;
	};

	diag_log text format ["%1 spawned at %2 facing %3.",_building,_position,_dir];
};

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...