Jump to content
gingerlikeme

Make Dog Follow Player HELP

Recommended Posts

Hello,

 

I'm trying to make a dog follow the player in my mission. However it doesn't seem to work.

 

In the spoiler is the script I've made. 

 

There are comments on it for you to understand more....

 

_Dog setVariable ["BIS_fnc_animalBehaviour_disable", true]; // Disables the ARMA 3 Default Animal Behaviour
_DogAlreadySpawned = 0; // Variable to see if the dog has already been spawned
_DogHandler = player; // Variable that defines the _DogHandler as the player
_dogGroup = createGroup west; // Creates a group for the Dog to join later and the player to join now
_chance = floor (random [0,875,1750]); // Makes a random number to depend what dog model spawns
[_DogHandler] joinSilent _dogGroup; // Adds the player to the group
if (playerSide == WEST) then // Only works on BluFor
{
 
 if (_DogAlreadySpawned == 0) then // Quick check to see if the dog has already been spawned
 {
  if ((_chance < 250) and (_chance > 0)) then
  {
   _Dog = createAgent ["Fin_sand_F", getPos player, [], 5, "CAN_COLLIDE"];
  };
  if ((_chance < 500) and (_chance > 250)) then
  {
   _Dog = createAgent ["Fin_blackwhite_F_F", getPos player, [], 5, "CAN_COLLIDE"];
  };
  if ((_chance < 750) and (_chance > 500)) then
  {
   _Dog = createAgent ["Fin_random_F", getPos player, [], 5, "CAN_COLLIDE"];
  }; 
  if ((_chance < 1000) and (_chance > 750)) then
  {
   _Dog = createAgent ["Fin_tricolour_F", getPos player, [], 5, "CAN_COLLIDE"];
  };
  if ((_chance < 1250) and (_chance > 1000)) then
  {
   _Dog = createAgent ["Alsatian_Sandblack_F", getPos player, [], 5, "CAN_COLLIDE"];
  }; 
  if ((_chance < 1500) and (_chance > 1250)) then
  {
   _Dog = createAgent ["Alsatian_Sand_F", getPos player, [], 5, "CAN_COLLIDE"];
  };
  if ((_chance < 1750) and (_chance > 1500)) then
  {
   _Dog = createAgent ["Alsatian_Black_F", getPos player, [], 5, "CAN_COLLIDE"];
  }; // Checks the chance and if chance is between a range spawn the dog model
  
  _Dog setDir getDir player; // Set the Dog Model to face the player
  [_Dog] joinSilent _DogGroup; // Adds the dog to the group
  
  while {alive _Dog} do
  {
   _pos = [(getPos player select 0) + (1 * sin (getDir player)), (getPos player select 1) + (0.3 * cos (getDir player)), 0];
   _Dog doMove _pos;
  }; // While the dog is alive get it to follow the player
        {
            if ((_Dog distance2D _x) < 10) then
            {
                if (weapons player != []) then
    {
     playSound3D ["A3\Sounds_F\sfx\blip1.wav", _Dog, true, _Dog, 7, 1, 50];
     _Dog playMoveNow "Dog_Idle_Bark";    
    }; 
            };
        } foreach playableUnits; // Get the dog to go into barking if a player has a gun within 10 meters
 };
} else {
 _DogAlreadySpawned = 1;
 diag_log "Player Already Has A Dog";
 hint "You Already Have A Police Dog";
};

 

Thanks in Advance,

Harry

Share this post


Link to post
Share on other sites
6 hours ago, gingerlikeme said:

solved

 

Hello there gingerlikeme !

 

By saying solved , you mean that the code in the first post is working?

Thanks !

  • Like 1

Share this post


Link to post
Share on other sites
33 minutes ago, gingerlikeme said:

I solved the issue.

 

Since you post the question for help, can you post the solution as well?

  • Like 8

Share this post


Link to post
Share on other sites

@gingerlikeme yea. posting the solution is not only editing forums etiquette for its own sake but also solves a purpose which is to create some type of encyclopedia of problems and their solutions here. this is the main advantage over something like discord where things are very momentary and come up over and over while here you can search through a rich history of discussions and often find the solution to your problem in no time without the need of discussion.

 

sometimes a thread from arma 2 days might even solve your problem. it's a beautiful thing that we should keep going.

  • Like 7

Share this post


Link to post
Share on other sites

_dog = createAgent ["Alsatian_Random_F", getPos player, [], 5, "CAN_COLLIDE"];
_range = 3;
_dog setVariable ["BIS_fnc_animalBehaviour_disable", true];

dog = _Dog;

_DogOut = 0;
If (_DogOut == 0) then {
 0 = [_dog] spawn {;
  _dog playMove "Dog_Run";
  
  PackUpDogAction = player addAction ["Put Away Police Dog", "Dog playMoveNow "Dog_Die_Sit"; deleteVehicle Dog; player removeAction PackUpDogAction;"];
  
  while {alive _dog} do
  {  
   _nearbyWithWeapon = (allUnits inAreaArray [ASLtoAGL getPosASL _dog, 10, 10, 0, false, 10]) apply { primaryWeapon _x } select { _x != "" };
   _dog moveTo getPos player;
   sleep 1;     
   if (count _nearbyWithWeapon > 0) then {
    playSound3D ["a3\sounds_f\ambient\animals\dog1.wss", dog, false, getPosASL dog , 6, 0.8, 0]
    _Dog playMoveNow "Dog_Idle_Bark";
   }else{
    _Dog playMoveNow "Dog_Run";
    _dog moveTo getPos player;
   }
  };
 };
}else{
 ["You Already Have A Police Dog Active", "IRPColor", 5] call Catraz_fnc_notification_system;
};

  • Like 2
  • Thanks 2

Share this post


Link to post
Share on other sites
8 hours ago, gingerlikeme said:

You Already Have A Police Dog

 

Thank you very much gingerlikeme !   :f:

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

×