[SCRIPT] (Request) Moving Shelf using Secrets Books - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: [SCRIPT] (Request) Moving Shelf using Secrets Books (/thread-53736.html) Pages:
1
2
|
(Request) Moving Shelf using Secrets Books - User01 - 05-06-2017 I'm more of a beginner in scripting yet I need this. I've seen those scripts in Custom Stories but I didn't understand them cause they are complicated asf. The moveable books should be pulled in the right order so that the shelf secret door opens. Pulling the books in the wrong order should reset the puzzle. All I know is SetMoveObjectState("shelf_secret_door_1", 0); this will open the shelf. I've created a sample Custom story you can download it here: Moveable Books RE: (Request) Moving Shelf using Secrets Books - Mudbill - 05-06-2017 So you're thinking a puzzle similar to the one in the Archives, except instead of a time limit, they're ordered? So I presume no time limit for this one? There are several ways of achieving this. First thing I can think of goes like this: Let's say we have 3 books, book_1, book_2 and book_3. They need to be pulled in the order they are named, but they all look the same. They each have an area covering the position they need to be in to trigger the pull. These are named area_book_1, area_book_2 and area_book_3. Start by adding the collision callbacks: PHP Code: int bookCounter = 1; PS: If you're unfamiliar with for-loops, here it basically just means that it runs the AddEntityCollideCallback 3 times, with a temporary variable counting 1, 2 and 3 (the variable is named i). I then use that variable to append the current loop number to the names of the books and areas. The integer variable that I set here will be used later (remember to place it outside the OnStart function). So now that this callback is created, we need the callback event: PHP Code: void PullBook(string &in asParent, string &in asChild, int alState) PS: If you don't know how to enable debug messages, see this guide. If this message doesn't show up when you want it, you may have to tweak the position of the area and the book so that they trigger when they should. Now, let's put the checks in that PullBook function. PHP Code: void PullBook(string &in asParent, string &in asChild, int alState) Ok, so the explanation for this is as follows: First we check if the number associated with the current book you're pulling matches the value of the bookCounter variable. If the player pulls book_2 first, then that will not match the bookCounter variable, but if they pull book_1, then it will. If it matches, it runs the following section. If not, it runs the else-section. If they pull the correct book, the bookCounter increases by one, so that it now matches the digit on the next book. If they pull the wrong book, the bookCounter variable resets back to 1 and the player has to start over. After they've pulled the first book, bookCounter becomes 2 (still not enough for the completed if-statement). After the second book, it becomes 3 (still not). After the third and final book, the value is increased to 4, which is more than 3, which is what the final if-statement checks for. Once you reach this section, the puzzle is complete. That's the magic of it all. But remember, there's more you need to do in terms of resetting the books when they fail it, and disabling the event when they complete it so that it doesn't happen multiple times. Scripts you may find useful for this are ResetProp, SetPropStaticPhysics, perhaps AddPropForce, and RemoveEntityCollideCallback. PS: If you're curious about the first if-statement and what it really means, remember that asParent is a string reference to the parent entity that triggered this current event (for example book_1). StringSub is a function that creates a new sub string from another string. I put asParent into it, and told it to create a new string from index 0 through the last index minus 1. Basically it took book_1 and removed the last character, and then it added the bookCounter instead. You can read about all the functions on the wiki. I wrote this out of visualization and memory so I may have overlooked something. Hopefully not. RE: (Request) Moving Shelf using Secrets Books - User01 - 05-06-2017 I haven't enabled debug messages, though. However, I can't put both callback events, so I just took the last one. I added the SetMoveObjectState function when the puzzle is supposed to be completed to see if this is working. But it didn't. RE: (Request) Moving Shelf using Secrets Books - Mudbill - 05-06-2017 I meant for the last PullBook function to replace the one above it. The first one is just a demonstration of how it's supposed to look before we put the script into it. Can you post the complete script you have and perhaps a screenshot of the map? I also highly suggest you enable debug messages as it makes it much easier to debug. RE: (Request) Moving Shelf using Secrets Books - User01 - 05-06-2017 PHP Code: int bookCounter = 1; In front of each book is a script area. RE: (Request) Moving Shelf using Secrets Books - Mudbill - 05-07-2017 You didn't get to check the debug messages, eh? That would give us a hint of where it stops working. You can upload the CS and I'll test it. RE: (Request) Moving Shelf using Secrets Books - User01 - 05-07-2017 Well, I tried setting up the development enviroment by following these steps. In the end I couldn't open the debug menu and therefore I don't see debug messages. Guess something went wrong, though. Would be easier if there was a video demonstration of it. However, I reinstalled the game to make sure nothing broke. Here's the CS: https://en.file-upload.net/download-12483851/MoveableBooks.rar.html RE: (Request) Moving Shelf using Secrets Books - Mudbill - 05-07-2017 Well, I opened the map and saw that you didn't name your books correctly. They are named book_moveable_1 instead of book_1 as the script asks for. I tested it and now it works just fine. I do have a video on setting up a dev environment, but it's for Mac. It's not very different though, so you should be able to figure it out pretty easily. The only difference is the file locations. https://www.youtube.com/watch?v=ktOU_dAvezo RE: (Request) Moving Shelf using Secrets Books - Radiance - 05-07-2017 What does this mean : //string &in asParent// RE: (Request) Moving Shelf using Secrets Books - Mudbill - 05-07-2017 If it starts with 2 forward slashes, then it's a comment and has no effect on the script. But that's not what you asked, eh? This part is used inside the parameters of a function. The first part specifies the data type of the parameter, the second part is optional but has to do with AngelScript and how it copies and transfers information between the input and output values (you don't necessarily need to know what this means), and the last part is the given name of the parameter. Have an example: PHP Code: void MyFunc(int value) { This function named MyFunc takes an integer parameter. Therefore if you want to call this function, you must satisfy that. PHP Code: void OnStart() { Here we give MyFunc an int with the value of 5. What happens is that MyFunc now takes that value of 5 and does something with it. The &in part I can't really explain because I don't properly understand it myself, but I've read about it on the AngelScript wiki, and it seems to be specific to this language. It can be &in, &out or &inout for input, output or both, respectively. I believe it handles the scope of the variables given to the function. |