Play a "stand up" animation before walking

Started by duckwizard, Thu 10/03/2011 19:26:25

Previous topic - Next topic

duckwizard

I have a spot that when you interact with it, it causes cEgo to walk there and play an animation to sit down.  That works great.

But now I want it so if you walk somewhere else, he will play a "stand up" animation before he starts to walk.

I tried making a 1 pixel region where he is programmed to sit, and when cEgo leaves that region it plays the stand up animation.  But by that time he is already walking, so it's too late for this to work.

I could work around this by disabling walk and forcing you to interact with something (like the rest of the floor I guess) in order to stand up, then re-enabling walk.  But that is not ideal.  So I thought I would check if anyone has ideas for making this happen.

There is probably something I could do with invisible dummy characters or dummy objects.  I will try to mess with that.  But I'm hoping there's an elegant solution because I am a little OCD when it comes to inelegance and I go to great (even ridiculous) lengths to avoid it.

Matti

Couldn't you just play a blocking stand-up animation in case the player clicks somewhere while the character is still sitting? If it's blocking the character won't start walking. You could then set variables for the coordinates the character is supposed to walk after standing up.

duckwizard

Thanks for the reply!

Quote from: Matti on Thu 10/03/2011 20:01:28
Couldn't you just play a blocking stand-up animation in case the player clicks somewhere while the character is still sitting? If it's blocking the character won't start walking. You could then set variables for the coordinates the character is supposed to walk after standing up.

Sure, but how would I intercept the click if the player is in walk mode?  There is no "any kind of click anywhere in the room" event.  Even if I make a hotspot that covers the whole floor (or the whole room), and assign "other click on hotspot" event, walking is the one kind of click that won't fire that event.

Am I missing something?

Khris

Just add this to your room script:

Code: ags
void on_mouse_click(MouseButton button) {
  
  // only intercept walking
  if (button != eMouseLeft || mouse.Mode != eModeWalkto) return;
  
  // test for sitting, either by region or view/loop/frame
    // standing up animation
}


After the room's on_mouse_click, AGS will proceed with the global one. (Should you want to prevent that in another situation, there's ClaimEvent();)

duckwizard

Khris, that works perfectly.  Didn't know you could intercept mouse events at the room level.  Very cool.

Even cooler that it waits until my blocking call finishes and then bubbles the event up to the global processor!  I wouldn't have expected that (separate event loops for animation and input).

monkey0506

on_mouse_click, on_key_press, on_event, and repeatedly_execute_always can appear, and of course will be fired appropriately, in any script (excluding dialog scripts since that would be considered nested functions). game_start and repeatedly_execute work too, but not in room scripts. The very first room isn't loaded until game_start (in every script) is completed. Rooms can have a repeatedly execute function, but by default it is called room_RepExec, not repeatedly_execute. You can however change that via the room's events pane. If you ever need to figure out what order something is being called in (particularly across multiple scripts) then breakpoints as well as the Display and AbortGame functions are rather handy.

SMF spam blocked by CleanTalk