unable to move or interact

Started by dude_r005, Sat 09/12/2006 15:41:58

Previous topic - Next topic

dude_r005

hi folks,
I'm trying to make a sequence, where something drops on my player, and he shall be unable to move or interact with other hotspots, objects, etc. in the room. all he should be capable of is moving his hand. In monkey island 2 is a very similair situation, when guybrush gets caught in lechucks hiding place. Later on, he and wally are hanging over some kind of acid. That's pretty much what I want.
I could solve it with setting a global int, which changes, if a certain action (which causes the thing to drop on my player) is done. This global int could then be a conditon to interact with objects etc in this room. and I'll have to remove the walkable areas and change the players view.

I'm pretty sure, all this would be no problem, but , I wonder if there ain't an easier way to do this. Any suggestions? maybe a little trick, which makes the player unable to move or interact with anything but some choosed combinations.
I'm thankful for all I can get

Khris

Try to intercept clicks in on_mouse_click:
Code: ags
// script header
import bool trapped;

// global script, right above on_mouse_click:

bool trapped;
export trapped

#sectionstart ...
function on_mouse_click(MouseButton button) {
...
  if (MouseButton==eMouseLeft) {

    if (trapped) {
      ..check if action is available when trapped, if not: return;
    }
    
    ..usual left click code here
  }
  ..rest of on_mouse_click
}


To make the player become trapped:
Code: ags
trapped=true;

dude_r005

hey sorry for my late reply. I was sick and couldn't get myself to work on the game. thanx for your answer, I guess this is the better way to do this. I included the code in my scripts and it worked, but I still don't understand or know how to check which actions are available.

for example: the player shall just able to interact on a electric wire.
on all other hotspots and object the message "I cannot reach it" be displayed. The player should also not be able to walk around or say things about the stuff he looks at, because if he does that, he automaticly gets in the talking-view.
could anybody give me some sort of help there?
I know it's probably a little much to ask, but I think if I'd just undestood how it works, I could get the rest going.
thx for your help in advance

dude_r005

hey, I try around a little and this is how far I got :

#sectionstart on_mouse_clickÃ,  // DO NOT EDIT OR REMOVE THIS LINE
Code: ags


