Jump to content
Sign in to follow this  
DPM

Apply to all units

Recommended Posts

Does anybody know how can I get this script to apply to all units including AI, I've tried a few variations on allUnits. but I could only get it working on players again (with some unwanted sleep effects on start and stop)......

SwimFastScriptHandle = [] spawn {
  while {true} do {
    if ("AsswPercMrunSnonWnonDf" == AnimationState player) then {
      player setAnimSpeedCoef 1.6;
    } else {    
      if (isTouchingGround player) then {
        player setAnimSpeedCoef 1;
      };
    };
  };
};

Share this post


Link to post
Share on other sites

33 people an nobody knows the answer, is the question really that difficult, or does a swim slightly faster script offend mil sim principles that much?

  • Confused 3

Share this post


Link to post
Share on other sites

instead of 'player' try '_x' and then the 'forEach allunits'. finally encapsulating code in {}'s

 

example:

{_x setDamage 1} foreach allUnits

  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, froggyluv said:

instead of 'player' try '_x' and then the 'forEach allunits'. finally encapsulating code in {}'s

 

example:

{_x setDamage 1} foreach allUnits

 

 

Thanks for the reply, when I substituted "player setAnimSpeedCoef 1.6;" for  {_x setAnimSpeedCoef 1.6} foreach allUnits; The AI did speed up, but obviously they were triggered from the player's animation so they sped up on land too. I'm unable to change "AnimationState player" to get it to trigger on their own animation state like it does for just players. The only positive result I managed was  "{AnimationState _x} foreach allUnits" and it must be saying pretty much the same thing as  animationstate player as it gets exactly the same result.

Share this post


Link to post
Share on other sites

One way I see to make this work is to call a script for each individual AI unit you want to do that for, because you need to constantly check each unit where it is...

If you want to try that, create a file called swimFaster.sqf and add this:

Spoiler

params ["_unit"];
while {true} do {
	if ("AsswPercMrunSnonWnonDf" == AnimationState _unit) then {
		_unit setAnimSpeedCoef 1.6;
		} else {
			if (isTouchingGround _unit) then {
				_unit setAnimSpeedCoef 1;
			};
		};
};

 

And then in the unit init:

_script = [this] execVM "swimFaster.sqf";

 

There are a lot of ways of doing this: different, cleaner and better but this is a simple way,

Share this post


Link to post
Share on other sites
12 hours ago, Erwin23p said:

One way I see to make this work is to call a script for each individual AI unit you want to do that for, because you need to constantly check each unit where it is...

If you want to try that, create a file called swimFaster.sqf and add this:

  Reveal hidden contents


params ["_unit"];
while {true} do {
	if ("AsswPercMrunSnonWnonDf" == AnimationState _unit) then {
		_unit setAnimSpeedCoef 1.6;
		} else {
			if (isTouchingGround _unit) then {
				_unit setAnimSpeedCoef 1;
			};
		};
};

 

And then in the unit init:


_script = [this] execVM "swimFaster.sqf";

 

There are a lot of ways of doing this: different, cleaner and better but this is a simple way,

 

Thanks for the reply, this works fine, but unfortunately the AI it's needed for are spawned, not placed. I tried using ...

//description.ext

class Extended_InitPost_EventHandlers {

        class CAManBase {

                class initpost_units {

                       serverInit = "_this call compile preprocessFileLineNumbers 'swimFaster.sqf'";

                };

         };

};

....and turning it into a function following davidoss's instructions from this topic 
 


...and another method using a functions.hpp, but it just seemed to ignore the script. The first method with the description.ext seemed pretty straight forward enough, but I could've messed up the function attempts. Any idea how to execute it other than from inside a placed units init?


 

Share this post


Link to post
Share on other sites

For sure there is a way, but remember that the condition cycles for all units each frame in a zone or maybe the whole mission so find a way to limit the usage of this...

For example, if you want to make a damaged ship spawn units make only units near that ship or something like that.

Spoiler

while {true} do {
	{
		if ("AsswPercMrunSnonWnonDf" == AnimationState _x) then {
			_x setAnimSpeedCoef 1.6;
			} else {
				if (isTouchingGround _x) then {
					_x setAnimSpeedCoef 1;
				};
			};
	} forEach allUnits;
	sleep 1;
};

 

just add this to the init.sqf. I tried this and it's pretty laggy but it works, I recommend using another kind of condition, or maybe an array to limit the usage of this script, or raise the sleep to 5.

  • Thanks 1

Share this post


Link to post
Share on other sites

I don't know how to write code from scratch, but I made this script a couple of years ago from parts of 2 older scripts and then adding the isTouchingGround, it's usually getting used in the Escape mission on 10 players, so is it continually checking to see if the condition is true because it has no sleep added? For this AI version I was wanting to use it on 30 to 60 units halo dropping from a plane, changing the animation and speed coef to disable damage so they don't kill themselves on trees. (works on a player but  the swim version is easier to observe if it's working other units) So, after the initial drop will the script continue to check throughout the approx 45 minute mission duration causing unnecessary lag? Never noticed in Escape as that mission is very resource demanding as it is.

Share this post


Link to post
Share on other sites

You could make the script work on only the first minutes when the units are dropping, or if you wanna go advanced, make a script that detects if the unit is para dropping and activate the script and once the unit is on the ground, disable the script.

Share this post


Link to post
Share on other sites
15 minutes ago, Erwin23p said:

You could make the script work on only the first minutes when the units are dropping, or if you wanna go advanced, make a script that detects if the unit is para dropping and activate the script and once the unit is on the ground, disable the script.

 

while {true} do {
    {
        if ("Para_Pilot" == AnimationState _x) then {
            _x allowDamage false;
            } else {
                if (isTouchingGround _x) then {
                sleep 5;
                    _x allowDamage true;
                };
            };
    } forEach allUnits;
    sleep 1;
};

I'm presuming that if they land in a tree it's considered touching ground so the sleep 5 is there to give them a chance to get out of the tree before they can take damage again, what would I need to add to stop the script checking after 5 minutes?

Share this post


Link to post
Share on other sites

You could change the condition of the while loop.

//Before the loop:
_timer = 0;

//Loop condition:
_timer < 300

//After the sleep:
_timer = _timer + 1;

but, I suggest you use a spawn when the unit is touching ground, because you will mess with the timer.

   if (isTouchingGround _x) then {
   		[] spawn {
                    	sleep 5;
                        _x allowDamage true;
                };
            };

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Ok, I'll give it a go. Thanks for all your help (and froggyluv)  ...it's greatly appreciated.

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×