Stratomunchkin Posted October 13, 2011 Share Posted October 13, 2011 (edited) Hey guys, since I'm pretty certain it won't stay at my one question I thought I might as well gather them all in one place for everybody's convenience (well, primarily mine, but you get the idea...). 1.) Is there a way (like a script already in the game) to make doors automatically close again after a period of time? If not, can anybody please provide me with one? The problem in this case is that I need the door to close because otherwise it will stick out into the level above it when I go back there. That kinda breaks the immersion I'm trying to establish. Solved, thanks to Cipscis 2.) What's the trick in using the cave tileset? No matter what I do, I'll always get clipping errors and gaps in my caves because the individual parts just don't want to fit. Is there a tool to smoothen those cuts and corners, or do I have to make ample use of the "rock"models to plug each and any gap? 3.) What is the reason that at some places on the worldspace map I'm unable to apply a certain ground texture? I'm playing around with tidying up Primm and would like to apply a scrubs & grass texture around the residential area, but there are places were it won't let me do so. Edited October 18, 2011 by Stratomunchkin Link to comment Share on other sites More sharing options...
Cipscis Posted October 13, 2011 Share Posted October 13, 2011 Yep, it's certainly possible to create doors that close automatically via a script. You can close a door via SetOpenState, and you can run a timer using GetSecondsPassed. I'd recommend using a trigger around the door, with your (persistent) door as its linked ref (use GetLinkedRef to get the door's refID). that way you could use an OnTriggerEnter block and an OnTriggerLeave block to only start counting time once the doorway is empty. See how you go with this - I think it's an excellent scripting exercise. If you run into any issues, just say and I (or anyone else) will give you a hand. Cipscis Link to comment Share on other sites More sharing options...
Stratomunchkin Posted October 15, 2011 Author Share Posted October 15, 2011 Yep, it's certainly possible to create doors that close automatically via a script. You can close a door via SetOpenState, and you can run a timer using GetSecondsPassed. I'd recommend using a trigger around the door, with your (persistent) door as its linked ref (use GetLinkedRef to get the door's refID). that way you could use an OnTriggerEnter block and an OnTriggerLeave block to only start counting time once the doorway is empty. See how you go with this - I think it's an excellent scripting exercise. If you run into any issues, just say and I (or anyone else) will give you a hand. Cipscis Since I don't know a thing about scripting (despite your own tutorial I fear it is a thing I just can't seem to wrap my head around) that hand will be needed. I'll just move ahead and go as far as my understanding goes, and hopefully you can fill in the blanks. Maybe I can learn something that way. scn AutoDoorThis one even I get. :tongue: begin OnTriggerLeaveI know you said both OnTriggerEnter and OnTriggerLeave, but since this is mainly about leaving the trigger area around the door, won't OnTriggerLeave suffice?if setOpenState 1 setOpenState 0 endif? SetOpenState controls the door itself, all right, and if it's open I want it to be closed. Do I do this with the setOpenState command, or do I have to use the getOpenState to do it in phases (closing, closed)? That brings me to the timer. If I use a timer (makes sense), does it have to be in the same way as in your tutorial, ie. a staged timer, or is their a way to tell the program that if setOpenState 1 for longer than 5 seconds to put it back to setOpenState 0? I'd appreciate it if you could run me through the correct way to do this script point by point. The whole thing is like a book with seven seals to me. :confused: Link to comment Share on other sites More sharing options...
Cipscis Posted October 16, 2011 Share Posted October 16, 2011 I'd appreciate it if you could run me through the correct way to do this script point by point. The whole thing is like a book with seven seals to me. :confused:Sure thing begin OnTriggerLeaveI know you said both OnTriggerEnter and OnTriggerLeave, but since this is mainly about leaving the trigger area around the door, won't OnTriggerLeave suffice?The reason why I recommended using both OnTriggerEnter and OnTriggerLeave is that this would allow you to count the number of actors inside the trigger, and only close the door once they've all left. I'll show you what I mean further down in this post. if setOpenState 1 setOpenState 0 endif? SetOpenState controls the door itself, all right, and if it's open I want it to be closed. Do I do this with the setOpenState command, or do I have to use the getOpenState to do it in phases (closing, closed)?There are two things that script functions can do:Return a valuePerform an actionThere are also functions that both perform an action and return a value, but commonly functions that affect a single value will come in Get and Set pairs, where the Get function (GetOpenState in this case) will return a value, and the Set function (SetOpenState) will perform an action, which is almost always changing a value for this type of function although in this case it does a little bit more than that. So, in order to check the current open state of the door, you can use GetOpenState, which you will most likely want to do in an "if" statement. In order to change the current open state of the door, you can use SetOpenState, which will be on a line of its own and takes a parameter to tell it what the open state of the door should become. That brings me to the timer. If I use a timer (makes sense), does it have to be in the same way as in your tutorial, ie. a staged timer, or is their a way to tell the program that if setOpenState 1 for longer than 5 seconds to put it back to setOpenState 0?We won't need to use a staged timer for this, as there would only be one stage. We will still need to use the GetSecondsPassed function, which is the key ingredient to any scripted timer, and a GameMode block in which we will run the timer. The first thing you'll need to do for this, before you write any code, is set up your door and trigger. The door should be a persistent reference, although it doesn't need to have an editorRefID, and the trigger should encompass the door and a small area around it. Then, you'll need to set the door to be the trigger's "linked ref", which allows you to get the door's refID (which we can use to call GetOpenState and SetOpenState on it via the GetLinkedRef function and a "ref" variable to store the value it returns). Once that's set up, here is an example script that you could use, with annotations. Let me know if you have any questions about anything that I've done here. Note that I haven't tested it, so if it turns out that it doesn't work for some reason let me know what seemed to go wrong and I'll take another look and see if I missed anything:ScriptName AutoDoor ref rDoor int iActorsInDoorway float fTimer Begin OnTriggerEnter ; An actor has entered the doorway if rDoor.GetOpenState > 2 ; The door is either closed (3) or closing (4) rDoor.SetOpenState 1 ; Open the door endif if fTimer > 0 ; The timer is running set fTimer to 0 ; Stop the timer endif set iActorsInDoorway to iActorsInDoorway + 1 End Begin OnTriggerLeave ; An actor has left the doorway set iActorsInDoorway to iActorsInDoorway - 1 if iActorsInDoorway == 0 ; The doorway is now empty set fTimer to 3 ; Start the timer (using 3 seconds as an example) endif End Begin GameMode if rDoor == 0 ; All variables are set to 0 before they are assigned set rDoor to GetLinkedRef endif if fTimer > 0 ; The timer is running set fTimer to fTimer - GetSecondsPassed ; Decrement timer if fTimer <= 0 ; The timer just ran out rDoor.SetOpenState 0 ; Close the door endif endif End Cipscis Link to comment Share on other sites More sharing options...
Stratomunchkin Posted October 16, 2011 Author Share Posted October 16, 2011 Oh, I just tried it, and it works just beautifully! Thank you so much, Cipscis! :thumbsup: Link to comment Share on other sites More sharing options...
Stratomunchkin Posted October 16, 2011 Author Share Posted October 16, 2011 Second question added. Link to comment Share on other sites More sharing options...
Recommended Posts