function on_mouse_click(int button) {
Ã,  
Ã,  // called when a mouse button is clicked. button is either LEFT or RIGHT 
if (IsGamePaused() == 1) {
Ã,  Ã,  // Game is paused, so do nothing (ie. don't allow mouse click)
}

 else if (button==LEFT) {
Ã,  Ã, 
Ã,  if (trapped){
Ã,  Ã,  if (mouse.Mode == eModeWalkto) { player.Think("I'm stuck");}
Ã,  Ã,  else if (mouse.Mode == eModeLookat){player.Think("I can't see nothin'");}
Ã,  Ã,  else if (mouse.Mode == eModeTalkto){player.Think("Hello? Anybody there?");}
Ã,  Ã,  else if (mouse.Mode == eModeInteract){player.Think("I can't reach it");}
Ã,  Ã,  else if (mouse.Mode == eModeUseinv) {
Ã,  Ã,  Ã,  Ã, if (player.activeinv == 3) {player.Think("Tataaaaaa");}
Ã,  Ã,  Ã,  Ã, else {player.Think("I don't think this would help right now.");}
				 }
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  


so far so good. But the player still does the old actions after the message has been dislplayed.

for example:

Before he was trapped you could click (look-mode) on the carpet and he would walk up to it and say "that's a nice carpet". If you do this now, while he is trapped, he will think "I can't see anything" and then walk right up to the carpet and say "that's a nice carpet".Ã,  how could I make him unable to walk and stop these options like the one with the carpet?
I thought about removing the walkable areas and changing his view, but I guess he'll still walk up to the carpet and talk...

any suggestions? ???

Khris

You forgot the "return;" from my script, but that was easy to miss.

Code: ags
function on_mouse_click(int button) {
Ã,  // called when a mouse button is clicked. button is either LEFT or RIGHT 
Ã,  if (IsGamePaused() == 1) {
Ã,  Ã,  // Game is paused, so do nothing (ie. don't allow mouse click)
Ã,  }

Ã,  else if (button==LEFT) {
Ã,  Ã, 
Ã,  Ã,  if (trapped){
Ã,  Ã,  Ã,  if (mouse.Mode == eModeWalkto) {
Ã,  Ã,  Ã,  Ã,  player.Think("I'm stuck");
Ã,  Ã,  Ã,  Ã,  return;
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (mouse.Mode == eModeLookat) {
Ã,  Ã,  Ã,  Ã,  player.Think("I can't see nothin'");
Ã,  Ã,  Ã,  Ã,  return;
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (mouse.Mode == eModeTalkto) {
Ã,  Ã,  Ã,  Ã,  player.Think("Hello? Anybody there?");
Ã,  Ã,  Ã,  Ã,  return;
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (mouse.Mode == eModeInteract) {
Ã,  Ã,  Ã,  Ã,  player.Think("I can't reach it");
Ã,  Ã,  Ã,  Ã,  return;
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (mouse.Mode == eModeUseinv) {
Ã,  Ã,  Ã,  Ã,  if (player.activeinv != 3) {
Ã,  Ã,  Ã,  Ã,  Ã,  player.Think("I don't think this would help right now.");
Ã,  Ã,  Ã,  Ã,  Ã,  return;
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  player.Think("Tataaaaaa");}
Ã,  Ã,  Ã,  }
Ã,  Ã,  }
Ã,  Ã,  ...finally handle left click
Ã,  }
Ã,  ...rest of on_mouse_click
}


"return;" will make AGS leave the function immediately.

Btw, if there's only one command between { and }, you don't need the brackets:
Code: ags
if (a==1) Display("a is 1.");
else Display("a isn't 1.");

dude_r005

great! thanx. Thats what was missing. Now everything works like it should. And thx for the hint with the braces, I already knew it, but I keep forgetting to use it that way.

dude_r005

well, it's me again, with another problem I can't solve. I tried around, I searched the help (manual), I searched the forum, but I couldn't figure it out.
The code is still the same from above. What I need now, is an exeption around here:
Code: ags

else if (mouse.Mode == eModeInteract) {
Ã,  Ã,  Ã,  Ã,  player.Think("I can't reach it");
Ã,  Ã,  Ã,  Ã,  return;


whenever my player tries to interact with anything, "I can't reach it" appears. Thats fine so far, but he muste be able to interact with one single object.
I thought about different ways to make that work, but none of it turned out to be usefull in the end. By the way, I'm not that good in scripting yet.
My ideas were
- to somehow export the name of the scriptname of the object (oBox) from the roomscript to the globalscript. I found an thread, where someone wanted to do the same, but he was told, it wasn't that easy.

Code: ags

else if (mouse.Mode == eModeInteract) {
Ã,  Ã,  Ã,  Ã,  if (mouse.IsButtonDown(eMouseLeft)==oBox) {player.Think("haudidaudi");}
Ã,  Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  Ã,  else {player.Think("I can't reach it");
Ã,  Ã,  Ã,  Ã,  return;}
Ã,  Ã,  Ã,  }




- add an action (run script) to the object in the room that sets a variable

something like this
#roomscript
any click on object --> set variable to 1

#global script
Code: ags

else if (mouse.Mode == eModeInteract) {
Ã,  Ã,  Ã,  Ã,  if (variable==1) { player.Say("shubidubidoo") }
Ã,  Ã,  Ã,  Ã,  else {player.Think("I can't reach it");}
Ã,  Ã,  Ã,  Ã,  return; }


I had some more, but I better not post'em if I intend to not make a complete fool of myself ;-)


Is this even possible to do? Am I heading the complete wrong direction?

once again, the player is trapped and shouldn't be able to move or interact wiht anything BUT this one object and the inventory objects.
pleeeeeaaaase help me out once again. This animation is too sweet to be buried now.

Ashen

This line
Code: ags

        if (mouse.IsButtonDown(eMouseLeft)==oBox) {player.Think("haudidaudi");}


Probably wouldn't do anything except generate an error - IsButtonDown can only return true or false, and you seem to want to return what Object the mouse is at. For that you'd use Object.GetAtScreenXY(mouse.x, mouse.y), and while you can't use the Objects Script-O-Name in the Global script, you can still use it's number. So, if oBox was object 2 in the room:
Code: ags

      else if (mouse.Mode == eModeInteract) {
        if (Object.GetAtScreenXY(mouse.x, mouse.y)==object[2]) player.Think("haudidaudi");
        else {
          player.Think("I can't reach it");
          return;
        }
      }


Also, Room Scripts can have their own on_mouse_click functions - if you only need this for one room you could move the code to there, so you can use Script-O-Names, and save making unnecessary changes to the Global Script. If you want to use this in several rooms, you could still use the room-based functions to set exceptions like this one.
Look up the ClaimEvent() function, to stop the Global on_mouse_click from running.
I know what you're thinking ... Don't think that.

dude_r005

damn it, I was so close, I was just playing around with this code, I used for a hotspot to change the cursor
Code: ags

if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hkitty){
Ã,  mouse.SaveCursorUntilItLeaves();
Ã,  mouse.Mode = eModeklo;
Ã,  status = String.Format("go to @overhotspot@");
Ã,  aaa.Text = status;}


Well, but now it's pretty much done. I just need to figure out some minor tweaks and it'll be done. Thanx really much. I'm not sure, if I'll try the thing with the room-mouse-click-scripts, as long it works quite well now, but I definetly look it up.
thx again!

SMF spam blocked by CleanTalk