austin_medic 109 Posted January 30, 2015 (edited) Been continuning to attempt to work on procedural object generation, but its starting to turn into a ton of bugs. My main problems now are the fact that doorways should only delete two blocks up the wall, but it deletes that whole section of wall. -- now fixed Another issue is that the buildings are clipping inside each other and I've tried about every possible way I can think of to fix it. In Init.sqf I have this: _oldpos = [0,0,0]; ["Land_VR_CoverObject_01_stand_f",getpos player,200] execVM "proced_gen_cover.sqf"; //generate random blocks everywhere for "_i" from 0 to 25 do { _Pos = [(getpos player select 0) + random 200 - random 200,(getpos player select 1) + random 200 - random 200,(getpos player select 2)]; if(_oldPos distance _Pos < 150) then { for "_i" from 0 to 50 do { _Pos = [(getpos player select 0) + random 200 - random 200,(getpos player select 1) + random 200 - random 200,(getpos player select 2)]; }; }; [_pos,"Land_VR_CoverObject_01_stand_f"] execVM "proced_gen_building.sqf"; sleep 1; //_pos = [_pos,150 + round(random 150),random 360] call BIS_fnc_relPos; - what was I thinking here? _pos = _oldPos; }; The script then calls the object builder script: _position = _this select 0; _type = _This select 1; _dir = 0; //server does randomize, sends results to clients so they can build objects themselves //if(isServer) then //{ _randomizePerim = 10 + round(random 10); _randomizeHigh = 5 + round(random 6); // publicVariable "randomizePerim"; // publicVariable "randomizeHigh"; //}; //waitUntil{!isNul "randomizePerim" & !isNul "randomizeHigh"}; _allSides = 0; _allObjects = []; _centerObj = _type createVehicle _position; _newObj = _centerObj; while{_allSides < 4} do { if(_allSides == 1) then { _dir = 90; }; if(_allSides == 2) then { _dir = 180; }; if(_allSides == 3) then { _dir = 270; }; if(_allSides == 4) then { _dir = 360; }; _i = 0; for "_i" from 0 to _randomizePerim do { if(_i == 1) then { _newPos = [_centerObj,1,_dir] call BIS_fnc_relPos; _newObj = createVehicle[_type,_newPos,[],0,"CAN_COLLIDE"]; _allObjects = _allObjects + [_newObj]; } else { _newPos = [_newObj,1,_dir] call BIS_fnc_relPos; _newObj = createVehicle[_type,_newPos,[],0,"CAN_COLLIDE"]; _allObjects = _allObjects + [_newObj]; }; _i = _i + 1; }; //make some doorways _random = round(random 10); if(_random > 5) then { _door = round(count _allObjects / 2); _doorway = _allObjects select _door; deleteVehicle _doorway; }; //sleep 1; //build the walls _i = 0; _height = 1; { _height = 1; _doorHeight = 1; for "_i" from 0 to _randomizeHigh do { _door = round(count _allObjects / 2); _doorway = _allObjects select _door; _newPos = [getpos _x select 0,getpos _x select 1,(getpos _x select 2) + 1.2 * _height]; _totHeight = 1.2 * _height; _newObj = createVehicle[_type,_newPos,[],0,"CAN_COLLIDE"]; _height = _height + 1; //_random = round(random 10); //_doorHeight = 2; //if(_random > 5 && _newPos isEqualTo [getpos _doorway select 0,getpos _doorway select 1,(getpos _doorway select 2) + _totHeight] && _doorHeight < 2) then //{ //_door = (count _allObjects / 2); // _doorway = _newObj; // deleteVehicle _doorway; //}; }; } foreach _allObjects; //random objs inside //_i = 0; //for "_i" from 0 to 3 + round(random 2) do //{ // _objectCentPos = round(count _allObjects / 2); // _objectCent = _allObjects select _objectCentPos; // _objPos = [_objectCent,2 + round(random 5),random 360] call BIS_fnc_relPos; // _newObj = createVehicle[_type,_objPos,[],0,"CAN_COLLIDE"]; //}; _i = 0; _allSides = _allSides + 1; _allObjects = []; _i = 0; }; Any help would be greatly appreciated. After I get something that functions and builds properly I suspect it'll be a challange to get it building more than one floor.... (staircases) Edited January 31, 2015 by austin_medic Share this post Link to post Share on other sites
TittErS 13 Posted January 31, 2015 (edited) Hi, i ve corrected and optimized your code. i hope this will you help for the future. proced_gen_building.sqf private ["_position","_type","_offsetXY","_offsetZ","_randomizePerim","_randomizeHigh","_doorSide","_doorPosX","_doorHeight","_allSides"]; _position = _this select 0; _type = _this select 1; _offsetXY = 1; _offsetZ = 1.3; _randomizePerim = 10 + round(random 10); _randomizeHigh = 5 + round(random 6); _doorSide = round(random 5) max 1 min 4; _doorPosX = round(_randomizePerim/2)-2; _doorHeight = 2; for "_allSides" from 1 to 4 do { private ["_dir"]; _dir = switch (_allSides) do { case 1: { 0 }; case 2: { 90 }; case 3: { 180 }; case 4: { 270 }; }; for "_i" from 0 to _randomizePerim-2 do { private ["_allObjects","_newObj","_dupliPos"]; _allObjects = []; _position = [_position,_offsetXY,_dir] call BIS_fnc_relPos; _newObj = createVehicle [_type,[0,0,0],[],0,"CAN_COLLIDE"]; _newObj setPosATL _position; _newObj setVectorUp [0,0,1]; _dupliPos = getPosATL _newObj; _allObjects pushBack _newObj; for "_ii" from 0 to _randomizeHigh-2 do { _dupliPos set [2, (_dupliPos select 2) + _offsetZ]; _newObj = createVehicle [_type,[0,0,0],[],0,"CAN_COLLIDE"]; _newObj setPosATL _dupliPos; _allObjects pushBack _newObj; }; if (_allSides == _doorSide && _doorPosX == _i) then { for "_i" from 0 to _doorHeight-1 do { deleteVehicle (_allObjects select _i); }; }; }; }; Edited January 31, 2015 by TittErS Share this post Link to post Share on other sites
austin_medic 109 Posted January 31, 2015 Hi, i ve corrected and optimized your code.i hope this will you help for the future. proced_gen_building.sqf private ["_position","_type","_offsetXY","_offsetZ","_randomizePerim","_randomizeHigh","_doorSide","_doorPosX","_doorHeight","_allSides"]; _position = _this select 0; _type = _this select 1; _offsetXY = 1; _offsetZ = 1.3; _randomizePerim = 10 + round(random 10); _randomizeHigh = 5 + round(random 6); _doorSide = round(random 5) max 1 min 4; _doorPosX = round(_randomizePerim/2)-2; _doorHeight = 2; for "_allSides" from 1 to 4 do { private ["_dir"]; _dir = switch (_allSides) do { case 1: { 0 }; case 2: { 90 }; case 3: { 180 }; case 4: { 270 }; }; for "_i" from 0 to _randomizePerim-2 do { private ["_allObjects","_newObj","_dupliPos"]; _allObjects = []; _position = [_position,_offsetXY,_dir] call BIS_fnc_relPos; _newObj = createVehicle [_type,[0,0,0],[],0,"CAN_COLLIDE"]; _newObj setPosATL _position; _newObj setVectorUp [0,0,1]; _dupliPos = getPosATL _newObj; _allObjects pushBack _newObj; for "_ii" from 0 to _randomizeHigh-2 do { _dupliPos set [2, (_dupliPos select 2) + _offsetZ]; _newObj = createVehicle [_type,[0,0,0],[],0,"CAN_COLLIDE"]; _newObj setPosATL _dupliPos; _allObjects pushBack _newObj; }; if (_allSides == _doorSide && _doorPosX == _i) then { for "_i" from 0 to _doorHeight-1 do { deleteVehicle (_allObjects select _i); }; }; }; }; thanks. Definately much easier to read Share this post Link to post Share on other sites