jakerod 254 Posted August 31, 2011 I have a H (Invisible) on the map named heli_mark. A Radio Alpha Trigger with the following in the On Activation Field: Quote testtest = [heli_mark,0,0,0] execVM "spawn_group.sqf" As of right now everything works perfectly as I expect it to so I am moving onto the next step. (Code is Below) Presently, the script will place 5 separate groups of units into the same house. This is undesirable but the way I set it up because I lack the knowledge on how to carry out the next part. This is the list of what needs to happen next: Put down a trigger and change the axis (in editor) The script should detect this area the script should then identify all buildings in the area (or buildings of the 5 classes I have set-up below) the script should then place the guys into those buildings if there are multiple buildings of that type, the script should fill in all of them (or if possible use the _percentBuildGar (which I have set-up below) to fill them up on a percentage basis. My main problem is the part with the trigger. I don't know how to do that. I'm fairly sure that it is possible but if a trigger isn't then a marker would work fine. I just don't want to use radius because I want to be able to skew it one direction or the other. The part about identifying buildings I would think would be done using this: Quote if (_somevariablehere isKindOf "Land_A_BuildingWIP") then {something else goes here}; However, I have never used that before and don't know how to go about it. And the rest of the stuff I have no idea how to do. If anyone has any good ideas on how to solve these issues or on how I can find out how to do this stuff please let me know. Additionally, if you think anything is totally stupid in my script or redundant please let me know. _buildingMark = _this select 0; ///Marker near the Building that Men are Going into _percentBuildGar = _this select 1; ///Percent of Buildings spawned with men _percentPosGar = _this select 2; ///Percent of Total Men in Building Spawned _minSkillRange = _this select 3; ///Lowest Skill of Units _maxSkillRange = _this select 4; ///Highest Skill of Units _buildingGar = nearestbuilding _buildingMark; ///Start of House Library ///House_L_1 _H_L_1_pos_00_A = [0.871826,-1.55762,-0.616486]; _H_L_1_pos_01_A = [-0.468628,-1.91333,-0.610672]; _H_L_1_pos_02_A = [-0.265747,0.536377,-0.597946]; _H_L_1_pos_00 = _buildingGar modelToWorld _H_L_1_pos_00_A; _H_L_1_pos_01 = _buildingGar modelToWorld _H_L_1_pos_01_A; _H_L_1_pos_02 = _buildingGar modelToWorld _H_L_1_pos_02_A; ///House_L_3 _H_L_3_pos_00_A = [2.47095,2.23193,-0.222473]; _H_L_3_pos_01_A = [0.26416,0.171143,-0.222473]; _H_L_3_pos_02_A = [2.61646,0.507813,-0.222473]; _H_L_3_pos_03_A = [-6.02686,1.77661,-0.229202]; _H_L_3_pos_04_A = [-5.7417,0.234619,-0.172028]; _H_L_3_pos_05_A = [-2.88672,0.0483398,-0.246185]; _H_L_3_pos_00 = _buildingGar modelToWorld _H_L_3_pos_00_A; _H_L_3_pos_01 = _buildingGar modelToWorld _H_L_3_pos_01_A; _H_L_3_pos_02 = _buildingGar modelToWorld _H_L_3_pos_02_A; _H_L_3_pos_03 = _buildingGar modelToWorld _H_L_3_pos_03_A; _H_L_3_pos_04 = _buildingGar modelToWorld _H_L_3_pos_04_A; _H_L_3_pos_05 = _buildingGar modelToWorld _H_L_3_pos_05_A; ///House_L_4 _H_L_4_pos_00_A = [-4.9248,0.795898,-1.34981]; _H_L_4_pos_01_A = [-4.9248,0.795898,-1.34981]; _H_L_4_pos_02_A = [6.14819,1.62915,-1.06708]; _H_L_4_pos_03_A = [-3.52319,3.36365,0.768433]; _H_L_4_pos_04_A = [-4.23145,0.80127,1.72308]; _H_L_4_pos_00 = _buildingGar modelToWorld _H_L_4_pos_00_A; _H_L_4_pos_01 = _buildingGar modelToWorld _H_L_4_pos_01_A; _H_L_4_pos_02 = _buildingGar modelToWorld _H_L_4_pos_02_A; _H_L_4_pos_03 = _buildingGar modelToWorld _H_L_4_pos_03_A; _H_L_4_pos_04 = _buildingGar modelToWorld _H_L_4_pos_04_A; ///House_L_7 _H_L_7_pos_00_A = [-0.447754,-3.17737,-0.97998]; _H_L_7_pos_01_A = [-0.447754,-3.17737,-0.97998]; _H_L_7_pos_02_A = [-5.09717,2.96655,-0.647263]; _H_L_7_pos_03_A = [-3.92456,3.10986,-0.651184]; _H_L_7_pos_04_A = [0.5625,2.16357,-0.261154]; _H_L_7_pos_05_A = [5.13916,-0.493408,-0.165512]; _H_L_7_pos_00 = _buildingGar modelToWorld _H_L_7_pos_00_A; _H_L_7_pos_01 = _buildingGar modelToWorld _H_L_7_pos_01_A; _H_L_7_pos_02 = _buildingGar modelToWorld _H_L_7_pos_02_A; _H_L_7_pos_03 = _buildingGar modelToWorld _H_L_7_pos_03_A; _H_L_7_pos_04 = _buildingGar modelToWorld _H_L_7_pos_04_A; _H_L_7_pos_05 = _buildingGar modelToWorld _H_L_7_pos_05_A; ///House_L_8 _H_L_8_pos_00_A = [5.31592,5.72583,0.440201]; _H_L_8_pos_01_A = [0.53125,5.56653,1.71164]; _H_L_8_pos_02_A = [-1.43726,5.44019,1.67599]; _H_L_8_pos_03_A = [-3.18311,0.695557,1.65121]; _H_L_8_pos_04_A = [-3.38647,-4.27258,1.32121]; _H_L_8_pos_05_A = [-1.90845,-6.01123,1.32121]; _H_L_8_pos_06_A = [3.79834,5.56799,1.72716]; _H_L_8_pos_07_A = [4.87573,3.19666,1.73621]; _H_L_8_pos_08_A = [5.24243,3.61133,1.73621]; _H_L_8_pos_09_A = [4.51929,3.89258,-0.773804]; _H_L_8_pos_10_A = [1.19531,0.245728,-1.01575]; _H_L_8_pos_11_A = [-2.98706,2.46497,-1.01575]; _H_L_8_pos_12_A = [-1.41406,5.46545,-0.993652]; _H_L_8_pos_13_A = [0.989746,5.41211,-1.01489]; _H_L_8_pos_14_A = [4.06152,0.920898,-1.07404]; _H_L_8_pos_15_A = [-2.81055,-1.93311,-1.54376]; _H_L_8_pos_00 = _buildingGar modelToWorld _H_L_8_pos_00_A; _H_L_8_pos_01 = _buildingGar modelToWorld _H_L_8_pos_01_A; _H_L_8_pos_02 = _buildingGar modelToWorld _H_L_8_pos_02_A; _H_L_8_pos_03 = _buildingGar modelToWorld _H_L_8_pos_03_A; _H_L_8_pos_04 = _buildingGar modelToWorld _H_L_8_pos_04_A; _H_L_8_pos_05 = _buildingGar modelToWorld _H_L_8_pos_05_A; _H_L_8_pos_06 = _buildingGar modelToWorld _H_L_8_pos_06_A; _H_L_8_pos_07 = _buildingGar modelToWorld _H_L_8_pos_07_A; _H_L_8_pos_08 = _buildingGar modelToWorld _H_L_8_pos_08_A; _H_L_8_pos_09 = _buildingGar modelToWorld _H_L_8_pos_09_A; _H_L_8_pos_10 = _buildingGar modelToWorld _H_L_8_pos_10_A; _H_L_8_pos_11 = _buildingGar modelToWorld _H_L_8_pos_11_A; _H_L_8_pos_12 = _buildingGar modelToWorld _H_L_8_pos_12_A; _H_L_8_pos_13 = _buildingGar modelToWorld _H_L_8_pos_13_A; _H_L_8_pos_14 = _buildingGar modelToWorld _H_L_8_pos_14_A; _H_L_8_pos_15 = _buildingGar modelToWorld _H_L_8_pos_15_A; ///End of House Library ///Start of Squad Library ///Squad for House L_1 ///3 Positions _L1SquadUnits = ["TK_INS_Soldier_TL_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_4_EP1"]; _L1SquadSkill = [_minSkillRange,_maxSkillRange]; _L1_squad = [getMarkerPos "Squad1", east, _L1SquadUnits, [], [], _L1SquadSkill] call BIS_fnc_spawnGroup; sleep .5; {dostop _x} foreach units _L1_squad; {_x enableattack false} forEach units _L1_squad; {_x setunitpos "up"} forEach units _L1_squad; _L1_squad_members = units _L1_squad; sleep .5; _L1_squad_mem_00 = _L1_squad_members select 0; _L1_squad_mem_00 setPosATL _H_L_1_pos_00; _L1_squad_mem_01 = _L1_squad_members select 1; _L1_squad_mem_01 setPosATL _H_L_1_pos_01; _L1_squad_mem_02 = _L1_squad_members select 2; _L1_squad_mem_02 setPosATL _H_L_1_pos_02; ///Squad for House L_3 ///6 positions _L3SquadUnits = ["TK_INS_Soldier_TL_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_4_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_TL_EP1","TK_INS_Soldier_MG_EP1", "TK_INS_Soldier_TL_EP1"]; _L3SquadSkill = [_minSkillRange,_maxSkillRange]; _L3_squad = [getMarkerPos "Squad1", east, _L3SquadUnits, [], [], _L3SquadSkill] call BIS_fnc_spawnGroup; sleep .5; {dostop _x} foreach units _L3_squad; {_x enableattack false} forEach units _L3_squad; {_x setunitpos "up"} forEach units _L3_squad; _L3_squad_members = units _L3_squad; sleep.5; _L3_squad_mem_00 = _L3_squad_members select 0; _L3_squad_mem_00 setPosATL _H_L_3_pos_00; _L3_squad_mem_01 = _L3_squad_members select 1; _L3_squad_mem_01 setPosATL _H_L_3_pos_01; _L3_squad_mem_02 = _L3_squad_members select 2; _L3_squad_mem_02 setPosATL _H_L_3_pos_02; _L3_squad_mem_03 = _L3_squad_members select 3; _L3_squad_mem_03 setPosATL _H_L_3_pos_03; _L3_squad_mem_04 = _L3_squad_members select 4; _L3_squad_mem_04 setPosATL _H_L_3_pos_04; _L3_squad_mem_05 = _L3_squad_members select 5; _L3_squad_mem_05 setPosATL _H_L_3_pos_05; ///Squad for House L_4 ///5 positions _L4SquadUnits = ["TK_INS_Soldier_TL_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_4_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_TL_EP1","TK_INS_Soldier_MG_EP1"]; _L4SquadSkill = [_minSkillRange,_maxSkillRange]; _L4_squad = [getMarkerPos "Squad1", east, _L4SquadUnits, [], [], _L4SquadSkill] call BIS_fnc_spawnGroup; sleep .5; {dostop _x} foreach units _L4_squad; {_x enableattack false} forEach units _L4_squad; {_x setunitpos "up"} forEach units _L4_squad; _L4_squad_members = units _L4_squad; sleep .5; _L4_squad_mem_00 = _L4_squad_members select 0; _L4_squad_mem_00 setPosATL _H_L_4_pos_00; _L4_squad_mem_01 = _L4_squad_members select 1; _L4_squad_mem_01 setPosATL _H_L_4_pos_01; _L4_squad_mem_02 = _L4_squad_members select 2; _L4_squad_mem_02 setPosATL _H_L_4_pos_02; _L4_squad_mem_03 = _L4_squad_members select 3; _L4_squad_mem_03 setPosATL _H_L_4_pos_03; _L4_squad_mem_04 = _L4_squad_members select 4; _L4_squad_mem_04 setPosATL _H_L_4_pos_04; ///Squad for House L_7 ///6 Positions _L7SquadUnits = ["TK_INS_Soldier_TL_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_4_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_4_EP1","TK_INS_Soldier_3_EP1"]; _L7SquadSkill = [_minSkillRange,_maxSkillRange]; L7_squad = [getMarkerPos "Squad1", east, _L7SquadUnits, [], [], _L7SquadSkill] call BIS_fnc_spawnGroup; sleep .5; {dostop _x} foreach units _L7_squad; {_x enableattack false} forEach units _L7_squad; {_x setunitpos "up"} forEach units _L7_squad; _L7_squad_members = units _L7_squad; sleep .5; _L7_squad_mem_00 = _L7_squad_members select 0; _L7_squad_mem_00 setPosATL _H_L_7_pos_00; _L7_squad_mem_01 = _L7_squad_members select 1; _L7_squad_mem_01 setPosATL _H_L_7_pos_01; _L7_squad_mem_02 = _L7_squad_members select 2; _L7_squad_mem_02 setPosATL _H_L_7_pos_02; _L7_squad_mem_03 = _L7_squad_members select 3; _L7_squad_mem_03 setPosATL _H_L_7_pos_03; _L7_squad_mem_04 = _L7_squad_members select 4; _L7_squad_mem_04 setPosATL _H_L_7_pos_04; _L7_squad_mem_05 = _L7_squad_members select 5; _L7_squad_mem_05 setPosATL _H_L_7_pos_05; ///Squad for House L_8 ///16 Positions _L8SquadUnits = ["TK_INS_Soldier_TL_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_4_EP1","TK_INS_Soldier_AAT_EP1","TK_INS_Soldier_MG_EP1","TK_INS_Soldier_AR_EP1","TK_INS_Soldier_4_EP1","TK_INS_Soldier_4_EP1","TK_INS_Soldier_4_EP1","TK_INS_Soldier_TL_EP1","TK_INS_Soldier_4_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_3_EP1","TK_INS_Soldier_3_EP1"]; _L8SquadSkill = [_minSkillRange,_maxSkillRange]; _l8_squad = [getMarkerPos "Squad1", east, _L8SquadUnits, [], [], _L8SquadSkill] call BIS_fnc_spawnGroup; sleep .5; {dostop _x} foreach units _L8_squad; {_x enableattack false} forEach units _L8_squad; {_x setunitpos "up"} forEach units _L8_squad; _L8_squad_members = units _L8_squad; sleep .5; _L8_squad_mem_00 = _L8_squad_members select 0; _L8_squad_mem_00 setPosATL _H_L_8_pos_00; _L8_squad_mem_01 = _L8_squad_members select 1; _L8_squad_mem_01 setPosATL _H_L_8_pos_01; _L8_squad_mem_02 = _L8_squad_members select 2; _L8_squad_mem_02 setPosATL _H_L_8_pos_02; _L8_squad_mem_03 = _L8_squad_members select 3; _L8_squad_mem_03 setPosATL _H_L_8_pos_03; _L8_squad_mem_04 = _L8_squad_members select 4; _L8_squad_mem_04 setPosATL _H_L_8_pos_04; _L8_squad_mem_05 = _L8_squad_members select 5; _L8_squad_mem_05 setPosATL _H_L_8_pos_05; _L8_squad_mem_06 = _L8_squad_members select 6; _L8_squad_mem_06 setPosATL _H_L_8_pos_06; _L8_squad_mem_07 = _L8_squad_members select 7; _L8_squad_mem_07 setPosATL _H_L_8_pos_07; _L8_squad_mem_08 = _L8_squad_members select 8; _L8_squad_mem_08 setPosATL _H_L_8_pos_08; _L8_squad_mem_09 = _L8_squad_members select 9; _L8_squad_mem_09 setPosATL _H_L_8_pos_09; _L8_squad_mem_10 = _L8_squad_members select 10; _L8_squad_mem_10 setPosATL _H_L_8_pos_10; _L8_squad_mem_11 = _L8_squad_members select 11; _L8_squad_mem_11 setPosATL _H_L_8_pos_11; _L8_squad_mem_12 = _L8_squad_members select 12; _L8_squad_mem_12 setPosATL _H_L_8_pos_12; _L8_squad_mem_13 = _L8_squad_members select 13; _L8_squad_mem_13 setPosATL _H_L_8_pos_13; _L8_squad_mem_14 = _L8_squad_members select 14; _L8_squad_mem_14 setPosATL _H_L_8_pos_14; _L8_squad_mem_15 = _L8_squad_members select 15; _L8_squad_mem_15 setPosATL _H_L_8_pos_15; ///End of Squad Library hint format ["I'm trying to work!"]; leader _L8_squad sidechat "Hahaha!"; ///wPos = nbuilding modelToWorld i8_00_pos; ///this setPosATL wPos; {_x enableAttack false} forEach units this; {dostop _x} forEach units this; Share this post Link to post Share on other sites
twirly 11 Posted September 1, 2011 BIS_fnc_InTrigger might help you there. I've never used it but it is in the Functions Module. Here is part of the comments for the script...will help with how to call it. Description: Detects whether is position within trigger area. Parameter(s): _this select 0: Trigger _this select 1: Position _this select 2: OPTIONAL - scalar result (distance from border) Returns: Boolean (true when position is in area, false if not). Share this post Link to post Share on other sites
jakerod 254 Posted September 1, 2011 twirly said: BIS_fnc_InTrigger might help you there. I've never used it but it is in the Functions Module.Here is part of the comments for the script...will help with how to call it. Description: Detects whether is position within trigger area. Parameter(s): _this select 0: Trigger _this select 1: Position _this select 2: OPTIONAL - scalar result (distance from border) Returns: Boolean (true when position is in area, false if not). Thanks, I'll take a look at that. Additional question, how can I stop the script from spawning multiple guys in the same place in multiplayer? Share this post Link to post Share on other sites
galzohar 31 Posted September 1, 2011 Why don't you use nearObjects? Then filter the array... Share this post Link to post Share on other sites
igneous01 19 Posted September 1, 2011 here are some functions I am using in my random fortification script to find buildings, and spawn groups inside them. just initialize the functions, then run them using call, the parameters are self explanatory, and i documented the return value // Building position counter function // Originally created by Rube // Returns a list of all available building positions RUFS_CountBuildingPos = { private ["_building", "_positions", "_i"]; _building = _this; _positions = [(position _building)]; // search more positions _i = 1; while {_i > 0} do { private ["_next"]; _next = _building buildingPos _i; if (((_next select 0) == 0) && ((_next select 1) == 0) && ((_next select 2) == 0)) then { _i = 0; } else { _positions set [(count _positions), _next]; _i = _i + 1; }; }; // return positions _positions }; // CityExists function // Determine whether or not buildings exist inside the area that are also enterable // returns true is buildings that are enterable are found RUFS_CityExists = { private ["_logic", "_rad", "_CityFound", "_listNearObjects", "_positions"]; _logic = _this select 0; _rad = _this select 1; _CityFound = false; _listNearObjects = nearestObjects [getpos _logic, ["house"], _rad]; // If buildings found if ((count _listNearObjects) > 0) then { // Examine all buildings, count their building positions, determine whether 3 or more building positions exist { _positions = _x call RUFS_CountBuildingPos; if ((count _positions) > 4) exitwith {_CityFound = true;}; } foreach _listNearObjects; }; if ((count _listNearObjects) < 1) then { _CityFound = false; }; _CityFound }; // Building count function, returns an array of buildings that are enterable RUFS_CountBuildings = { private ["_logic", "_rad", "_buildingarray", "_listNearObjects", "_positions"]; _logic = _this select 0; _rad = _this select 1; _listNearObjects = nearestObjects [getpos _logic, ["house"], _rad]; _buildingarray = []; { _positions = _x call RUFS_CountBuildingPos; if ((count _positions) > 4) then { _buildingarray set [(count _buildingarray), _x]; }; } foreach _listNearObjects; _buildingarray }; // Group move in building function RUFS_GroupBuilding = { private ["_group", "_units", "_building", "_pos", "_curUnit", "_nextUnit"]; _group = _this select 0; _building = _this select 1; _units = units _group; // count building positions _pos = _building call RUFS_CountBuildingPos; if ((count _pos) < 2) exitWith { hint "Error RUFS_GroupBuilding: No building with positions found"; }; for [{_i = 0}, {_i >= (count _units - 1)}, {_i = _i + 2}] do { _curUnit = (_units select _i); _nextUnit = (_units select (_i + 1)); _curUnit setpos (_pos select (floor(random(count _pos))) ); doStop _curUnit; if ( !(isNull _nextUnit) ) then { _nextUnit doFollow _curUnit; _nextUnit setpos (_pos select (floor(random(count _pos))) ); }; }; }; you may want to adjust some of the hints and stuff so its more appropriate for your mission/script. they are mainly used for debugging. Hopefully the functions are self explanatory. If not feel free to ask questions ;) Share this post Link to post Share on other sites
twirly 11 Posted September 1, 2011 (edited) Here is the BIS_fnc_InTrigger modified to work with markers. It might help you. Tests whether a position is in a rectangular or elliptical marker area. Returns true or false. In init.sqf:- fnc_InMarker = compile preProcessFile "fnc_InMarker.sqf"; fnc_InMarker.sqf:- /* ****fnc_InMarker.sqf ****BIS_fnc_InTrigger modified by twirly to work with markers. ****Sept 1st 2011 Description: Detects whether is position within marker area. Parameter(s): _this select 0: Marker _this select 1: Position _this select 2: OPTIONAL - scalar result (distance from border) Returns: Boolean (true when position is in area, false if not). */ private ["_mkr","_object","_posx","_posy","_tstuff","_tx","_ty","_tdir","_tshape","_in"]; _mkr = _this select 0; _position = _this select 1; _scalarresult = if (count _this > 2) then {_this select 2} else {false}; _posx = getmarkerpos _mkr select 0; _posy = getmarkerpos _mkr select 1; _tstuff = markersize _mkr; _tx = _tstuff select 0; _ty = _tstuff select 1; _tdir = markerdir _mkr; _tshape = markershape _mkr; _in = false; if (_tshape == "RECTANGLE") then { //--- RECTANGLE _difx = (_position select 0) - _posx; _dify = (_position select 1) - _posy; _dir = atan (_difx / _dify); if (_dify < 0) then {_dir = _dir + 180}; _relativedir = _tdir - _dir; _adis = abs (_tx / cos (90 - _relativedir)); _bdis = abs (_ty / cos _relativedir); _borderdis = _adis min _bdis; _positiondis = _position distance getmarkerpos _mkr; _in = if (_scalarresult) then { _positiondis - _borderdis; } else { if (_positiondis < _borderdis) then {true} else {false}; }; } else { //--- ELLIPSE _dis = sqrt abs(_tx^2 - _ty^2); _posF1 = [_posx + (sin (_tdir) * _dis),_posy + (cos (_tdir) * _dis)]; _posF2 = [_posx - (sin (_tdir) * _dis),_posy - (cos (_tdir) * _dis)]; _n = _tx max _ty; _total = 2 * _n; _dis1 = _position distance _posF1; _dis2 = _position distance _posF2; _in = if (_scalarresult) then { (_dis1 + _dis2) - _total; } else { if (_dis1 + _dis2 < _total) then {true} else {false}; }; }; _in Call with:- _test = ["mkrname",_pos] call fnc_InMarker.sqf; Where:- "mkrname" is the name of the marker _pos is the position you are checking Returns true or false. Hope it helps. EDIT: Here's the mission I was using to test. Both a trigger and a marker are used in the test....so both functions there. Of course this is just a part of the puzzle..... but you can build an array of buildings in the marker or trigger and then filter that list to find out if any of the buildings you are interested in are there. Edited September 1, 2011 by twirly Clarity. Share this post Link to post Share on other sites
jakerod 254 Posted September 1, 2011 twirly said: Here is the BIS_fnc_InTrigger modified to work with markers. It might help you.Tests whether a position is in a rectangular or elliptical marker area. Returns true or false. In init.sqf:- fnc_InMarker = compile preProcessFile "fnc_InMarker.sqf"; fnc_InMarker.sqf:- /* ****fnc_InMarker.sqf ****BIS_fnc_InTrigger modified by twirly to work with markers. ****Sept 1st 2011 Description: Detects whether is position within marker area. Parameter(s): _this select 0: Marker _this select 1: Position _this select 2: OPTIONAL - scalar result (distance from border) Returns: Boolean (true when position is in area, false if not). */ private ["_mkr","_object","_posx","_posy","_tstuff","_tx","_ty","_tdir","_tshape","_in"]; _mkr = _this select 0; _position = _this select 1; _scalarresult = if (count _this > 2) then {_this select 2} else {false}; _posx = getmarkerpos _mkr select 0; _posy = getmarkerpos _mkr select 1; _tstuff = markersize _mkr; _tx = _tstuff select 0; _ty = _tstuff select 1; _tdir = markerdir _mkr; _tshape = markershape _mkr; _in = false; if (_tshape == "RECTANGLE") then { //--- RECTANGLE _difx = (_position select 0) - _posx; _dify = (_position select 1) - _posy; _dir = atan (_difx / _dify); if (_dify < 0) then {_dir = _dir + 180}; _relativedir = _tdir - _dir; _adis = abs (_tx / cos (90 - _relativedir)); _bdis = abs (_ty / cos _relativedir); _borderdis = _adis min _bdis; _positiondis = _position distance getmarkerpos _mkr; _in = if (_scalarresult) then { _positiondis - _borderdis; } else { if (_positiondis < _borderdis) then {true} else {false}; }; } else { //--- ELLIPSE _dis = sqrt abs(_tx^2 - _ty^2); _posF1 = [_posx + (sin (_tdir) * _dis),_posy + (cos (_tdir) * _dis)]; _posF2 = [_posx - (sin (_tdir) * _dis),_posy - (cos (_tdir) * _dis)]; _n = _tx max _ty; _total = 2 * _n; _dis1 = _position distance _posF1; _dis2 = _position distance _posF2; _in = if (_scalarresult) then { (_dis1 + _dis2) - _total; } else { if (_dis1 + _dis2 < _total) then {true} else {false}; }; }; _in Call with:- _test = ["mkrname",_pos] call fnc_InMarker.sqf; Where:- "mkrname" is the name of the marker _pos is the position you are checking Returns true or false. Hope it helps. EDIT: Here's the mission I was using to test. Both a trigger and a marker are used in the test....so both functions there. Of course this is just a part of the puzzle..... but you can build an array of buildings in the marker or trigger and then filter that list to find out if any of the buildings you are interested in are there. Thanks. In your example mission does it actually find the buildings in it? I was a bit confused because it goes through like 4 different hint screens in two seconds and I couldn't tell precisely what it was doing. If that is what it's doing then can I use: Quote if (_somevariablehere isKindOf "Land_A_BuildingWIP") then {something else goes here}; Or something similar to help sort them out? Is that how that would work? Share this post Link to post Share on other sites
galzohar 31 Posted September 1, 2011 For missions I make I usually just use a function that counts building positions and filter out buildings that have at least 1. But you could use any condition to filter once you have the array, such as (typeOf _x) == "Land_A_BuildingWIP". Share this post Link to post Share on other sites
twirly 11 Posted September 2, 2011 (edited) Jakerod said: Thanks. In your example mission does it actually find the buildings in it? I was a bit confused because it goes through like 4 different hint screens in two seconds and I couldn't tell precisely what it was doing. If that is what it's doing then can I use: Yes... in the demo... the script buildInMarker.sqf is finding all buildings in the marker using the function fnc_InMarker.sqf and placing them in the array _builds_in_mrkr. You then have to filter this list to find the buildings you want. Then it does the same thing again using the script buildInTrigger.sqf which uses the function fnc_InTrigger.sqf. So you have an example for both triggers and markers in the one demo. If you didn't already know this...you can increase the sleep values in the script to slow down the hints. Edited September 2, 2011 by twirly Clarity Share this post Link to post Share on other sites
VictorFarbau 0 Posted September 2, 2011 Jakerod said: Additional question, how can I stop the script from spawning multiple guys in the same place in multiplayer? Oldie but goldie - use the isServer command (check the Wiki + example) to make sure the script exits when started on a client in MP mode. Only the server should spawn objects. VictorFarbau Share this post Link to post Share on other sites
jakerod 254 Posted September 2, 2011 twirly said: Yes... in the demo... the script buildInMarker.sqf is finding all buildings in the marker using the function fnc_InMarker.sqf and placing them in the array _builds_in_mrkr. You then have to filter this list to find the buildings you want.Then it does the same thing again using the script buildInTrigger.sqf which uses the function fnc_InTrigger.sqf. So you have an example for both triggers and markers in the one demo. If you didn't already know this...you can increase the sleep values in the script to slow down the hints. Okay. I missed those sleep commands some how. VictorFarbau said: Oldie but goldie - use the isServer command (check the Wiki + example) to make sure the script exits when started on a client in MP mode. Only the server should spawn objects.VictorFarbau Thank you. Share this post Link to post Share on other sites
jakerod 254 Posted September 3, 2011 I'm fairly sure that I'm going to use twirly's buildinTrigger script for the area search. Now my question is what do you guys think the best way of finding the individual buildings are? The array is temporarily named _list. This is an excerpt from what I'm doing right now (setdamage is being used because it if fairly obvious when it is true or false and I am already using a hint): Quote Method #1 if ("land_house_l_1_ep1" in _list) then {player setdamage 1}; Method #2 if ((_list select 0) isKindOf "Land_House_L_1_EP1") then {player setdamage 1}; if ((_list select 0) isKindOf "Land_House_L_3_EP1" OR (_list select 0) isKindOf "Land_House_L_3_dam_EP1") then {player setdamage 1}; The problem is that with the first method I have to have the exact same name and it is case sensitive. So far I have been unable to find the exact case order for that house and I have tried every order that makes sense to me. The problem with the second method is that I would have to do that for every element in the array and I don't even know how many elements are going to be in the array because it is going to vary from one trigger placement and/or area to the next. Share this post Link to post Share on other sites
galzohar 31 Posted September 3, 2011 (edited) Not sure exactly how isKindOf works, try using typeOf (_list select 0) instead to get the exact class name. If you don't want case sensitive problems use toLower or toUpper on both, but upper/lower case shouldn't be a problem if you originally obtained the classname by using the typeOf command. By the way, to test you could use: player sideChat "testing..."; { player sideChat format [ "building: %1 ... typeOf building: %2 ... isKindOf Land_House_L_1_EP1: %3 ... isKindOf Land_House_L_3_EP1: %4", _x, typeOf _x, _x isKindOf "Land_House_L_1_EP1", _x isKindOf "Land_House_L_3_EP1" ]; } forEach _list; Edited September 3, 2011 by galzohar Share this post Link to post Share on other sites
jakerod 254 Posted September 3, 2011 galzohar said: Not sure exactly how isKindOf works, try using typeOf (_list select 0) instead to get the exact class name. If you don't want case sensitive problems use toLower or toUpper on both, but upper/lower case shouldn't be a problem if you originally obtained the classname by using the typeOf command.By the way, to test you could use: The isKindof part works. The problem I have with it is that I don't know how to use it to check all elements in an array only a specific one and since I don't know how many elements there are going to be in the array then that is problematic to me. That is why I wanted to try to use the "in" command but then that gave me the problem of capitalization. If I use the isKindOf or the typeOf command then I still have the problem of checking all elements of the array do I not? Your upper or lower case thing gave me an idea though so I tried this: Quote _target_object = _this select 0; ///center of radius_list = nearestObjects [player, ["building"], 1]; ///check objects within 1 meter. hint format ["%1", _list]; ///show objects in hint form _strlist = tostring (_list); ///convert the list to a string because it has to be a string for tolower to work. _strllist = tolower (_strlist); ///lowercase the letters _arrlist = toarray (_strllist); ///change back to array because "in" needs an array if ("land_house_l_1_ep1" in _arrlist) then {player setdamage 1}; ///kill player if this is met. That doesn't work. It should I think though to the best of my knowledge. Because I am standing inside the building and the hint shows up the model of that class. The hint shows: {a bunch of numbers and letters} land_house_l_1_ep1.p3d And then when I change it to: Quote _target_object = _this select 0;_list = nearestObjects [player, ["building"], 1]; hint format ["%1", _list]; sleep 5; _strlist = tostring (_list); sleep 5; hint format ["%1", _strlist]; _strllist = tolower (_strlist); sleep 5; hint format ["%1", _strllist]; _arrlist = toarray (_strllist); sleep 5; hint format ["%1", _arrlist]; if ("land_house_l_1_ep1" in _arrlist) then {player setdamage 1}; Only the first hint says anything. Two more pop up but they both just say []. Even though I think another one should pop up. Neither thing of code I used showed any error either. Share this post Link to post Share on other sites
galzohar 31 Posted September 3, 2011 toString is actually the reverse command for toArray and is useful for string manipulation. In your example you actually want to use str command. As fro your original question, best would probably be to use forEach, or alternatively (usually not as easy to use but can do the same thing) count and then for or while. Share this post Link to post Share on other sites
twirly 11 Posted September 3, 2011 (edited) Try this to find specific buildings using the stuff in my demo. Replace the call and the script buildInMarker.sqf. You have to add an array to the call of the types of buildings you want to find. Call with:- nul = ["mkr1",[b]["Land_HouseV_1I4","Land_Shed_W4","Land_HouseV_1I3"][/b]] execVM "buildInMarker.sqf"; Then I changed the script buildInMarker.sqf to:- _mkr = _this select 0; _buildings_to_check_4 = _this select 1; _mkrsiz = markersize _mkr; _mkrszx = _mkrsiz select 0; _mkrszy = _mkrsiz select 1; _mkrpos = getmarkerpos _mkr; _longside = _mkrszx max _mkrszy; _builds = nearestObjects [_mkrpos, ["Building"], _longside]; _inmrkr = false; _builds_in_mrkr = []; for "_i" from 0 to (count _builds - 1) do { _build = _builds select _i; _pos = getpos _build; _inmrkr = [_mkr,_pos] call fnc_InMarker; if (_inmrkr) then { if (typeOf _build in (_buildings_to_check_4)) then { _builds_in_mrkr set [count _builds_in_mrkr,_build]; _mrk = format ["%1", diag_ticktime]; _m = createMarkerLocal [_mrk, _pos]; _m setMarkerTypeLocal "mil_dot"; _m setMarkerColorLocal "colorRED"; _m setMarkerSizeLocal [1, 1]; }; }; sleep 0.01; }; The array _builds_in_mrkr will now only contain those types of buildings if they exist. The code is also placing markers at the locations of the buildings found to show what's going on. EDIT: I'm writing this just for you as a one off..... so rename the scripts, variables, etc... to whatever you want... I'm running out of original names for scripts! lol! Edited September 3, 2011 by twirly Added stuff Share this post Link to post Share on other sites
jakerod 254 Posted September 4, 2011 (edited) twirly said: Try this to find specific buildings using the stuff in my demo. Replace the call and the script buildInMarker.sqf.You have to add an array to the call of the types of buildings you want to find. Then I changed the script buildInMarker.sqf to:- The array _builds_in_mrkr will now only contain those types of buildings if they exist. The code is also placing markers at the locations of the buildings found to show what's going on. EDIT: I'm writing this just for you as a one off..... so rename the scripts, variables, etc... to whatever you want... I'm running out of original names for scripts! lol! I tried this but I could not get it working. This is what I have: I copied the actual script and named it "build_in_mark.sqf" I put the following in a radio alpha trigger: nul = ["mkr1",["Land_House_L_1_EP1","Land_House_L_3_EP1","Land_House_L_4_EP1"]] execVM "build_In_Mark.sqf"; I put a marker named mkr1 in around a village (located at the end of the road to the west of Chaman on Takistan) I hit the Radio Alpha trigger. No hint and no markers on the map. I'm wondering if it is because of: if (typeOf _build in (_buildings_to_check_4)) then { It might be because of the case sensitive requirement. That is the only thing I can think of. @galzohar- I tried what you said and it makes the hints work. The problem now though is that it turns it to a list of numbers in the last two hints and doesn't go back to letters. I tried changing the building class using the toarray but that didn't work either. Thanks for all your help guys! I wasn't expecting this part of it to be so difficult. Edited September 4, 2011 by Jakerod Share this post Link to post Share on other sites
galzohar 31 Posted September 4, 2011 (edited) Can you show exactly what you have done? If you convert an entire array to string, then "in" command obviously won't work... If you want to compare typeOf _x to a string you'll have to iterate over the array yourself (ex: with a forEach loop). Edited September 4, 2011 by galzohar Share this post Link to post Share on other sites
jakerod 254 Posted September 4, 2011 (edited) galzohar said: Can you show exactly what you have done? If you convert an entire array to string, then "in" command obviously won't work... If you want to compare typeOf _x to a string you'll have to iterate over the array yourself (ex: with a forEach loop). _target_object = _this select 0; _list = nearestObjects [player, ["building"], 1]; hint format ["%1", _list]; sleep 5; _strlist = str (_list); sleep 5; hint format ["%1", _strlist]; _strllist = tolower (_strlist); sleep 5; hint format ["%1", _strllist]; _arrlist = toarray (_strllist); sleep 5; hint format ["%1", _arrlist]; _lhl1s = toarray ("land_house_l_1_ep1"); sleep 5; hint format ["%1", _lhl1s]; I tried converting back to an array but I think it stays as a number. I Also tried turning the house name to an array although maybe it already is one at that point. Point being I was trying to make the numbers match up but I don't know how well that worked. Edited September 4, 2011 by Jakerod Share this post Link to post Share on other sites
galzohar 31 Posted September 4, 2011 Read again about the toArray command. It's mean for something completely different than what you are trying to do. In other words, it does not do anything that is even similar to what you seem to think it does, and has absolutely no use in your case. I still don't completely understand what you are trying to do... If you want to get an array of all buildings of a given class out of a list of objects/buildings, you can do: _classArray = ["Land_House_L_1_EP1", "Land_House_L_3_EP1"]; // or whatever _buildingArray = []; _buildingArrayCount = 0; { if ((typeOf _x) in _classArray) then { _buildingArray set [_buildingArrayCount, _x]; _buildingArrayCount = _buildingArrayCount+1; }; } forEach _list; player sideChat _buildingArray; //test Share this post Link to post Share on other sites
twirly 11 Posted September 4, 2011 (edited) The strings must match exactly. Try this... add the line in bold red to the buildInMarker script and run the code. Then look in your .rpt file and you will see all the building types (classnames) found in the marker. You have to use names chosen from these. if (_inmrkr) then { [b][color="Red"]diag_log format ["%1",typeOf _build];[/color][/b] if (typeOf _build in (_buildings_to_check_4)) then { _builds_in_mrkr set [count _builds_in_mrkr,_build]; _mrk = format ["%1", diag_ticktime]; _m = createMarkerLocal [_mrk, _pos]; _m setMarkerTypeLocal "mil_dot"; _m setMarkerColorLocal "colorRED"; _m setMarkerSizeLocal [1, 1]; }; }; Alternatively... look here and use these names. Classnames can also be found in this post here. Galzohars post also shows you how to filter the list. It's not that hard! Edited September 4, 2011 by twirly Clarity Share this post Link to post Share on other sites
galzohar 31 Posted September 4, 2011 Yes. If you don't want upper/lower case issues you don't even have to use toLower/toUpper, just get the correct classname from a proper classlist, or place a game logic near a building of said class and in its init line type: xx = typeOf (nearestBuilding this); hint xx; player sideChat xx; copyToClipboard xx; Share this post Link to post Share on other sites
jakerod 254 Posted September 5, 2011 twirly said: The strings must match exactly.Try this... add the line in bold red to the buildInMarker script and run the code. Then look in your .rpt file and you will see all the building types (classnames) found in the marker. You have to use names chosen from these. if (_inmrkr) then { [b][color="Red"]diag_log format ["%1",typeOf _build];[/color][/b] if (typeOf _build in (_buildings_to_check_4)) then { _builds_in_mrkr set [count _builds_in_mrkr,_build]; _mrk = format ["%1", diag_ticktime]; _m = createMarkerLocal [_mrk, _pos]; _m setMarkerTypeLocal "mil_dot"; _m setMarkerColorLocal "colorRED"; _m setMarkerSizeLocal [1, 1]; }; }; Alternatively... look here and use these names. Classnames can also be found in this post here. Galzohars post also shows you how to filter the list. It's not that hard! galzohar said: Yes. If you don't want upper/lower case issues you don't even have to use toLower/toUpper, just get the correct classname from a proper classlist, or place a game logic near a building of said class and in its init line type: xx = typeOf (nearestBuilding this); hint xx; player sideChat xx; copyToClipboard xx; That's what I have been doing. I've been using the classnames (with pictures) I found somewhere on the forum but it hasn't been working still. I have also been doing the whole nearestBuilding thing but maybe the typeOf aspect will help. I used galzohar's code and got the following: Quote Land_House_L_1_EP1 Well I was going to continue about how I tried that when I first started but it didn't work but now it seems to be working. I swear I copy and pasted that exact thing from the classlist name I had and it looked exactly like that. 99.9% sure with the .1% being the slight chance that I'm insane and that nothing around me is actually real. Alright, I will check and see if I can get the whole set-up working tomorrow then. Thanks again guys. Share this post Link to post Share on other sites
jakerod 254 Posted September 5, 2011 I take back what I said last night. It still doesn't work. Last night I accidentally used the method I used before which was working but didn't allow for multiple elements in an array. I tried using "in" this morning and it didn't work. The code is as follows: _target_object = _this select 0; _list = nearestObjects [player, ["building"], 1]; hint format ["%1", _list]; if ("Land_House_L_1_EP1" in _list) then {player setdamage 1}; I still think I have an option left that twirly gave me though so I will try that out when I get a chance. Share this post Link to post Share on other sites
twirly 11 Posted September 5, 2011 (edited) Does the hint return a list of buildings? EDIT:- If it does.... you will never find "Land_House_L_1_EP1" in there! You have to use typeOf with the items in the list for it to work. That's what you're not grasping. The light will eventually come on I'm sure!!!!:) Edited September 6, 2011 by twirly Share this post Link to post Share on other sites