Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, rki), 390 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Doors and Keys #454069
08/26/15 16:15
08/26/15 16:15
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

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?

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] #454076
08/26/15 20:38
08/26/15 20:38
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
Budapest
What should do the key function?

Re: Doors and Keys [Re: Aku_Aku] #454077
08/26/15 20:46
08/26/15 20:46
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

Joined: Aug 2013
Posts: 101
change the variable have_key1 to true. If it's key 2, it should change the variable have_key2 to true.

Re: Doors and Keys [Re: mschoenhals] #454079
08/26/15 20:53
08/26/15 20:53
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
Budapest
When should change that variable? What activity does trigger change?

Re: Doors and Keys [Re: Aku_Aku] #454081
08/26/15 21:37
08/26/15 21:37
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

Joined: Aug 2013
Posts: 101
When the player gets the key. So, if he comes within 50 quints, he picks up the key and can unlock the door.

Re: Doors and Keys [Re: mschoenhals] #454082
08/26/15 21:44
08/26/15 21:44
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
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: Aku_Aku] #454085
08/27/15 00:42
08/27/15 00:42
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

Joined: Aug 2013
Posts: 101
Yup. Key should be taken automatically when the player runs over it.

Re: Doors and Keys [Re: mschoenhals] #454111
08/27/15 19:11
08/27/15 19:11
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
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.

Re: Doors and Keys [Re: Aku_Aku] #454116
08/27/15 21:39
08/27/15 21:39
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
Did not read, but wanna leave this. Maybe it helps...
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=439108

Greets


Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1