BEAKSBY 11 Posted July 24, 2014 HI Folks, I'm trying to get the soldier to get back in even if the player interrupts the while loop by getting in the turret (_gun1) by force. When the player exits then immediately gets back in, then soldier (_newUnit) stops his [_newUnit] orderGetIn true; and does not reattempt after the player gets out a second time. // order soldier out of StaticWeapon (_gun1), player gets in, and soldiers (_newUnit) stands-by to re-enter once player exits private ["_gun1","_newUnit","_guarddistance"]; // hint "HELLO!"; _gun1 = cursorTarget; _newUnit = gunner _gun1; _guarddistance = 0; hint format ["_gun1: %1 \n _newUnit: %2", typeOf _gun1, typeOf _newUnit]; [_newUnit] orderGetIn false; // soldier gets out waitUntil { (vehicle _newUnit) == _newUnit }; // (vehicle _newUnit) == _newUnit ) is true soldier when out of StaticWeapon _newUnit SetBehaviour "SAFE"; player action ["salute", _newUnit]; player assignAsGunner _gun1; sleep 1.75; player action ["getInGunner", _gun1]; sleep 0.5; // ensure AI remains within 10m original position while { ((vehicle player) != player) && alive player} do { // (vehicle player) != player is true when player is in StaticWeapon _guarddistance = _gun1 distance _newUnit; if (_guarddistance >= 10) then {_newUnit doMove getPos _gun1; _newUnit allowFleeing 0}; }; waitUntil { (alive player) && ((vehicle player) == player) }; // (vehicle player) == player is true when player is out of StaticWeapon _newUnit assignAsGunner _gun1; [_newUnit] orderGetIn true; Share this post Link to post Share on other sites
squeeze 22 Posted July 24, 2014 unassign the player Share this post Link to post Share on other sites
sxp2high 22 Posted July 24, 2014 Question is, where/how do you execute this whole thing? Also, please, don't use while loops without sleep for such things. It's very heavy on the engine. This is only OK, without sleep, for loops that run for a somewhat short period. OK: _count = 0; while {count < 100} do { _count = _count + 1; }; Bad: while {true} do { // Something }; Good: while {true} do { // Something sleep 0.1; }; Edit: I think I misunderstood your problem, Squeeze is correct :) Share this post Link to post Share on other sites
BEAKSBY 11 Posted July 25, 2014 (edited) I tried both unassignVehicle player; and [player] allowGetIn false; but the player can still get in a second time interrupting the process...I assume I'll need a while loop with some breakTo statements? waitUntil { (alive player) && ((vehicle player) == player) }; // (vehicle player) == player is true when player is out of StaticWeapon [player] allowGetIn false; //unassignVehicle player; _newUnit assignAsGunner _gun1; [_newUnit] orderGetIn true; waitUntil { (alive _newUnit) && ((vehicle _newUnit) == _newUnit) }; [player] allowGetIn true; I tried with a breakTo loop but the _newUnit does not move afterwards and hint does not execute. // ensure _newUnit remains within 10m original _gun1 or GetIn when player exits _gun1 scopeName "main"; while {((vehicle player) != player) && (alive player)} do { // true when player is in StaticWeapon hint format["currentCommand %1",currentCommand _newUnit ]; _guarddistance = _gun1 distance _newUnit; if (_guarddistance >= 10) then {_newUnit doMove getPos _gun1; _newUnit allowFleeing 0}; scopeName "loop1"; while {(alive player) && ((vehicle player) == player) } do { // true when player is out of StaticWeapon _newUnit assignAsGunner _gun1; [_newUnit] orderGetIn true; scopeName "loop2"; if (((vehicle player) != player) && alive player) then {breakTo "main"}; // Breaks all scopes and return to "main" if ((alive _newUnit) && ((vehicle _newUnit) == _newUnit)) exitWith {}; // Breaks scope named "loop2" // true when _newUnit is in StaticWeapon ///sleep 1; }; //sleep 1; }; Edited July 25, 2014 by BEAKSBY Share this post Link to post Share on other sites
squeeze 22 Posted July 25, 2014 this would be better then awhile loop _vehicle addEventHandler ["GetOut", {unassignVehicle (_this select 2)}]; Share this post Link to post Share on other sites
BEAKSBY 11 Posted July 25, 2014 this would be better then awhile loop_vehicle addEventHandler ["GetOut", {unassignVehicle (_this select 2)}]; I tried EVHs but the AI soldiers takes off and does not maintain _guarddistance and does not get back in when the player triggers EVH GetOut. _gun1 addEventHandler ["GetIn", {if ((_this select 2) == player) then { //true when player is in StaticWeapon _guarddistance = _gun1 distance _newUnit; if (_guarddistance >= 10) then {_newUnit doMove getPos _gun1; _newUnit allowFleeing 0}; hint format ["currentCommand %1",currentCommand _newUnit ]; }; }]; _gun1 addEventHandler ["GetOut", {if ((_this select 2) == player) then { //true when player is out of StaticWeapon _newUnit assignAsGunner _gun1; [_newUnit] orderGetIn true; }; }]; Share this post Link to post Share on other sites
squeeze 22 Posted July 25, 2014 if you placed your statics in the editor you put the EventHandler in the init field, this addEventHandler ["GetOut", {unassignVehicle (_this select 2)}]; if you createVehicle the statics then it's like my 2nd post then use your 1st code you posted, looks like a good start Share this post Link to post Share on other sites