samatra 85 Posted December 26, 2012 I've decided to release my script that creates chain of walls with different settings. Originally created after help request from other member. Script is free to be used and modified with mention of original author left intact Function code fn_createWallChain.sqf: /* File: fn_createWallChain.sqf Author: Sa-Matra Description: Function creates chain of objects (walls) from specific pos with supplied array of relative angles. Example: _walls = ["Land_fort_bagfence_long", 1.5, getPos player, [0, 90, 90]] execVM "fn_createWallChain.sqf"; Parameter(s): _this select 0: string, Wall class name _this select 1: float, Wall length divided by 2 _this select 2: array, PositionATL of first wall _this select 3: array, List of angles where each angle is relative to angle of previous wall _this select 4: array (optional), List of settings strings. Possible strings are "NO_FIRST" which will not create first wall in the chain and "FLIP_WALLS" to flip all walls the other way Returns: Array of created objects */ if(typeName(_this) != typeName([])) exitWith { diag_log format ["Wall chain script error :: Supplied argument is %1, expected %2", typeName(_this), typeName([])]; }; if(!(count(_this) in [4, 5])) exitWith { diag_log format ["Wall chain script error :: Supplied array length is %1, expected 4 or 5", count(_this)]; }; private ["_class", "_w", "_pos", "_angles", "_no_first", "_flip_walls"]; private ["_new_pos", "_angle", "_edge_pos", "_obj", "_objs"]; _class = _this select 0; // Wall classname _w = _this select 1; // Length of the wall divided by 2 _pos = _this select 2; // Initial wall position _angles = _this select 3; // Array of angles relative to previous angle _no_first = false; _flip_walls = false; if(count(_this) == 5) then { if(typeName(_this select 4) != typeName([])) exitWith { diag_log format ["Wall chain script error :: 5th argument is %1, expected %2", typeName(_this select 4), typeName([])]; }; _no_first = "NO_FIRST" in (_this select 4); // Do not create first wall _flip_walls = "FLIP_WALLS" in (_this select 4); // Flip all walls }; _new_pos = _pos; _angle = nil; _objs = []; _is_first = true; { if(isNil{_angle}) then { _angle = -90 + _x; } else { _is_first = false; _edge_pos = [(_new_pos select 0) + (_w * cos (_angle * -1)), (_new_pos select 1) + (_w * sin (_angle * -1)), _new_pos select 2]; _angle = _angle + _x; _new_pos = [(_edge_pos select 0) + (_w * cos (_angle * -1)), (_edge_pos select 1) + (_w * sin (_angle * -1)), _new_pos select 2]; }; if(!_no_first || !_is_first) then { _obj = createVehicle [_class, _new_pos, [], 0, "CAN_COLLIDE"]; _obj setPosATL _new_pos; _obj setDir (if(_flip_walls) then {180 + _angle} else {_angle}); _obj setVectorUp (surfaceNormal getPosATL _obj); _objs = _objs + [_obj]; }; } forEach _angles; _objs Or here: http://pastie.org/pastes/5580626/text How to use it: Compile the script: fn_createWallChain = compile preprocessFileLineNumbers "fn_createWallChain.sqf"; and then call it [... arguments ...] call fn_createWallChain; Examples: Create earthen rampart curve Code: fn_createWallChain = compile preprocessFileLineNumbers "fn_createWallChain.sqf"; ["Land_fort_rampart", 5, [10355, 8643, 0], [0, 20, 20, 20, 20, 20]] call fn_createWallChain; Create concrete walls box Code: fn_createWallChain = compile preprocessFileLineNumbers "fn_createWallChain.sqf"; ["Concrete_Wall_EP1", 1.2, [10355, 8643, 0], [0, 0, 0, 90, 0, 0, 0, 0, 0, 0, 90, 0, 0, 0, 0, 0, 0, 90, 0, 0, 0, 0, 0, 0, 90, 0, 0]] call fn_createWallChain; Randomized tank traps lines Code: fn_createWallChain = compile preprocessFileLineNumbers "fn_createWallChain.sqf"; _angles = []; for "_i" from 0 to 20 do {_angles = _angles + [-20 + random 40];}; ["Hedgehog", 2, [10335, 8643, 0], _angles] call fn_createWallChain; _angles = []; for "_i" from 0 to 20 do {_angles = _angles + [-20 + random 40];}; ["Hedgehog", 2, [10355, 8643, 0], _angles] call fn_createWallChain; _angles = []; for "_i" from 0 to 20 do {_angles = _angles + [-20 + random 40];}; ["Hedgehog", 2, [10375, 8643, 0], _angles] call fn_createWallChain; Share this post Link to post Share on other sites
Jastreb 69 Posted December 26, 2012 Good stuff thanks for this one. Lots of effort invested here :pc: Share this post Link to post Share on other sites
Horner 13 Posted December 26, 2012 Nice work man, very impressed :D Share this post Link to post Share on other sites
tryteyker 28 Posted December 26, 2012 Nice work, I had a mission idea where I'd need such a concrete wall box, helps immensely, thanks alot. Share this post Link to post Share on other sites
Alo Keen 7 Posted April 15, 2013 Inspired by this and needing something similar, I adapted it to create a circle of objects centered around given position: /* File: fn_createWallCircle.sqf Author: Sa-Matra Original version: fn_createWallChain.sqf http://forums.bistudio.com/showthread.php?143989-RELEASE-fn_createWallChain-sqf-Easy-way-to-create-chain-of-walls Adapted by: ÄŒeh Description: Function places objects centered around a specific position. Example: _walls = ["Land_fort_bagfence_long", getPos player, 6, 8] execVM "fn_createWallRing.sqf"; Parameter(s): _this select 0: string, Wall class name _this select 1: array, PositionATL of first object _this select 2: float, Radius of the circle _this select 3: int, Number of objects _this select 4: boolean, flip walls _this select 5: int, max angle of variation on each object placement angle (useful if you don't want the circle to look too tidy) Returns: Array of created objects */ private ["_class", "_pos", "_flip_walls", "_noise"]; private ["_new_pos", "_angle", "_obj", "_objs"]; private ["_radius", "_count", "_center", "_i", "_xpos", "_ypos"]; _class = _this select 0; // Wall classname _center = _this select 1; // Center of the circle _radius = _this select 2; // Radius of the circle _count = _this select 3; // Number of objects _flip_walls = _this select 4; // Flip all walls the other way _noise = _this select 5; // Max angle of variation for each object _objs = []; _new_pos = []; _center set [2, 0]; for "_i" from 1 to _count do { _xpos = (_center select 0) + (_radius * cos(360 * _i / _count)); _ypos = (_center select 1) + (_radius * sin(360 * _i / _count)); _angle = 90 - ((360/_count) * _i); _new_pos set [0, _xpos]; _new_pos set [1, _ypos]; _new_pos set [2, 0]; if(_flip_walls) then { _angle = 180 + _angle; }; if(_noise != 0) then { _angle = _angle + (random _noise) - (_noise/2); }; _obj = createVehicle [_class, _new_pos, [], 0, "CAN_COLLIDE"]; _obj setPosATL _new_pos; _obj setDir _angle; _obj setVectorUp (surfaceNormal getPosATL _obj); _objs = _objs + [_obj]; }; _objs Share this post Link to post Share on other sites