Home   Help Search Login Register  

Author Topic: Help with dofollow Hoz script please  (Read 2609 times)

0 Members and 1 Guest are viewing this topic.

Offline CaptainBravo

  • Members
  • *
Help with dofollow Hoz script please
« on: 28 Aug 2010, 12:05:42 »
Hey everyone,

I am using a dofollow script made by Hoz and it workds great till the followed (leader) gets shot.

Anyway of making the follower follow group leader instead of just one unit?

Here is the script code below:
Code: [Select]
/*
Do Follow other Unit example - Hoz 01/02/07 / Updated August 2007
Set Hoz_ReleaseUnit to false in some other location to stop the following.
Usage: dummy = [Follower,Leader] execVM DoFollowUnit.sqf
v.4
*/
_Hoz_Follower = _this select 0;
_Hoz_Leader = _this select 1;
Hoz_ReleaseUnit = true;
_Hoz_LongDist = 150;

if !(leader _Hoz_Follower == _Hoz_Follower) then
{
  [_Hoz_Follower] join grpNull;
};

_leftc = 0;
_leftg = 0;
_leftk = 0;
_leftd = 0;
_assigned = 0;


while {(alive _Hoz_Follower) && (alive _Hoz_Leader) && Hoz_ReleaseUnit}do
{

// If unit gets too far behind then wait until the follower is closer.

   waitUntil {_Hoz_Follower distance _Hoz_Leader < _Hoz_LongDist};

   if (vehicle _Hoz_Leader != _Hoz_Leader) then
   {
      _Hoz_VehicleTmp = vehicle _Hoz_Leader;

      _leftc = _Hoz_VehicleTmp emptyPositions "cargo";
      _leftg = _Hoz_VehicleTmp emptyPositions "Gunner";
      _leftk = _Hoz_VehicleTmp emptyPositions "Commander";
      _leftd = _Hoz_VehicleTmp emptyPositions "Driver";

      hint format["%1 %2 %3 %4", _leftc, _leftg, _leftk, _leftd];


      for [{_i = 0},{_i != count units group _Hoz_Follower},{_i = _i + 1}] do
      {
         if (_i < _leftc) then
         {
            (units group _Hoz_Follower select _i) assignAsCargo _Hoz_VehicleTmp;
            _assigned = _assigned + 1;
         };

         if ((_i >= _leftc) && (_i < (_leftc + _leftg))) then
         {
            (units group _Hoz_Follower select _i) assignAsGunner _Hoz_VehicleTmp;
            _assigned = _assigned + 1;
         };

         if ((_i >= (_leftc + _leftg)) && (_i < (_leftc + _leftg + _leftk))) then
         {
            (units group _Hoz_Follower select _i) assignAsCommander _Hoz_VehicleTmp;
            _assigned = _assigned + 1;
         };

         if ((_i >= (_leftc + _leftg + _leftk)) && (_i < (_leftc + _leftg + _leftk + _leftd))) then
         {
            (units group _Hoz_Follower select _i) assignAsDriver _Hoz_VehicleTmp;
            _assigned = _assigned + 1;
         };
      };    
      (units group _Hoz_Follower) orderGetIn true;
      while {vehicle _Hoz_Leader != _Hoz_Leader} do
      {
         group _Hoz_Follower move [(getpos vehicle _Hoz_Leader select 0) + ((random(10))*sin(getdir vehicle _Hoz_Leader - 180)), (getpos vehicle _Hoz_Leader select 1) + ((random(7))*cos(getdir vehicle _Hoz_Leader - 180))];
         sleep 2.5;
      };
      {unassignVehicle _x} forEach units group _Hoz_Follower;
   };

   if ((_Hoz_Follower distance _Hoz_Leader) < 10) then
   {
      sleep 2;
   }
   else
   {
      group _Hoz_Follower move [(getpos vehicle _Hoz_Leader select 0) + ((random(10))*sin(getdir vehicle _Hoz_Leader - 180)), (getpos vehicle _Hoz_Leader select 1) + ((random(7))*cos(getdir vehicle _Hoz_Leader - 180))];
      sleep 2.5;
   };
};



Thanks for your help.


« Last Edit: 05 Sep 2010, 06:58:20 by h- »

Offline CaptainBravo

  • Members
  • *
Re: Help with dofollow Hoz script please
« Reply #1 on: 03 Sep 2010, 23:32:47 »
Does anyone check these forumes anymore  ???

Offline Zipper5

  • BIS Team
  • ****
Re: Help with dofollow Hoz script please
« Reply #2 on: 03 Sep 2010, 23:47:38 »
Um... I'm not entirely sure, but...

You could add a check to see if the leader's been killed, and if he has, then execute the script for the new leader. To do this you would need to name the group something, like ldrGrp. I.E.
Code: [Select]
ldrGrp = (group _Hoz_Leader);

