Author Topic: animals  (Read 427 times)

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
animals
« on: July 21, 2011, 05:34:56 am »


                I would like my chickens and cows to roam around .onspawn ? I guess if you could wind me up and point me in the right direction.    Much appreciated.
               
               

               


                     Modifié par Knight_Shield, 21 juillet 2011 - 04:36 .
                     
                  


            

Legacy_Mad.Hatter

  • Full Member
  • ***
  • Posts: 156
  • Karma: +0/-0
animals
« Reply #1 on: July 21, 2011, 05:44:03 am »


               http://www.nwnlexico...randomwalk.html
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
animals
« Reply #2 on: July 21, 2011, 05:59:20 am »


               ActionRandom walk is good suggestion, but you also wont want to roam whole area so the way to go is to make trigger which will tell the chicken to go at spawn point if she tries to exit the trigger.

Or easiest solution is to set the chicken walk waypoints, (click on chicken, and then right click at location and use one choice, cant remember the name atm but it will make a waypoint, then the chicken will go from spawn at those waypoints in order you made then and after she walk last then she return to the spawn point again.
               
               

               
            

Legacy_Morbane

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-0
animals
« Reply #3 on: July 21, 2011, 09:33:46 am »


               Usually the randomwalk function would be placed in the heartbeat - so in effect the random direction is rechosen every 6 seconds - the chicken will not get far before changing path. But potentially they can actually roam anywhere.
               
               

               


                     Modifié par Morbane, 21 juillet 2011 - 08:34 .
                     
                  


            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
animals
« Reply #4 on: July 21, 2011, 02:07:57 pm »


               Thanks ,I will experiment on this after work.
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
animals
« Reply #5 on: July 21, 2011, 02:09:23 pm »


               I just keep most of my farm animals in pens and they don't stray far. If you're using the default Bioware scripts, then it's likely you can just set a variable on the ones you want to wander. You can also just activate wandering in their Onspawn using something like this:

#include "x0_i0_anims"
void main()
{
SetSpawnInCondition(NW_FLAG_SHOUT_ATTACK_MY_TARGET);
SetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS);
SetListeningPatterns();
WalkWayPoints();
}


               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
animals
« Reply #6 on: July 21, 2011, 11:47:47 pm »


               

Morbane wrote...

Usually the randomwalk function would be placed in the heartbeat - so in effect the random direction is rechosen every 6 seconds - the chicken will not get far before changing path. But potentially they can actually roam anywhere.



Adding the RandomWalk stright to the HB without a filter is a bad Idea.   Random walk does not need to be called every HB.  Once it is called it will continue untill a clear all actions is called.   If you just place it into the HB you are going to be adding a action to the Que ever round with the chance of non of them ever being removed.  I am not sure what the limit is on the number of actions in the que, but if left unchecked this can cause problems.  
               
               

               


                     Modifié par Lightfoot8, 21 juillet 2011 - 10:48 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
animals
« Reply #7 on: July 22, 2011, 12:31:56 am »


               My cows onperception:

//Goes OnUserDefined of a creature, or on perception.
#include "NW_I0_GENERIC"
void main()
{
   if (d100()>25)
//fires % of the time.
   return;
   object oPC = GetLastPerceived();
   object oBale= GetNearestObjectByTag ("HayBale");
   object oBale1= GetNearestObjectByTag ("HayBale01");
   object oTrough = GetNearestObjectByTag ("WaterTrough");
   effect eRegenerate = EffectRegenerate(5, 6.0);
      {
    if  (GetIsInCombat())
   return;//if fighting fight on.
      }
   switch( d6())
    {
    case 1: ActionInteractObject (oBale);break;
    case 2: AssignCommand(oPC, PlaySound("as_an_cows1")); break;
    case 3: AssignCommand(oPC, PlaySound("as_an_cows2")); break;
    case 4: ActionInteractObject (oBale1);break;
    case 5: ActionInteractObject (oTrough);break;
    case 6: ActionInteractObject (oBale1);break;
     }
    if (GetDistanceToObject(oTrough) < 2.0)
    DelayCommand (2.0, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eRegenerate, OBJECT_SELF, 30.0));
}
Now you want to put an object tagged HayBale HayBale01 and WaterTrough.  The cows will roam around only if they perceive something nearby as I put them on short range perception with one cow having a medium ranged perception.  This is for cows in a pen but I have used it effectively in open fields too.  Usually the cows simply graze, and if you have ever observed cows, something I would guess most have not, they are are normally very placid.  Only if something comes close do they react.  I delete their hb and just use the script above.  With this method I  have achieved a method which emulates reality pretty well.  The original if % returns most of the time so they won't just change behaviors, flip back and forth, a lot.  So  a higher number will return the script less often and of course only onperception.  The result is if you move towards the cows they react, if you move away they settle down, though sometimes the perception will refire if they perceive another object, like Bill the Bull who roams around and tends to get the gals riled up a bit.  He is on a seperate script.  Anyway just an alternative method for dealing with animals.  You can also tag a waypoint WaterTrough and put it in a stream.
I did one for chickens, cats, dogs, and the aforementioned Bill the Bulls script.
               
               

               


                     Modifié par ffbj, 21 juillet 2011 - 11:35 .
                     
                  


            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
