Author Topic: Scripting an NPC Fish not to go on land.  (Read 431 times)

Legacy_Ivanovich

  • Full Member
  • ***
  • Posts: 142
  • Karma: +0/-0
Scripting an NPC Fish not to go on land.
« on: December 14, 2010, 06:54:12 pm »


               Hello, all.  I have a trigger that I have set up in an area that is mainly water, with a little island.  In the trigger's OnEnter event, I have the following script:

void main()
{
object oObject = GetEnteringObject();
int iFish = GetLocalInt(oObject, "fish");
object oWay = GetNearestObjectByTag("FISHRETURN", OBJECT_SELF, 1);
location lWay = GetLocation(oWay);


if(!GetIsPC(oObject))
{

if (iFish == 1)
{
AssignCommand(oObject, ActionJumpToLocation(lWay));
}
}

}


There is a waypoint out in the water far away called "FISHRETURN".  All fish/sharks or otherwise water only creatures have the "fish" LocalInt set to "1".  However, when I try this in game, the NPC ignores the trigger entirely.  I cannot figure out why that is.  

Thanks in advance for help.
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Scripting an NPC Fish not to go on land.
« Reply #1 on: December 14, 2010, 08:32:00 pm »


               How do you have the triger drawn down? Is it along the water edge where thefish might swim into it, or is it drawn around the whole water section where the fish is swimming around inside the trigger?
               
               

               
            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Scripting an NPC Fish not to go on land.
« Reply #2 on: December 14, 2010, 09:46:37 pm »


               This is how I do it.

Create a trigger. This trigger fills the entire section where you want the fish to remain inside.

I placed the following script on the OnExit of the trigger.

void main()
{

object oExiting = GetExitingObject();

if( !GetIsObjectValid( oExiting) || (GetTag( oExiting) != "TAG_OF_FISH_HERE")) return;
  {

    AssignCommand(oExiting, ClearAllActions());

    DelayCommand (0.5, AssignCommand(oExiting, ActionForceMoveToLocation(GetLocation(GetNearestObjectByTag("FISHRETURN")))));

    }
}


FP!
               
               

               


                     Modifié par Fester Pot, 14 décembre 2010 - 09:46 .
                     
                  


            

Legacy_Ivanovich

  • Full Member
  • ***
  • Posts: 142
  • Karma: +0/-0
Scripting an NPC Fish not to go on land.
« Reply #3 on: December 15, 2010, 01:16:43 pm »


               

_Knightmare_ wrote...

How do you have the triger drawn down? Is it along the water edge where thefish might swim into it, or is it drawn around the whole water section where the fish is swimming around inside the trigger?


The trigger is around the island i do not want the fish to "walk" upon.  Yet the fish comes into the trigger with no issues and attacks.

The fish does not spawn inside the trigger.
               
               

               


                     Modifié par Ivanovich, 15 décembre 2010 - 01:19 .
                     
                  


            

Legacy_Ivanovich

  • Full Member
  • ***
  • Posts: 142
  • Karma: +0/-0
Scripting an NPC Fish not to go on land.
« Reply #4 on: December 15, 2010, 01:18:31 pm »


               

Fester Pot wrote...

This is how I do it.

Create a trigger. This trigger fills the entire section where you want the fish to remain inside.

I placed the following script on the OnExit of the trigger.

void main()
{

object oExiting = GetExitingObject();

if( !GetIsObjectValid( oExiting) || (GetTag( oExiting) != "TAG_OF_FISH_HERE")) return;
  {

    AssignCommand(oExiting, ClearAllActions());

    DelayCommand (0.5, AssignCommand(oExiting, ActionForceMoveToLocation(GetLocation(GetNearestObjectByTag("FISHRETURN")))));

    }
}


FP!


I appreciate the suggestion, but exit triggers would be far more difficult given the terrain I'm managing.  There must be a reason why the script I posted above does not work right.
               
               

               
            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Scripting an NPC Fish not to go on land.
« Reply #5 on: December 15, 2010, 04:50:59 pm »


               So flip the script around if you don't want to use the OnExit event. Keep it as it is and use it as an OnEnter as you originally wanted to do.

