Tutorial
I was mucking around with scripts and winzones and found that I couldn't really use a winzone through trigger zones and simply slap the code I needed onto the end of a dooruse script. I was surprised how easy it was to do, but I thought its a usefull little script so I'd share it on the forums. All I did was make use of the "if used" property and plrmoveto action.
For this you'll need to modify
dooruse.fpi or any door script, so make a copy of the original (only a little bit needs to be changed, but just always back up original files). In the script all you need to do is add activateifused=1 after the player has opened the door, so the script should be:
;Artificial Intelligence Script
;Header
desc = Use Door (Push Open and Push Closed)
;Triggers
:state=0:hudreset,hudx=50,hudy=90,hudimagefine=gamecore\text\pressentertouse.tga,hudname=usedoorprompt,hudhide=1,hudmake=display,state=10
:state=10,plrdistwithin=60:hudshow=usedoorprompt,hudfadeout=usedoorprompt
:state=10,plrdistwithin=60,plrusingaction=1:activate=2,activateifused=1
:state=10,activated=2:state=1,setframe=0,sound=$0
:state=1:incframe=0
:state=1,frameatend=0:state=2,coloff
:state=2,plrdistwithin=60,plrusingaction=1:activate=0
:state=2,activated=0:state=3,sound=$1,colon
:state=3:decframe=0
:state=3,frameatstart=0:state=10,setframe=0
;End of Script
Once thats happened, set up you're level with a door in it. Under the doors properties find the
"If Used" part. In this field put a simple but unique name for the entity we're going to activate. For simplicity's sake I'm going to call mine
bob.
Create the entity "bob" (be sure to keep the name the same as whats referred to in the door) and place it near the door (it doesnt actually have to be near the door, read on). Make sure bob has no other purpose than to transport the player to the next entity and is set to dynamic. So we're also going to need to create another entity, this one for the player to move to. Make sure this entity is dynamic as well. For simplicity's sake I'm going to call mine
mary.
Now we're going to have to create a new script, name this one something appropriate, such as "plrmovetomary.fpi". Put this into the script:
;Header
desc = Player move to... (entity)
;Triggers
:state=0,plrdistwithin=60:state=1
:state=1:plrmoveto=mary,state=0
;end of script
Those who have read the ocfpsc guide may recognise this script. In this script if the player is within 1 segment of bob than the player will be transported to mary. The reason we needed the opening of the door to activate bob was stop the player being transported to mary as you come close. So we needed to activate bob to spawn bob, then its effects come into place.
Underneath the properties of bob you need to set
Spawn At Start to
NO,
Max at any time to
1,
Number to Spawn to
1,
Maximum Spawn to
1. All this means that only one will spawn, and it will spawn when the door activates it. After that, assign your plrmovetomary.fpi script to bob's main AI script.
Place the entity Mary somewhere secluded (only one segment is needed) and place a winzone in that same spot. If you dont what to let the player know you've teleported them somewhere random just for the effect, you could have a dark room or show a black hud. This is optional, but just do note the room you're transported to (where mary is located) is visible for half a second . . . so you might want to consider what I previously mentioned.
The script does work, but if for some reason it doesnt for you check that:
-the dooruse script is correct (does it contain activateifused=1?)
-the name of the entity to be activated is in the "If Used" field of the door, and is spelt the same
-the two entities are a set to dynamic
-check if you've correctly referred to entities in the scripts
-make sure bob's (or the first entity) properties for spawning are correctly set, without these done properly it wont work
-the scripts are correclty linked (new dooruse in door's main, plrmovetomary in bobs main)
Happy Scripting
I'm inspired by my own wise quotes, thank you.