Jump to content
Sign in to follow this  
Phyrstorm

Random Building placer

Recommended Posts

I am working on a random barracks placer for Dayz and I have most of the code working but when I run it on my test server I get a "Cannot create non-ai vehicle "Land_Mil_Barracks_i"" error in my RPT file. With the diag_log lines I have in the the script for debugging I can see in the RPT file that all of the variables are getting pulled from the array the way I want them to but the createVehicle array seems not to want to use them. the array is setup just like it is in the mission.sqf file from the editor and they will spawn in from that file without issue. Below Is the code I put together and the section from the RPT file pertaining to the buildings trying to be spawned in.

The sqf 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 {

_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];
};

The RPT file.

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.

Share this post


Link to post
Share on other sites

Just for anyones refrence I was overthinking the code and got it working finally after working with someone 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];
};

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  

×