void main()
{

object oEntering = GetEnteringObject();

if( !GetIsObjectValid( oEntering) || (GetTag( oEntering) != "TAG_OF_FISH_HERE")) return;
 {

  AssignCommand(oEntering, ClearAllActions());

  DelayCommand (0.5, AssignCommand(oEntering, ActionForceMoveToLocation(GetLocation(GetNearestObjectByTag("FISHRETURN")))));

  }
}


FP!
               
               

               


                     Modifié par Fester Pot, 15 décembre 2010 - 04:51 .
                     
                  


            

Legacy_AndarianTD

  • Hero Member
  • *****
  • Posts: 725
  • Karma: +0/-0
Scripting an NPC Fish not to go on land.
« Reply #6 on: December 16, 2010, 01:56:25 pm »


               

Ivanovich wrote...

I appreciate the suggestion, but exit triggers would be far more difficult given the terrain I'm managing.  There must be a reason why the script I posted above does not work right.


I'm having to do something similar to manage the mixed flying and walking areas in Sanctum 3. Depending on how important it is for the creature's behavior to look natural and the shape of the area, you may want to put several of the waypoints in various parts of the water area. If the area is at all concave and you use ActionForceMoveToLocation instead of jumping, it'll also help avoid the possibility of a fish trying to walk over land to get to the "FISHRETURN" point. If you do that then you'll want to use the entering object rather than the trigger in GetNearestObjectByTag.

The only other thing I can see with the script you posted that might cause it not to work is the lack of a ClearAllActions call before assigning the jump or move action. What FP wrote looks like a simplified version of my scripts, and they work fine.

You may also want to use a delay to get the creature to return to its normal behavior after the move. One thing I found for example is that the ClearAllActions will reset a creature's combat state, which is important for me to restore after preventing a land-based creature from entering a flyng area. You're trying to keep a water-based creature from entering a land area, so what you're doing is largely the same thing with different names.
               
               

               


                     Modifié par AndarianTD, 16 décembre 2010 - 01:57 .
                     
                  


            

Legacy_Ivanovich

  • Full Member
  • ***
  • Posts: 142
  • Karma: +0/-0
Scripting an NPC Fish not to go on land.
« Reply #7 on: December 17, 2010, 06:56:18 pm »


               It was indeed the ClearAllActions that was making the original script not work. Thank you.  And thanks for helping, FP.
               
               

               
            

Legacy_archer4217

  • Full Member
  • ***
  • Posts: 206
  • Karma: +0/-0
Scripting an NPC Fish not to go on land.
« Reply #8 on: April 06, 2011, 11:43:36 pm »


               I would love to use your script in my PW, with your permission of course, Ivanovich. I was wondering if you could post the corrected one you made? Pretty please? '<img'>
               
               

               
            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Scripting an NPC Fish not to go on land.
« Reply #9 on: April 10, 2011, 05:32:48 am »


               // crtr_return
/*
   MADE BY:Ivanovich
   DATE:12.01.2010 4 months ago by forums
   current date 04.09.2011
*/
void main()
{
object oObject = GetEnteringObject();
// replace name of local variable on creature here
int iFish = GetLocalInt(oObject, "fish");
// replace name of return waypoint hhere
object oWay = GetNearestObjectByTag("FISHRETURN", OBJECT_SELF, 1);
location lWay = GetLocation(oWay);


if(!GetIsPC(oObject))
{
if (iFish == 1)
{
AssignCommand(oObject,ClearAllActions(TRUE));
AssignCommand(oObject, ActionJumpToLocation(lWay));
}
}

}

This is pasted fix of Ivanovich above script pretty easy to do.  The issue was ClearAllActions(TRUE) needed to be in there to clear the creatures combat state. Both Ivanovich, and fester Pot are correct in there scripting methods.  The terrian makes a difficult sometimes you just adjust.  Im sure Ivanovich wont mind you using the script thats why we post here to help each other out
               
               

               
            

Legacy_archer4217

  • Full Member
  • ***
  • Posts: 206
  • Karma: +0/-0
Scripting an NPC Fish not to go on land.
« Reply #10 on: April 18, 2011, 06:26:38 pm »


               Thank you, Greyfort. You're a sweetie. '<img'>