Page 1 of 1

MoveTo / MoveToward problem

PostPosted: Wed Sep 12, 12 11:29 pm
by Cozmo
For a mod I'm doing, I have a scripted melee attack in state code, where it plays the animation, then delays, then checks if the player is within range and does the damage.

This works great, but the NPCs stop to attack, so unless you fight them in a small enclosed space, they're useless. So, seeing as this is within state code, I added a MoveToward function just before the delay so they would run after their target while attacking. Problem is, they don't seem to be able to execute any code under the MoveToward line until they get to their destination. And if you stand still, they never get to their destination, and just run around you until they give up and finish the attack.

Code: Select all
   if(RandInt <= 2) //NORMAL ATTACK
   {
      PlayAnimPivot('Attack',,0.1);
      MoveToward(Enemy, GroundSpeed); //Nothing after this line gets called until finished!
      Sleep(0.4); //Wait for the animation

      if(VSize(Location-Enemy.Location) < 130)
      {
         Enemy.TakeDamage(6+RandInt, Self, Enemy.Location, vect(0,0,0), 'Shot');
         DeusExPlayer(Enemy).ShakeView(0.8, 15.0, 30.0);
      }

      PlayRunning();
   }


I tried MoveTo(Enemy.Location) as well, which is a little better than standing still, but has the same problem if the player stands still.

Basically, I need a way to leave the MoveToward() as soon as the Sleep() is finished. If anyone can help, I'd appreciate it, plus the mod would be significantly better. :P

PostPosted: Thu Sep 13, 12 2:51 am
by Allan
Hm... Perhaps try placing the vSize check before the MoveTo[ward] call, so if it's within range, it'll attack instead of trying to move? :p

PostPosted: Thu Sep 13, 12 5:29 am
by Poor
MoveTo and MoveToward are latent functions. The next line won't execute until the pawn reaches the destination. You can use Tick() to perform other functions while the latent function is running, but I'm not sure if you can prematurely stop the latent function.

Why not just use a melee weapon?

PostPosted: Thu Sep 13, 12 6:49 pm
by Cozmo
Thanks for the replies!

Allan wrote:Hm... Perhaps try placing the vSize check before the MoveTo[ward] call, so if it's within range, it'll attack instead of trying to move? :p


I thought about this, but then the attack would happen as the animation starts, so it'd be either standing still or without a delay. :( I'd like to give the players a slight chance to run away if they see it coming (NPC runs slightly slower than player).

Poor wrote:Why not just use a melee weapon?


I was originally going to use a weapon, but to be honest I'm a noob of a coder, especially when it comes to fixing replication problems with NPCs. They have several custom attacks too, I find it easier to control how they're used this way.

Poor wrote:MoveTo and MoveToward are latent functions. The next line won't execute until the pawn reaches the destination. You can use Tick() to perform other functions while the latent function is running, but I'm not sure if you can prematurely stop the latent function.


Ah, thanks for the tip. :) I think I'll remove sleep and do the attack timing/coding in a function called through Tick(). I'll play around and report any progress.