|
Doors and Keys
#454069
08/26/15 16:15
08/26/15 16:15
|
Joined: Aug 2013
Posts: 101
mschoenhals
OP
Member
|
OP
Member
Joined: Aug 2013
Posts: 101
|
Hi all, I'm trying to create locking doors with keys. I can get a rotating door working just fine; I can create the lock and even the variable for unlocking but I can't get the key action to work correctly. I'm uncertain on how to switch my variable during the game. If I switch it in code, it works. Below is the variables, locking function and the door function. Can someone suggest a key action that would work with my code?
var have_key1 = false; //beginning of game you don't have the key
var have_key2 = false;
STRING* got_key_wav = "gotkey.wav"; //sets the file name for getting a key
STRING* door_opens_wav = "dooropens.wav"; //sets the file name for opening the door
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function lock_check(){
if(////////////////////////////////////
(my.skill1 == 0) || //if the door is set to 0, it has no lock. The || means OR.
(my.skill1 == 1 && have_key1) || //you have key one or....
(my.skill1 == 2 && have_key2) //my.skill1 is defined in the first skill of the key model.
){return (false);} //you either have the key or there is no lock
else{
return (true);
}
}
action door(){ //this will appear as the behavior in WED
set(me, POLYGON | SHADOW); //polygon sets it for collision with player.
var door_swing_speed = 5; //variable speed for door swinging
var closed_pan = my.pan; //variable for closed door
var OPEN_OR_CLOSED = 0; // -- 0 is closed
if(is(my,FLAG1)) {OPEN_OR_CLOSED = 1;my.pan+=90;closed_pan = my.pan-90;} //if you check flag1 in WED, 1 is Open.
VECTOR door_handle; //vector spot on the model, that's where the player needs to be closest to activate the door.
vec_for_vertex(door_handle, me, 8); //check what vertex to use for the door handle. This is defined in MED
while(1){wait(1);
if(lock_check() == false){ //lock check is defined above. If it returns false, you can open the door.
if(vec_dist(door_handle.x, player.x) < 100 && key_enter == 1 && my.pan == closed_pan){ //this for a closed door being opened.
set(me, PASSABLE);
while(my.pan < closed_pan+90){wait(1);my.pan+=door_swing_speed;}
SND_CREATE_STATIC(door_opens, door_opens_wav); // play the "door opens" sound
snd_play(door_opens, 100, 0);
reset(me, PASSABLE); //when it is opening, it won't get hung up on things
while(key_enter){wait(1);}
}
if(vec_dist(door_handle.x, player.x) < 100 && key_enter == 1 && my.pan == closed_pan+90){ //this for an open door being closed.
set(me, PASSABLE);
while(my.pan > closed_pan){wait(1);my.pan-=door_swing_speed;}
SND_CREATE_STATIC(door_opens, door_opens_wav); // play the "door opens" sound
snd_play(door_opens, 100, 0);
reset(me, PASSABLE);
while(key_enter){wait(1);}
}
}
}
}
|
|
|
Re: Doors and Keys
[Re: mschoenhals]
#454082
08/26/15 21:44
08/26/15 21:44
|
Joined: Sep 2009
Posts: 1,032 Budapest
Aku_Aku
Serious User
|
Serious User
Joined: Sep 2009
Posts: 1,032
Budapest
|
I think that is a state (possessing the key). Is there a variable that hold that state? OK i can see, the 50 quants proximity is that state. Will be get the key automatically? Next day i can continue this conversion. Stay tuned...
Last edited by Aku_Aku; 08/26/15 21:47.
|
|
|
Re: Doors and Keys
[Re: mschoenhals]
#454111
08/27/15 19:11
08/27/15 19:11
|
Joined: Sep 2009
Posts: 1,032 Budapest
Aku_Aku
Serious User
|
Serious User
Joined: Sep 2009
Posts: 1,032
Budapest
|
I assume, there is a function that controls the movement of the player. I think, this function should check the status of player in each moment. When the function recognizes the proximity between the player and the key is 50 quants or less, then it have to set the relevant variable to store this state, perhaps in the my.skill1. From this point the action door will notice the change and will open the door, in my opinion. I can imagine, may there are other solutions, so you don't need to accept this at the first sight. You can look up for other solutions, if it does not fit to your requirements. Or you can find a flaw in this logic... Anyway, i hope this post helps you in your work.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|