Stop player walking

Started by Slasher, Sat 08/08/2020 08:51:21

Previous topic - Next topic

Slasher

Hi,

If a character interacts/looks etc  and it's during player walking the player should cease walking, even after interacting/looking until commanded to do...

At the moment it kind of looks silly.

Would like an 'if player walking' condition.. Then stop player temp. from walking.

Cheers


Crimson Wizard

Quote from: Slasher on Sat 08/08/2020 08:51:21
Would like an 'if player walking' condition..

Not sure if this is what you asking about, but there's Character.Moving property that is "true" when character walks or moves with Move command. There's similar property for an Object.

zeta_san

hi, this makes the character arrive at their destination to perform the action and can be interrupted

Code: ags
  if (Verbs.MovePlayer(x, y)) {

arj0n

Quote from: zeta_san on Sat 08/08/2020 16:46:44
hi, this makes the character arrive at their destination to perform the action and can be interrupted

Code: ags
  if (Verbs.MovePlayer(x, y)) {


That's specifically for when using the Tumbleweed template...

ToeKnee

#4
I would use this to get that effect... may not be elegant but I just tried it and it will work;

To stop a moving Object/Char
Code: ags

   cEgo.Move(200, 100, eNoBlock, eWalkableAreas);
   if(cEgo.Moving==1) 
      cEgo.StopMoving(); 


This works to stop a moving character or object - However the Character is not 'moving' in your example... but is 'walking'!

To stop a walking Character
Code: ags

   int CharX=cEgo.x; int CharY=cEgo.y;
   Wait(1);
   if ((CharX==cEgo.x) && (CharY==cEgo.y))
      Display ("Wasn't Walking!");
   else {
      cEgo.Walk(cEgo.x, cEgo.y, eNoBlock, eWalkableAreas);
      Display("Was Walking, but is not now!");
      }


- Which stores the Characters x/y position on the screen, then waits 1/40th of a second, then checks for any change to either of those values (meaning it is walking). If there is a change, then make the character 'walk' to the 'current location' (effectively halting the character from walking - i.e: 'cancelling' the prior 'walk' location that it was going to and setting that to where it already is)
If it’s not broken, let’s fix it till it is...!

Laura Hunt

Quote from: ToeKnee on Mon 17/08/2020 17:57:34
To stop a moving Object/Char
Code: ags

   cEgo.Move(200, 100, eNoBlock, eWalkableAreas);
   if(cEgo.Moving==1) 
      cEgo.StopMoving(); 


This works to stop a moving character or object - However the Character is not 'moving' in your example... but is 'walking'!

Character.Moving and Character.StopMoving also work with the Walk command.

From the manual:

QuoteExample:

cEgo.Walk(125, 40);
while (cEgo.Moving) Wait(1);

will move EGO to 125,40 and return control to the player when he gets there.

Also, you don't have to do "if(cEgo.Moving==1)". Simply doing "if (cEgo.Moving)" is enough.

ToeKnee

Quote
   cEgo.Move(200, 100, eNoBlock, eWalkableAreas);
   if(cEgo.Moving==1)
      cEgo.StopMoving();

Laura, the manual says that but it does not work in gameplay once the Character is moving.
I just tried it again using the Moving and Stop Moving commands when you click on anything whilst the character is moving and it will not stop it.
My code works but those commands do not interrupt the normal 'walk' command that AGS has internally to move a character (probably has it's own blocking style)
Cheers. Tony
If it’s not broken, let’s fix it till it is...!

Laura Hunt

Quote from: ToeKnee on Wed 19/08/2020 09:21:09
Quote
   cEgo.Move(200, 100, eNoBlock, eWalkableAreas);
   if(cEgo.Moving==1)
      cEgo.StopMoving();

Laura, the manual says that but it does not work in gameplay once the Character is moving.
I just tried it again using the Moving and Stop Moving commands when you click on anything whilst the character is moving and it will not stop it.

I have the following lines in my script and it works perfectly fine when the character is walking:

Code: ags
function hLamp_Interact()
{
  if (cLadyW.Moving) cLadyW.StopMoving();
  cLadyW.SetWalkSpeed(1, 1);
}


You must be doing something else that's interfering with it, because the commands work exactly as expected (otherwise the game would crash, because you can't change walk speed while a character is moving).

Khris

I imagine that player.StopMoving() will always work but depending on where exactly you put it, might not get called during a blocking walk.
I put it in repeatedly_execute_always and it stopped the player perfectly fine during a standard blocking walk and a hotspot's walkto point approach (which is probably the same as a blocking walk internally).

ToeKnee

QuoteYou must be doing something else that's interfering with it

Yep, on re-checking the Stop Moving command was triggered on a Hotspot that has a 'WalkToPoint' set on it
- if I clear the WalkToPoint (0,0) - then the Character stops. Otherwise it (of course) keeps moving/walking to the Hotspot if I interact with it whilst character is moving.
If it’s not broken, let’s fix it till it is...!

Laura Hunt

Quote from: ToeKnee on Wed 19/08/2020 10:00:55
QuoteYou must be doing something else that's interfering with it

Yep, on re-checking the Stop Moving command was triggered on a Hotspot that has a 'WalkToPoint' set on it
- if I clear the WalkToPoint (0,0) - then the Character stops. Otherwise it (of course) keeps moving/walking to the Hotspot if I interact with it whilst character is moving.

Ah, that explains it, of course if the walk command is blocking then a workaround (such as using repeatedly_execute_always like Khris suggested) is needed. Glad it made sense in the end!

SMF spam blocked by CleanTalk