id_steacie 0 Posted April 13, 2017 I am trying to get a function to spawn from the init box of a logic unit that is created in front of about a dozen select enemy soldiers in a base. The idea is that the logic unit has a virtual box around it that set the players captive status from true to false to simulate an AI vision cone. The issue I am having is that the way the script is written is such that once it is called it spawns this logic unit for all units assigned to a given side. This isn't ideal because the stealth segment is only one objective in the whole mission and calling the stealth script has the effect of permanently handicapping all OPFOR in the entire operation. Since I haven't been able to figure out how to get the code to delete the logic units properly and return the AI to full "intelligence" I was hoping to just assign the function to certain units. I just can't seem to figure out how to get the array to work properly. The original code is: _enemyArray = []; _i = 0; {if (side _x == east) then {_enemyArray set [_i, _x]; _i = _i + 1};} forEach allUnits; _center = createCenter sideLogic; _group = createGroup _center; player setCaptive true; for "_j" from 0 to (count _enemyArray) - 1 step 1 do { "Logic" createUnit [position (_enemyArray select _j), _group, "this AttachTo [(_enemyArray select _j), [0,25,0.5]]; _anythi = [_enemyArray select _j, this] spawn _fex_fnc_patrol;"]; sleep 0.1; }; As you can see all the units on side == east are assigned an index in the array and then all of those index's have a logic unit spawned at a specific offset which then calls the function from it's init box. I figured that simply removing lines 2 and 3, which index all units from the opfor side in the array, then change the code to this: _enemyArray = [patrol1, patrol2, patrol3, patrol4, patrol5, patrol6, sentry1, sentry2, sentry3]; _center = createCenter sideLogic; _group = createGroup _center; for "_j" from 0 to 9 do {player setCaptive true; "Logic" createUnit [position (_enemyArray select _j), _group, "this AttachTo [(_enemyArray select _j), [0,14,0.5]]; _anythi = [_enemyArray select _j, this] spawn _fex_fnc_patrol;"]; sleep 0.1; }; would work. Unfortunately what seems to happen is that either the logic unit does not spawn at all which results in the player being permanently set to captive of the code throws an error that the "Logic" createUnit command requires 3 elements and I provided 0. Im super confused, can anyone help?? Share this post Link to post Share on other sites
pierremgi 4857 Posted April 13, 2017 First, disregard createCenter, createGroup, logic... Just use bis_fnc_spawnGroup. Then I don't clearly understand the "AI vision cone", as far as there is no cone in your script, but you don't need to "attach" anything. Just consider the distance between an AI and a player. If necessary, you can limit the intended behavior (captive false?) to an angle referring to AI's direction. Or, like you seemed to do, define a "spot" in front of the AI by an offset vector. Share this post Link to post Share on other sites
id_steacie 0 Posted April 13, 2017 Sorry I didnt include the whole script as its rather long i only included the part that selects the units on which to call the function _fex_fnc_patrol. The whole script reads like this: _fex_fnc_patrol = { _soldier = _this select 0; _logic = _this select 1; while {!alarm && triggeractivated stealth} do { _posx = position _logic select 0; _posy = position _logic select 1; _areadir = getDir _soldier + 45; _position = position player; _areax = 10; _areay = 10; _difx = (_position select 0)- _posx; _dify = (_position select 1) - _posy; _dir = aTan (_difx / _dify); if (_dify < 0) then {_dir = _dir + 180;}; _relativedir = _areadir - _dir; _adis = abs(_areax / cos (90 - _relativedir)); _bdis = abs (_areay / cos _relativedir); _borderdis = _adis Min _bdis; _positiondis = _position distance _logic; if (_positiondis < _borderdis) then { _ins = lineIntersectsSurfaces [ eyePos player, eyePos _soldier, player, _soldier, true, 1, "GEOM", "NONE" ]; if (isNil {_ins select 0}) then { alarm = true; player setCaptive false; hint "He's inside the area."; {if (side _x == east) then { _px = ((position player select 0) + (Random (15)) - 30); _py = ((position player select 1) + (Random (15)) - 30); _x move [_px, _py,0];}} forEach AllUnits; {if (side _x == sideLogic) then {deleteVehicle _x}} forEach AllUnits; sleep 40; if (alarm) exitWith {alarm = false; _again = [] execVm "stealthscript.sqf";}; } else { hint "He's inside, but hidden"; }; } else { hint "He's outside."; }; sleep 0.5; }; }; _enemyArray = [patrol1, patrol2, patrol3, patrol4, patrol5, patrol6, sentry1, sentry2, sentry3]; _center = createCenter sideLogic; _group = createGroup _center; for "_j" from 0 to 9 do {player setCaptive true; "Logic" createUnit [position (_enemyArray select _j), _group, "this AttachTo [(_enemyArray select _j), [0,14,0.5]]; _anythi = [_enemyArray select _j, this] spawn _fex_fnc_patrol;"]; sleep 0.1; }; I found it in a sample mission from a youtube video and am trying to adapt it to my use. Unfortunately, since i didnt write it myself I dont fully understand exactly how to manipulate it. Essentially whats supposed to happen is a square logic unit is spawned in front of each enemy within which the players set captive status is set to true. Outside the square the players capture status is set to false to represent a cone of vision. Its not ideal but should work in certain highly specific circumstances. I'm just having trouble getting it to apply only to specific units at a specific time. IE only the units in a certain base and only at night when the player is present. Share this post Link to post Share on other sites
id_steacie 0 Posted April 13, 2017 So small update. I've had some success by changing the way the player is detected from setCaptive to AI behaviour. IE rather than the player being set captive then not set captive when they enter the vision cone the AI is set to careless then changed to combat when the player is in the vision zone. I also realized why it seemed like the script applied to all units was because setcaptive is linked to the player not the AI so by having the script set the player captive meant that no unit would shoot him. I think. Now It's just the usual issues of trying to get the AI out of combat mode back to safe or careless. Share this post Link to post Share on other sites