while {true} do {
if (!(alive _Hoz_Leader)) then {
null = [_Hoz_Follower, (leader ldrGrp)] execVM "DoFollowUnit.sqf"
};
};
It's definitely a very basic solution, but I think it would work. Probably the best person to comment on this is the maker himself, hoz.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Help with dofollow Hoz script please
« Reply #3 on: 04 Sep 2010, 08:24:49 »
Or, you could make it so that instead of the unit following one certain person, it'd simply always follow the leader of a group. To wit:

Code: [Select]
/*
Do Follow other Unit example - Hoz 01/02/07 / Updated August 2007
Set Hoz_ReleaseUnit to false in some other location to stop the following.
Usage: dummy = [Follower,Leader] execVM DoFollowUnit.sqf
v.4
*/
_Hoz_Follower = _this select 0;
_Hoz_LeaderGrp = _this select 1;
Hoz_ReleaseUnit = true;
_Hoz_LongDist = 150;

if !(leader _Hoz_Follower == _Hoz_Follower) then
{
  [_Hoz_Follower] join grpNull;
};

_leftc = 0;
_leftg = 0;
_leftk = 0;
_leftd = 0;
_assigned = 0;


while {(alive _Hoz_Follower) && Hoz_ReleaseUnit}do
{
_Hoz_Leader = leader _Hoz_LeaderGrp;

// If unit gets too far behind then wait until the follower is closer.

   waitUntil {_Hoz_Follower distance _Hoz_Leader < _Hoz_LongDist};

   if (vehicle _Hoz_Leader != _Hoz_Leader) then
   {
      _Hoz_VehicleTmp = vehicle _Hoz_Leader;

      _leftc = _Hoz_VehicleTmp emptyPositions "cargo";
      _leftg = _Hoz_VehicleTmp emptyPositions "Gunner";
      _leftk = _Hoz_VehicleTmp emptyPositions "Commander";
      _leftd = _Hoz_VehicleTmp emptyPositions "Driver";

      hint format["%1 %2 %3 %4", _leftc, _leftg, _leftk, _leftd];


      for [{_i = 0},{_i != count units group _Hoz_Follower},{_i = _i + 1}] do
      {
         if (_i < _leftc) then
         {
            (units group _Hoz_Follower select _i) assignAsCargo _Hoz_VehicleTmp;
            _assigned = _assigned + 1;
         };

         if ((_i >= _leftc) && (_i < (_leftc + _leftg))) then
         {
            (units group _Hoz_Follower select _i) assignAsGunner _Hoz_VehicleTmp;
            _assigned = _assigned + 1;
         };

         if ((_i >= (_leftc + _leftg)) && (_i < (_leftc + _leftg + _leftk))) then
         {
            (units group _Hoz_Follower select _i) assignAsCommander _Hoz_VehicleTmp;
            _assigned = _assigned + 1;
         };

         if ((_i >= (_leftc + _leftg + _leftk)) && (_i < (_leftc + _leftg + _leftk + _leftd))) then
         {
            (units group _Hoz_Follower select _i) assignAsDriver _Hoz_VehicleTmp;
            _assigned = _assigned + 1;
         };
      };   
      (units group _Hoz_Follower) orderGetIn true;
      while {vehicle _Hoz_Leader != _Hoz_Leader} do
      {
         group _Hoz_Follower move [(getpos vehicle _Hoz_Leader select 0) + ((random(10))*sin(getdir vehicle _Hoz_Leader - 180)), (getpos vehicle _Hoz_Leader select 1) + ((random(7))*cos(getdir vehicle _Hoz_Leader - 180))];
         sleep 2.5;
      };
      {unassignVehicle _x} forEach units group _Hoz_Follower;
   };

   if ((_Hoz_Follower distance _Hoz_Leader) < 10) then
   {
      sleep 2;
   }
   else
   {
      group _Hoz_Follower move [(getpos vehicle _Hoz_Leader select 0) + ((random(10))*sin(getdir vehicle _Hoz_Leader - 180)), (getpos vehicle _Hoz_Leader select 1) + ((random(7))*cos(getdir vehicle _Hoz_Leader - 180))];
      sleep 2.5;
   };
};

Now, it would be called:

nul = [follower, leadergroup] execvm "DoFollowUnit.sqf"

So for instance, [dummy1, (group dude1)] execvm "DoFollowUnit.sqf"

At the beginning of each run-through of the main while...do loop, it updates _Hoz_Leader to be the current leader of the group you designated when calling the script. Untested, but it should work :)

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline CaptainBravo

  • Members
  • *
Re: Help with dofollow Hoz script please
« Reply #4 on: 05 Sep 2010, 14:13:54 »
Thanks Wolfrug for your response. I have tried it but for some reason the follower is still not following the new leader of the grp. I will post the sample mission.

Thanks.

Offline ZapBrannigan

  • Members
  • *
Re: Help with dofollow Hoz script please
« Reply #5 on: 05 Sep 2010, 23:25:36 »
I would just set Hoz_ReleaseUnit  to false when the leader dies then exit the script and run it again. that should make them start following the new leader.

or not even check if the leader dies, just set a count in the script for like 20 seconds and each time it gets to zero make it exit and rerun the script.