@ Meows,
I took some time out of my schedule to help you out. First, I have a small video that shows our "traversing levels" and key/locked door. I realize that you may not be doing something like this, but the principle is still the same. The player needs to get a key from one level and bring into another.
In this video, the player starts out and makes his/her way to a blue room with three doors (level 2). The player goes into level 5 (red room) and discovers two doors- one locked and requires a key; the other has a winzone and the door is open via switch on the other side of the locked door needing the key. The player will return back to level 2, then go into level 3 (green room). Upon entering level 3, the player picks up the key, then returns to level 2. Turning around, the player re-enters level 3 and the key is not there, then leaves again. The player then enters level 5, where the door can be unlocked and the switch activated to access the winzone. Here is the video:
Now, as far as the scripts I used, here is how I designed it. In level 3, I have the key placed and used the following script for the key's appear:
Key appear script
;Artificial Intelligence Script
;Header
desc = Instant On
;Triggers
:state=0:dimvar=key
:state=0:state=1
:state=1,varequal=key 0:state=5
:state=1,varequal=key 1:state=10
:state=5:setalphafade=100,runfpidefault=1
:state=10:destroy
;End of Script
In the appear script, notice how I call the variable
key, then have it checking the value of key. if the value is equal to 1, that means the player has picked it up already; if not then it loops and checks again until picked up. This is used when player comes and goes into that level multiple times and we only need the key to appear once until picked up.
The next script is the key's main script.
Key main script
;Artificial Intelligence Script
;Header
desc = Pickup Key
;Triggers
:state=0:hudreset,hudx=50,hudy=90,hudimagefine=gamecore\text\pickedupakey.tga,hudname=keyprompt,hudhide=1,hudmake=display,state=10
:state=10,plrdistwithin=40:state=1,playertake,coloff,plrsound=audiobank\misc\ping.wav,hudshow=keyprompt,hudfadeout=keyprompt
:state=1:dimvar=key,state=2
:state=2:setvar=key 1,state=3
:state=3:none
;End of Script
Pretty straight forward. The player picks up the key, and the value of key is set to 1. So if the player leaves level 3 to go back to level 2, then returns to 3, the key appear script will check the variable
key and since the value is already 1, the key is destroyed and therefore is not visible to be picked up.
Here is the door script in level 5 that requires the key:
Door main script
;Artificial Intelligence Script
;Header
desc = Key Door (Open 'With Key' and Close)
;Triggers
:dimvar=key
:state=0:hudreset,hudx=50,hudy=90,hudimagefine=gamecore\text\lockeddoor.tga,hudname=keydoorprompt,hudhide=1,hudmake=display,state=1
:state=1,plrdistwithin=60:hudshow=keydoorprompt,hudfadeout=keydoorprompt
:state=1,plrdistwithin=60,varequal=key 1,plrusingaction=1:state=2,setframe=0,sound=$0
:state=2:incframe=0
:state=2,frameatend=0:state=3,coloff
:state=3,plrdistfurther=60:state=4,sound=$1,colon
:state=4:decframe=0
:state=4,frameatstart=0:state=1,setframe=0
;End of Script
Again, the door script checks the variable
key and will continue to unlock and open if the variable value is set to 1. If the player does not have the key, the door will not unlock and open when the player presses the key to unlock.
So you have to ensure a few things:
1. make sure the key's appear script calls your variable first (my key appear script using "dimvar=key") and is setup according to prevent multiple keys appearing (if using traversing levels).
2. make sure the key main script sets that variable value to what it needs when the key is picked up (my key main script). This value should be the same value as the door value. If the variable value is set to 1 when the key is picked up, then the door would require that same value of 1.
3. ensure the door script checks for the correct value of the variable.
It can get quite confusing at times and complicated, but as I have shown using v1.17, it can be done.
Twitter: @NFoxMedia