Having a character sit down at a table [SOLVED]

Started by Stacy Davidson, Sun 09/08/2009 11:28:56

Previous topic - Next topic

Stacy Davidson

Surprisingly, I haven't found anything that really deals directly with this issue in the manual or on the site.

I need my player to walk to a table and sit down in a chair, staying in that "sitting" view until he walks again.  As soon as the walk icon is clicked on a walkable area and he begins to walk again, he should go back to the normal view.

So far, I have a hotspot, and when you walk to it, I use a WalkToPoint to get him into the right position, and a LockView to lock him into the sitting view.  That part seemed simple enough.  I'm just not sure how best to sense he's moving again and unlock the view.

I half expected to see this sort of functionality built-in, but it looks like I'll have to code it up myself.  I thought about writing some sort of loop while he's sitting to check if he's moving again, but I figured I should throw the question out there and see if anyone already has a bulletproof method before I overcomplicate it too much.

Thanks!
-Stacy Davidson
Jack Houston and the Necronauts
Warbird Games
www.warbirdgames.com

Ghost

One simple way is to check if the x/y coordinates of the character change. In the room's script, you could define an int cur_x, and set it each frame (repeatedly_execut) to the player's x position. Then, as soon as cur_x != player.x, he has moved, and you can reset the views.

Pumaman

There are two ways to do this, you can either:
(1) intercept the mouse click by adding an on_mouse_click handler to the room script. Then you check if the player is trying to walk somewhere and if the character is sitting down, and if you do your standing up logic
(2) let AGS handle the move automatically and capture the fact that he has started moving, as Ghost suggests.
Rather than checking the X co-ordinate you can just check the character's Moving property in the Repeatedly Execute handler.

Stacy Davidson

OK, that definitely shed enough light on the subject for me to find a fairly elegant way (I think) to get it handled.  Thanks for the help!

Here's what I finally settled on.  I first wrote a small function that unlocks the view and moves him to an appropriate position in front of the chair, so he can continue to move around freely.  Next, I added a player.Moving check with a call for that function into the "Stands on Hotspot" function (the chair being the hotspot): if(player.Moving) PlayerStand();

Here's the whole piece of code, including the code that gets him sitting to begin with.  Works beautifully.




// "Walk To Hotspot" moves player to chair, locks view to sitting mode

function CantinaBooth_Mode9()
{
player.Walk(hCantinaBooth.WalkToX, hCantinaBooth.WalkToY, eBlock, eWalkableAreas);
player.LockView(3);
}


// Special "stand up" function to unlock view to normal mode, and move player to a position just in front of the chair and well off the chair's hotspot.

function PlayerStand()
{
player.UnlockView();
player.Walk(270, 116, eBlock, eWalkableAreas);
}


// "Stands On Hotspot" will automatically repeatedly execute a check to see if player has started to move again. If so, PlayerStand() is called.

function hCantinaBooth_WalkOn()
{
if(player.Moving) PlayerStand();
}


-Stacy Davidson
Jack Houston and the Necronauts
Warbird Games
www.warbirdgames.com

Stacy Davidson

I cut it down to two functions (only using Stands On, because Walks To was a little unreliable).  I also added some extra checks with a new global boolian "playerSitting" for added safety.  Works even better now.



function PlayerStand()
{
if (playerSitting == true) {
  player.UnlockView();
  player.Walk(270, 116, eBlock, eAnywhere);
  while (player.Moving) Wait(1);
  playerSitting = false;
  }
}

function hCantinaBooth_WalkOn()
{
if (playerSitting == false) {
  player.Walk(hCantinaBooth.WalkToX, hCantinaBooth.WalkToY, eBlock, eWalkableAreas);
  while (player.Moving) Wait(1);
  player.LockView(3);
  playerSitting = true;
  }

if(player.Moving) {
  PlayerStand();
  }
}
-Stacy Davidson
Jack Houston and the Necronauts
Warbird Games
www.warbirdgames.com

Pumaman

Looks good. One comment I'd make is that this line:

while (player.Moving) Wait(1);

shouldn't be necessary, since the previous line is a blocking Walk command; therefore the Walk command won't finish until the character has finished moving.

Stacy Davidson

That's what I thought, but I stuck it in while debugging in an attempt to strong arm the pause, but I think doing all the checking within the one WalkOn function is what finally stabilized it.  So I'm sure that line was indeed redundant.

-s


-Stacy Davidson
Jack Houston and the Necronauts
Warbird Games
www.warbirdgames.com

Stacy Davidson

I've noticed another issue though, when I click on the character sitting across from the player, or talk to him, it automatically moves the player a few pixels toward him.  And it doesn't do it with traditional movement, because the code doesn't even detect it, so he remains in his sitting view as he slides toward the other character.

This was the only reference I could find to this in the manual:


* Walk to hotspot in Look mode - controls whether the player will walk to "walk-to" spots when the player looks at the hotspot. ***Normally he only walks on use, speak and use-inv.***


Is there a way to toggle automatic movement of the player on use, speak and use-inv?  The player also seems to do this even when just clicking on another character with the walk mode cursor.

BTW, I am using a Lucasarts style template.

Thanks!
-s





-Stacy Davidson
Jack Houston and the Necronauts
Warbird Games
www.warbirdgames.com

Stacy Davidson

#8
Looks like this was a special GoToCharacter function in the global script, so I got around it by placing the code inside a simple:

if (playerSitting == false) {

}
-Stacy Davidson
Jack Houston and the Necronauts
Warbird Games
www.warbirdgames.com

SMF spam blocked by CleanTalk