Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How would you make a mechanic where you can hide under a bed?
GeneralCAL Offline
Junior Member

Posts: 12
Threads: 3
Joined: Jun 2014
Reputation: 0
#1
How would you make a mechanic where you can hide under a bed?

Hi, I'm GeneralCAL, and I was wondering if any hps scripting experts would know how to make a mechanic where you can hide under a bed and have the enemy just stroll by and not notice you unless you got out from underneath the bed? This mechanic is one I want to add to my CS, but I have no clue on how to do it. Thanks
07-04-2014, 05:03 PM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#2
RE: How would you make a mechanic where you can hide under a bed?

I would put a clickable area under the bed so player may click it to enter/leave.
To locate the player under the bed, you could use TeleportPlayer function along with a PlayerStart area to spawn the player and select his angle of view. You should also force him to duck, and remove his movement speed.

Your problem, or hard to solve issue, is when the player collides with the bed.
To solve that, you could have a version of the bed that has no body, or its body without collision with player. Then you switch between those when the player wants to hide or leave.

07-04-2014, 06:37 PM
Find
GeneralCAL Offline
Junior Member

Posts: 12
Threads: 3
Joined: Jun 2014
Reputation: 0
#3
RE: How would you make a mechanic where you can hide under a bed?

(07-04-2014, 06:37 PM)Amn Wrote: I would put a clickable area under the bed so player may click it to enter/leave.
To locate the player under the bed, you could use TeleportPlayer function along with a PlayerStart area to spawn the player and select his angle of view. You should also force him to duck, and remove his movement speed.

Your problem, or hard to solve issue, is when the player collides with the bed.
To solve that, you could have a version of the bed that has no body, or its body without collision with player. Then you switch between those when the player wants to hide or leave.

Thanks Ann! I understand what you would do, but I have no idea how to put it into script. Do you know how?
07-04-2014, 06:42 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#4
RE: How would you make a mechanic where you can hide under a bed?

To make the non-collideable bed, open the bed entity in the Model Editor, and uncheck CollidePlayer after selecting the body. Save as a different name (for example bed_nocollide).

Place both beds in the same place, but keep the nocollide version inactive. Add a script area where you want the player to be able to click to hide, then go on the Entity tab of that area and write a function name in the PlayerInteractCallback box. Also uncheck the AutoRemove box.

Jump to your script and add the callback:
PHP Code: (Select All)
void InteractBed(string &in asEntity)
{
    If(
GetLocalVarInt("IsHiding") == 0) {
        
    }
    else {
        
    }


This variable I added is just IF the player is able to interact with the same area while hiding under the bed. If not, you can add another area where the player is hiding that they can click, which will run the same function (here named InteractBed but can be anything).

Inside the IsHiding = 0 block, add the scripts you want to run when the player will hide. This will probably be TeleportPlayer("PlayerStartArea"); and MovePlayerHeadPos(1, 0.2, 1, 10, 3); but I suggest you use a FadeOut and FadeIn effect in between to make it more smooth. Also add SetPlayerMoveSpeedMul(0); and SetPlayerRunSpeedMul(0); Don't forget to also switch between the entities, using SetEntityActive("normal_bed", false); and SetEntityActive("bed_nocollide", true);

Inside the else block, restore the player's position. Teleport them to another start area beside the bed, and reset the values. MovePlayerHeadPos(1, 1, 1, 10, 3); and SetPlayerMoveSpeedMul(1); + SetPlayerRunSpeedMul(1); Also switch the entities back by doing the same as before, just inverted.

(This post was last modified: 07-04-2014, 07:11 PM by Mudbill.)
07-04-2014, 07:09 PM
Find
GeneralCAL Offline
Junior Member

Posts: 12
Threads: 3
Joined: Jun 2014
Reputation: 0
#5
RE: How would you make a mechanic where you can hide under a bed?

(07-04-2014, 07:09 PM)Mudbill Wrote: To make the non-collideable bed, open the bed entity in the Model Editor, and uncheck CollidePlayer after selecting the body. Save as a different name (for example bed_nocollide).

Place both beds in the same place, but keep the nocollide version inactive. Add a script area where you want the player to be able to click to hide, then go on the Entity tab of that area and write a function name in the PlayerInteractCallback box. Also uncheck the AutoRemove box.

Jump to your script and add the callback:
PHP Code: (Select All)
void InteractBed(string &in asEntity)
{
    If(
GetLocalVarInt("IsHiding") == 0) {
        
    }
    else {
        
    }


This variable I added is just IF the player is able to interact with the same area while hiding under the bed. If not, you can add another area where the player is hiding that they can click, which will run the same function (here named InteractBed but can be anything).

Inside the IsHiding = 0 block, add the scripts you want to run when the player will hide. This will probably be TeleportPlayer("PlayerStartArea"); and MovePlayerHeadPos(1, 0.2, 1, 10, 3); but I suggest you use a FadeOut and FadeIn effect in between to make it more smooth. Also add SetPlayerMoveSpeedMul(0); and SetPlayerRunSpeedMul(0); Don't forget to also switch between the entities, using SetEntityActive("normal_bed", false); and SetEntityActive("bed_nocollide", true);

Inside the else block, restore the player's position. Teleport them to another start area beside the bed, and reset the values. MovePlayerHeadPos(1, 1, 1, 10, 3); and SetPlayerMoveSpeedMul(1); + SetPlayerRunSpeedMul(1); Also switch the entities back by doing the same as before, just inverted.

Thanks a bunch, Mudbill! I hope this works! (I probably won't be able to test it for a couple weeks, tho. Also, what program do you recommend I download to allow me to download .zip files and .rar files, because my computer wont let me and I don't know how to work 7-Zip... D:
(This post was last modified: 07-04-2014, 07:17 PM by GeneralCAL.)
07-04-2014, 07:16 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#6
RE: How would you make a mechanic where you can hide under a bed?

Oh, and I forgot to add that you'd probably want to use SetLocalVarInt("IsHiding", 1) in the check for 0, then set it back to 0 in the else block. Without that, it'd be useless.

I suggest you get WinRAR. It's free and quite easy to use in my opinion.
http://www.rarlab.com/download.htm

07-04-2014, 07:24 PM
Find
GeneralCAL Offline
Junior Member

Posts: 12
Threads: 3
Joined: Jun 2014
Reputation: 0
#7
RE: How would you make a mechanic where you can hide under a bed?

Thanks! I have another question for anyone who wants to answer: does anyone know how to write script for a chemistry puzzle similar to the puzzle in the Laboratory of the main game?
07-04-2014, 07:35 PM
Find




Users browsing this thread: 1 Guest(s)