animals
« Reply #8 on: July 22, 2011, 12:42:32 am »


               This is good stuff , thanks
               
               

               
            

Legacy_Builder_Anthony

  • Hero Member
  • *****
  • Posts: 786
  • Karma: +0/-0
animals
« Reply #9 on: July 22, 2011, 03:56:50 am »


               I think axe made this .....you dont need to create a place footprint with the tag itll run wiothout the footprint placeable.Its very cool for other animals like small crabs and deer.

Very good in game...........

// Deer OnPerceive script
const string DEER_TRACKS_RESREF = "x0_tracks";


int GetIsNearMapEdge( object oObject, float fDistanceAway = 2.5)
{ if( !GetIsObjectValid( oObject) || !GetIsObjectValid( GetAreaFromLocation( GetLocation( oObject))) || (fDistanceAway <= 0.0)) return FALSE;

 // If near edge of map, vanish leaving footprints behind
 float  fMaxX = IntToFloat( GetAreaSize( AREA_WIDTH,  GetArea( OBJECT_SELF))) *10.0;
 float  fMaxY = IntToFloat( GetAreaSize( AREA_HEIGHT, GetArea( OBJECT_SELF))) *10.0;
 vector vPos  = GetPosition( oObject);
 return ((vPos.x <= fDistanceAway) || (vPos.y <= fDistanceAway) || ((fMaxX -vPos.x) <= fDistanceAway) || ((fMaxY -vPos.y) <= fDistanceAway));
}


void SpawnTracks( location lSpawnAt, string sResref, string sCreatureName, string sTAG = "")
{ if( !GetIsObjectValid( GetAreaFromLocation( lSpawnAt)) || (sResref == "") || (sCreatureName == "")) return;

 string sLowerName = GetStringLowerCase( sCreatureName);
 string sUpperName = GetStringUpperCase( GetStringLeft( sLowerName, 1)) +GetStringRight( sLowerName, GetStringLength( sLowerName) -1);

 object oTracks    = CreateObject( OBJECT_TYPE_PLACEABLE, sResref, lSpawnAt, FALSE, sTAG);
 if( !GetUseableFlag( oTracks)) { SetUseableFlag( oTracks, TRUE);   SetUseableFlag( oTracks, FALSE); }

 SetName( oTracks, sUpperName +" tracks");
 SetDescription( oTracks, "A fresh set of " +sLowerName +" tracks.");
 AssignCommand( oTracks, DelayCommand( HoursToSeconds( 1), SetDescription( oTracks, "These tracks indicate a " +sLowerName +" came this way a little over an hour ago.")));
 AssignCommand( oTracks, DelayCommand( HoursToSeconds( 3), SetDescription( oTracks, "Looks like a " +sLowerName +" ran through here a few hours ago.")));
 AssignCommand( oTracks, DelayCommand( HoursToSeconds( 15), SetDescription( oTracks, "These " +sLowerName +" tracks are almost a day old.")));
 AssignCommand( oTracks, DelayCommand( HoursToSeconds( 24), SetDescription( oTracks, "It's been over a day since the " +sLowerName +" that made these tracks ran through here.")));
 AssignCommand( oTracks, DelayCommand( HoursToSeconds( 36), DestroyObject( oTracks)));
}
void main()
{ // If being chased
 if( GetIsInCombat())
 { if( GetIsNearMapEdge( OBJECT_SELF))
   { // Chased away -- reached edge of map. Vanish and leave some tracks behind.
     DestroyObject( OBJECT_SELF);
     SpawnTracks( GetLocation( OBJECT_SELF), DEER_TRACKS_RESREF, "Deer", "DeerTracks");
     return;
   }

   // Not near a map edge keep running away.
   // See if the perceived is a closer enemy
   if( GetLastPerceptionSeen() || GetLastPerceptionHeard())
   { object oPerceived = GetLastPerceived();
     if( !GetIsObjectValid( oPerceived) || !GetIsEnemy( oPerceived)) { ExecuteScript( "nw_c2_default2", OBJECT_SELF);   return; }

     // If nobody is attacking. run from the nearest enemy.
     object oEnemy = GetLastHostileActor();
     if( !GetIsObjectValid( oEnemy) || GetIsDead( oEnemy))
     { oEnemy = GetNearestCreature( CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, OBJECT_SELF, 1, CREATURE_TYPE_IS_ALIVE, TRUE, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);
       if( !GetIsObjectValid( oEnemy)) oEnemy = GetNearestCreature( CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, OBJECT_SELF, 1, CREATURE_TYPE_IS_ALIVE, TRUE, CREATURE_TYPE_PERCEPTION, PERCEPTION_HEARD_AND_NOT_SEEN);
     }

     // Switch who we are running from if necessary
     if( !GetIsObjectValid( oEnemy) || ((oPerceived != oEnemy) && (GetDistanceToObject( oPerceived) < GetDistanceToObject( oEnemy)))) oEnemy = oPerceived;

     // Run away
     ClearAllActions( TRUE);
     ActionMoveAwayFromObject( oEnemy, TRUE);
     return;
   }
 }

 // Do default OnPerception behavior
 ExecuteScript( "nw_c2_default2", OBJECT_SELF);
}
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
animals
« Reply #10 on: July 22, 2011, 08:22:48 pm »


               Thanks.  This is one I did for chickens:

