Author Topic: Heartbeat script on spawned creatures  (Read 323 times)

Legacy_Aradan Kir

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +0/-0
Heartbeat script on spawned creatures
« on: August 16, 2011, 03:48:44 pm »


               I'm trying to create a script which makes animals herd together, which uses the heartbeat element to check distance from another creature, and if too far away, moves them together.

The problem I'm having is that whilst this works fine for creatures that are placed directly into the mod; if the creatures are created via an encounter spawn, it doesn't work.  The script itself does fire and the checks etc all fire correctly (tested with a speakstring), but the creature's don't actually move.  "sCreatureTag" is displayed as part of the debug text, and it's the same whether the creature is placed directly or spawned.

Any ideas?  Bit stumped.

This is the code.  This was added to a replacement version of the default NW_C2_DEFAULT1 script that the creature has set to it's OnHeartbeat.  

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
object oMe = OBJECT_SELF;
  
string sCreatureTag = GetTag(oMe);
// get the nearest creature in the area with the same tag as itself (ie one of the same creature type)
object oNearbyCreature = GetNearestObjectByTag(sCreatureTag, oMe, 1);

// if there is another creature with the same tag in the area, and it's more than 8 metres away, run towards it
if ( GetIsObjectValid(oNearbyCreature) && GetDistanceToObject(oNearbyCreature) > 8.0  )
{
    ActionForceMoveToObject(oNearbyCreature, TRUE, 5.0, 30.0);
    SpeakString(sCreatureTag + " is seeking the herd", TALKVOLUME_TALK);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Heartbeat script on spawned creatures
« Reply #1 on: August 16, 2011, 04:13:23 pm »


               Try ClearAllActions before your Force Move.   THe creature could be doing something like RandomWalk.   Never getting to your move action in the action Que.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Heartbeat script on spawned creatures
« Reply #2 on: August 16, 2011, 07:32:47 pm »


                Have you seen the Flocking Behavior scripts on the vault?
               
               

               
            

Legacy_Aradan Kir

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +0/-0
Heartbeat script on spawned creatures
« Reply #3 on: August 16, 2011, 08:46:10 pm »


               

Lightfoot8 wrote...

Try ClearAllActions before your Force Move.   THe creature could be doing something like RandomWalk.   Never getting to your move action in the action Que.


Yes, this fixed it!  Thanks so much!!

Also, thanks for the Flocking script - I'll check that out; but this was mostly about me getting my head around scripting, rather than necessarily needing an actual herding system working.

Thanks guys - much appreciated!':wizard:'