Tiger51 3 Posted May 3, 2020 Hi all, I need some help. I am on this code sine 1 week, and l looking for solutions but hier i dont understand. So, this code is called by a trigger on act : null = execVM "inf3.sqf"; hint "lets do it!" I want to spawn a groupe of IA and when players are about 250 meters IA move to players. The code : Quote _chasseurs = createGroup east; _player = position player; _unit20 = _chasseurs createUnit ["O_G_Soldier_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit30 = _chasseurs createUnit ["O_G_Soldier_lite_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit40 = _chasseurs createUnit ["O_G_medic_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit50 = _chasseurs createUnit ["O_G_Soldier_LAT_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit60 = _chasseurs createUnit ["O_G_officer_F", getMarkerPos "inf500", [], 0, "FORM"]; _loups100 = [_unit20, _unit30, _unit40, _unit50, _unit60]; waituntil {sleep 1; ({isPlayer _x AND alive _x AND (_x distance _loups100) <= 250} count playableUnits) !=0}; _loups100 doMove _player; But nothing happen even if i am near IA. IA spawn but dont move even if i change distance value to 1500. I dont understand where i am wrong. Any Ideas? Share this post Link to post Share on other sites
gc8 977 Posted May 3, 2020 _loups100 is where I see the problem, it's array of units while it should be a position Share this post Link to post Share on other sites
Tiger51 3 Posted May 3, 2020 Thanks for reply @gc8. If i delete this line : Quote waituntil {sleep 1; ({isPlayer _x AND alive _x AND (_x distance _loups100) <= 250} count playableUnits) !=0}; IA move to player. Edit : i understand what you mean. Share this post Link to post Share on other sites
Tiger51 3 Posted May 3, 2020 I modify the code like this : Quote _chasseurs = createGroup east; _player = position player; _unit20 = _chasseurs createUnit ["O_G_Soldier_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit30 = _chasseurs createUnit ["O_G_Soldier_lite_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit40 = _chasseurs createUnit ["O_G_medic_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit50 = _chasseurs createUnit ["O_G_Soldier_LAT_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit60 = _chasseurs createUnit ["O_G_officer_F", getMarkerPos "inf500", [], 0, "FORM"]; _loups100 = [_unit20, _unit30, _unit40, _unit50, _unit60]; _pos = getMarkerPos "inf500"; waituntil {sleep 1; ({isPlayer _x AND alive _x AND (_x distance _pos) <= 2200} count playableUnits) !=0}; _loups100 doMove _player; It does not work anymore. Any other idea? Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted May 3, 2020 22 minutes ago, Tiger51 said: I modify the code like this : It does not work anymore. Any other idea? This won't really work in MP and due to logical errors, since there's no "player" in MP, at least on dedicated. Depends on if you're on dedicated or locally hosted MP, or on SP, needs an individual solution in any case. Also no need for _loups100 array in the first place, unless you need it somewhere else. Something like this might do the trick: _chasseurs = createGroup east; _pos = getMarkerPos "inf500"; _unit20 = _chasseurs createUnit ["O_G_Soldier_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit30 = _chasseurs createUnit ["O_G_Soldier_lite_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit40 = _chasseurs createUnit ["O_G_medic_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit50 = _chasseurs createUnit ["O_G_Soldier_LAT_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit60 = _chasseurs createUnit ["O_G_officer_F", getMarkerPos "inf500", [], 0, "FORM"]; _approach = [_chasseurs,_pos] spawn { params ["_grp","_pos"]; leader _grp globalChat "Waiting"; _validTargets = []; waituntil { sleep 1; _validTargets = (playableUnits select {isPlayer _x AND alive _x AND (_x distance _pos) <= 2200});systemchat str _validTargets; count _validTargets > 0 }; _target = _validTargets#0; leader _grp globalChat format ["Engaging %1!",name _target]; _grp move getPosATL _target; }; You can use _chasseurs, since this is already the group, to issue the move order. No need to give move orders to individual units. To test this in SP you'd need to replace playableUnits with allPlayers or similar. Cheers Share this post Link to post Share on other sites
Tiger51 3 Posted May 3, 2020 Thanks @Grumpy Old Man I paste and copy your code but nothing happen. I would like the code work in MP. I have the message "waiting" but IA still stay in their original position. What i miss? EDIT : Under editor i write this and work : Quote _chasseurs = createGroup east; _pos = getMarkerPos "inf500"; _unit20 = _chasseurs createUnit ["O_G_Soldier_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit30 = _chasseurs createUnit ["O_G_Soldier_lite_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit40 = _chasseurs createUnit ["O_G_medic_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit50 = _chasseurs createUnit ["O_G_Soldier_LAT_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit60 = _chasseurs createUnit ["O_G_officer_F", getMarkerPos "inf500", [], 0, "FORM"]; _approach = [_chasseurs,_pos] spawn { params ["_grp","_pos"]; leader _grp globalChat "Waiting"; _validTargets = []; waituntil { sleep 1; _validTargets = (allPlayers select {isPlayer _x AND alive _x AND (_x distance _pos) <= 2200});systemchat str _validTargets; count _validTargets > 0 }; _target = _validTargets#0; leader _grp globalChat format ["Engaging %1!",name _target]; _grp move getPosATL _target; }; So if i want this code to work in MP i will change with the other variable. Thanks. Share this post Link to post Share on other sites
pierremgi 4886 Posted May 3, 2020 That's probably because you test your code in preview SP, so playableunits = []; For SP & MP work use playableUnits + switchableUnits. You can use also allPlayers if you don't want all non-played AI slots. if isServer then { private _chasseurs = createGroup east; private _pos = getMarkerPos "inf500"; private _unit20 = _chasseurs createUnit ["O_G_Soldier_F", getMarkerPos "inf500", [], 0, "FORM"]; private _unit30 = _chasseurs createUnit ["O_G_Soldier_lite_F", getMarkerPos "inf500", [], 0, "FORM"]; private _unit40 = _chasseurs createUnit ["O_G_medic_F", getMarkerPos "inf500", [], 0, "FORM"]; private _unit50 = _chasseurs createUnit ["O_G_Soldier_LAT_F", getMarkerPos "inf500", [], 0, "FORM"]; private _unit60 = _chasseurs createUnit ["O_G_officer_F", getMarkerPos "inf500", [], 0, "FORM"]; private _approach = [_chasseurs,_pos] spawn { params ["_grp","_pos"]; leader _grp globalChat "Waiting"; private _validTargets = []; waituntil { sleep 1; _validTargets = (allPlayers select {alive _x && (_x distanceSqr _pos) <= 4840000}); !(_validTargets isEqualTo []) }; systemChat str _validTargets; private _target = _validTargets#0; leader _grp globalChat format ["Engaging %1!",name _target]; _grp move getPosATL _target; }; }; Whatever array you are using, if you run this code when some players/playable/switchable are already within the area, the array can have more than one element. If you want to engage the nearest one, after the waitUntil: _validTargets = _validTargets apply {[_x distanceSqr _pos,_x]}; _validTargets sort TRUE; _target = _validTargets #0#1; It's useless if you are sure to run the code, creating the OPFOR far enough the players/playable/switchable because there is a few chance two players meet the condition within the 1 second of waitUntil. Share this post Link to post Share on other sites
Tiger51 3 Posted May 3, 2020 Thanks for your help all. @pierremgi if i want to test my code in Host (under editor) and MP, what i have to write instead of : Quote _validTargets = (allPlayers select..... Something like this : Quote _validTargets = (allPlayers select && playableUnits select {isPlayer _x AND alive _x AND (_x distance _pos) <= 2200}); ? I will never find the solution, if you dont help me. So i would like to understand the logic. The value "_approach" and "_validTargets" are in the Arma 3 code? What mean private? When do i use the code "spawn" ? What is mean for the game? I find a lot of informations hier, so for those who are interessted by the code without IA in game speak : Quote _chasseurs = createGroup east; _pos = getMarkerPos "inf500"; _unit20 = _chasseurs createUnit ["O_G_Soldier_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit30 = _chasseurs createUnit ["O_G_Soldier_lite_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit40 = _chasseurs createUnit ["O_G_medic_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit50 = _chasseurs createUnit ["O_G_Soldier_LAT_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit60 = _chasseurs createUnit ["O_G_officer_F", getMarkerPos "inf500", [], 0, "FORM"]; _approach = [_chasseurs,_pos] spawn { params ["_grp","_pos"]; _validTargets = []; waituntil { sleep 1; _validTargets = (allPlayers select {isPlayer _x AND alive _x AND (_x distance _pos) <= 2200}); count _validTargets > 0 }; _target = _validTargets#0; _grp move getPosATL _target; }; For SP in editor, For MP : Quote _chasseurs = createGroup east; _pos = getMarkerPos "inf500"; _unit20 = _chasseurs createUnit ["O_G_Soldier_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit30 = _chasseurs createUnit ["O_G_Soldier_lite_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit40 = _chasseurs createUnit ["O_G_medic_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit50 = _chasseurs createUnit ["O_G_Soldier_LAT_F", getMarkerPos "inf500", [], 0, "FORM"]; _unit60 = _chasseurs createUnit ["O_G_officer_F", getMarkerPos "inf500", [], 0, "FORM"]; _approach = [_chasseurs,_pos] spawn { params ["_grp","_pos"]; _validTargets = []; waituntil { sleep 1; _validTargets = (playableUnits select {isPlayer _x AND alive _x AND (_x distance _pos) <= 2200}); count _validTargets > 0 }; _target = _validTargets#0; _grp move getPosATL _target; }; Share this post Link to post Share on other sites
pierremgi 4886 Posted May 3, 2020 playableUnits returns [] in SP and the playable slots in MP, except if you disable the AIs in lobby. Ifyou do so, playableUnits = allPlayers (MP); switchableUnits = [] in MP and all the switchable units as edited in SP This is true for preview/played, hosted/dedicated server So: (playableUnits + switchableUnits) select {isPlayer _x && alive _x && (_x distanceSqr _pos) <= 4840000}); will do the same job as : allPayers in MP, the player in SP (due to the isPlayer condition). Share this post Link to post Share on other sites
Tiger51 3 Posted July 12, 2020 Thanks for reply @pierremgi Mieux vaut tard, que jamais ^^ 1 Share this post Link to post Share on other sites