Making a door open only when character is beside it

Started by Global Lint, Wed 19/07/2006 14:43:56

Previous topic - Next topic

Global Lint

How do you make a door that only opens when the player is in front of it?Ã,  Otherwise the door will open no matter where I am in the room, and that's not good.Ã, 

I was thinking I could make it so that if you're not near the door and you say 'open door' it will display 'You're not close enough!'Ã,  And if you're near, the door (an object) disappears.Ã, 

(By the way, remember the issue about the text parser?Ã,  It works now, so, thanks!Ã,  I was really happy about that.Ã,  My family [most of them anyway] likes games where you can just type away.... me too...)
Spaz ate the dopefish.

hedgefield

You can easily do this with regions. Go to the room editor>areas and from the dropdown box where you have hotspots and walkbehinds and such, select regions. Now draw the area around the door where you want it to be able to open, it's radius so to speak. Then from the interactions you select 'when player stands on region>run script' and add Objectoff(#);, where # is the number of the door. If it's an object that is. This way the door will be open while the player stands on that region of the room.

Global Lint

Whenever I stand on the region, it won't let me type in anything.Ã,  It lets me type one letter and then starts replacing that letter with other letters I type!

Also, if I type 'open door' while NOT on the region, then go onto the region, the door opens.

I don't want the door to automatically open just by standing in front of it.Ã,  It's like this:

1.Ã,  The player stands on the region
2.Ã,  Player types 'open'
3.Ã,  Door opens.

Spaz ate the dopefish.

hedgefield

Oh right, you're using a text parser. Yeah I have no experience with that so I'm not sure how that interferes with the code.

Khris

I doesn't matter if a text parser is used or not, the original explanation was wrong.
Remove the code from the "player stands on region"-interaction.

Then use this when handling "open door":
Code: ags
if (Region.GetAtScreenXY(player.x, player.y)==region[1]) {Ã,  Ã, // change the index to the door region's number
Ã,  // remove door, and so on.
}
else {
Ã,  Display("You're not close enough!");
}


(Putting something in "player stands on region" will trigger those actions continuously as long as the player keeps standing on the region. This has probably messed up the text input, too.)

hedgefield

Ah that would explain it. I had a space door or some such in mind when you described region-specific doors. My bad. I usually use player walks onto region and player leaves region. I thought keeping it centered in one interaction would make it easier, but I didn't know it loops then. Learn something new every day.

Global Lint

Okay, I removed it from the player-stands-on-region interaction. 

I tried putting the code you gave me into the room script and adding the part where if the parser says 'open door' then the door opens.   

But an error message says, '.GetAtScreenXY' is not a public member of 'Region'.
Spaz ate the dopefish.

Khris

#7
Ah yes, sorry, with regions it's Region.GetAtRoomXY.

largopredator: It could be done with a variable and "Player walks onto region", too. That's probably what you meant.
The other event is called "While player stands on region", that one would loop.

Global Lint

THANK YOU!!Ã,  :DÃ,  It works now :DÃ,  Thank you so much!

While I'm here... I started the game in an empty file, so it didn't start with its own inventory.Ã,  I created a GUI that should work for an inventory window, but when I try to get into it, it says:

Error:Ã,  inconsistent inventory calculations.

Internal error.Ã,  I'll look up some stuff on creating your own inventory in the meantime...
Or, I could just make it stay at the top of the screen the whole game.  Yeah, that could work.  Just thinking aloud.
Spaz ate the dopefish.

strazer

#9
Quote from: Faith on Thu 20/07/2006 01:08:09Error:  inconsistent inventory calculations.

Huh? Never heard of that one. :P
How big are your inventory item sprites?

Edit:

I've pm'd CJ about this:

Quote from: CJ (via pm)
Hmm that's a rather odd one, it happens if the actual number of inventory items available is different to the cached count of inventory items for the character. It shouldn't be able to happen, but maybe if there are no inventory items defined in the editor something goes wrong. I'll take a look.

Global Lint

There are none :P

That's ok, it's fine at the top o' the screen anyway ^-^  Thanks guys!
Spaz ate the dopefish.

Thorsell

Quote from: largopredator on Wed 19/07/2006 20:38:42
Ah that would explain it. I had a space door or some such in mind when you described region-specific doors. My bad. I usually use player walks onto region and player leaves region. I thought keeping it centered in one interaction would make it easier, but I didn't know it loops then. Learn something new every day.
I have a very nice example game where some different "space"-doors are shown. They all open when you get close. If I can find somewhere to upload it, then maybe I can show it.


Thorsell

Quote from: strazer on Thu 20/07/2006 23:09:22
There's also a thread about automatic doors in the Tech Archive.

Oh, ok. I am a bit new to the forums as you can see on my postcoun  :) .
I have used AGS some time now, but I haven't used the forums at all, just the tutorials and such.

strazer

Don't worry about it, I was merely pointing it out.
Feel free to upload your demo somewhere, I'm sure someone will get something out of it.
And Welcome to the forums! :)

SMF spam blocked by CleanTalk