#include "NW_I0_GENERIC"
void main()
{
   object oPC = GetLastPerceived();
   object oSpawn;
   oSpawn = OBJECT_SELF;
   object oArea = GetArea(oSpawn);
   effect eRegenerate = EffectRegenerate(2, 10.0);
      location lWP = GetLocation(GetNearestObjectByTag("WP_Chicken_01"));
      location lWP1 = GetLocation(GetNearestObjectByTag("WP_Chicken_02"));
      location lWP2= GetLocation(GetNearestObjectByTag("WP_Chicken_03"));
      location lWP3 = GetLocation(GetNearestObjectByTag("WP_Chicken_04"));
      if (GetIsInCombat())
        return;
      if (GetIsNight() || (GetWeather(oArea) == WEATHER_RAIN))
          {
          DelayCommand (2.0, ActionForceMoveToLocation(lWP3,TRUE));
          DelayCommand (6.0, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eRegenerate, oSpawn, 20.0));
          return;
          }
        if (d100()< 25)
          switch( d4())
    {
    case 1: ActionMoveAwayFromObject(oPC, FALSE, 5.0);break;
    case 2: ActionMoveToLocation(lWP,FALSE);break;
    case 3: ActionMoveToLocation(lWP1,FALSE);break;
    case 4: ActionMoveToLocation(lWP2,FALSE);break;
    }
 }
So you paint down four wp for the chickens, two in the corn and one near the granary .  The fourth wp is where they run to in bad weather, usually under the open shed tile, where they roost at night.  I also put a small chicken clucking sound placeable there.  I don't like the chickens squawking all the time.  Anyway that is my general approach to animals you can see in the above scripts, again no heartbeats.  Then if you want the cat and dog just let me know, or make your own.  I am pretty happy with my cat.  I used a re-sized panther for him and then scaled down rats for the mice he chases and kills.  On chickens there is a nice thing you can add, chicken feed where they run to it and gobble it up, so you could have npc's or pc's feed the chickens.  I don't use that but it is fun and easy to do. The reason for no hb btw is that I don't want the walkwaypoints script or other things interferring with the chickens above script.  Typically they move randoml but then stop and peck and scratch at the ground for a bit, then move on.  So a bit of a workaround and you don't half to deal with the endless random walk.
               
               

               


                     Modifié par ffbj, 22 juillet 2011 - 07:27 .
                     
                  


            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
animals
« Reply #11 on: July 22, 2011, 09:01:32 pm »


               Are these in your PW base you put on the Vault, ffjb? I knew I should have looked through it and grabbed some of that stuff, lol....
               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
animals
« Reply #12 on: July 22, 2011, 09:49:49 pm »


               ffbj, that's some cool scripts you've got there...
               
               

               
            

Legacy_zunath

  • Full Member
  • ***
  • Posts: 152
  • Karma: +0/-0
animals
« Reply #13 on: July 22, 2011, 09:50:42 pm »


               

Lightfoot8 wrote...

Morbane wrote...

Usually the randomwalk function would be placed in the heartbeat - so in effect the random direction is rechosen every 6 seconds - the chicken will not get far before changing path. But potentially they can actually roam anywhere.



Adding the RandomWalk stright to the HB without a filter is a bad Idea.   Random walk does not need to be called every HB.  Once it is called it will continue untill a clear all actions is called.   If you just place it into the HB you are going to be adding a action to the Que ever round with the chance of non of them ever being removed.  I am not sure what the limit is on the number of actions in the que, but if left unchecked this can cause problems.  


You just need a simple check to make sure it doesn't fire every single heartbeat. Something like this:



if ((GetCurrentAction() == ACTION_INVALID) )
    {
        ClearAllActions();
        ActionRandomWalk();
    }


               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
animals
« Reply #14 on: July 22, 2011, 10:14:39 pm »


               @zunath, Basicly that is what I said.   I just did nto define the filter.