Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Using a key with a switch
Using a key with a switch
2006-12-24, 1:59 AM #1
This is cog question on how to use a key with a switch. On level 3 of JK there is a switch you have to use with the red key to open the door (There is also one on level 19). What is the best cog to use? I have tried to use 03doorkey.cog (thinking that it might be used for the switch/key). Thanks :)
'Its always a good idea to move foward not back'

/Axecrasher/
2007-01-07, 11:28 PM #2
I don't know if there is a premade generic cog for that, but I figured it would be something interesting to try. Besides now I can use this idea in my level as well. I will make a quick appology now if these cogs are sloppy, but I have only been cogging for about a week. I did it with two cogs 1: to activate the switch and 2: to handle the door. The first one : Switch.cog

Code:
# SWITCH.GOG
# activates switch
#
#
# Defiled by freshlamb


symbols

message		startup
message		activated

surface		switch0
surface		switch1	

sound		onsound
sound		offsound

int			player		local
int			amion		local
end

code

//-----------------------------------------------------------------------------

startup:
	player=GetLocalPlayerThing();
	SetWallCel(switch0,0);
	SetWallCel(switch1,0);
	amion = GetWallCell(switch);
	return;

//-----------------------------------------------------------------------------

activated:

	amion = GetWallCel(switch0);
	if(amion == 1){
		SetWallCel(switch0,0);
		SetWallCel(switch1,0);
		PlaySoundPos(offsound, SurfaceCenter(switch0), 1, -1, -1, 0x4); 
		amion = 0;
		}
	else {
		SetWallCel(switch0,1);
		SetWallCel(switch1,1);
		PlaySoundPos(onsound, SurfaceCenter(switch0), 1, -1, -1, 0x4); 
		amion = 1;
		}

	return;


end


the door cog : SwitchKeyDoor.cog

Code:
# SWITCHKEYDOOR.COG
# opens door if switch activated and has the right key
#
#
#
#
# Defiled by freshlamb


symbols

message		startup
message		activated
message		timer

surface		switch			
thing		door0			linkid=1	mask=0x405
float		moveSpeed=8.0
thing		key
float		sleeptime

int		player			local
int		dont			local
int		amion			local
int		what			local
sound       	locksound=df_door2-3.wav	local

end

code

//-----------------------------------------------------------------------------

startup:
	player=GetLocalPlayerThing();
	key = key + 46;
	amion = 0;
	dont = 0;
	return;

//-----------------------------------------------------------------------------

activated:

	
	what = GetSenderRef();
	amion = GetWallCel(switch);
	if((what == door0) && (amion == 1)) {
		if(IsInvAvailable(player,key) == 0) return;		
		dont = IsThingMoving(door0);
                if(dont == 1) return;
		MoveToFrame(door0, 1, moveSpeed);
		SetTimer(sleeptime);
		}
	else {
		if(what == door0) PlaySoundLocal(locksound, 1, 0, 0);
		}
	return;

//-----------------------------------------------------------------------------


timer:

	SetWallCel(switch,0);
	MoveToFrame(door0, 0, moveSpeed);
	amion = 0;
	dont = 0;
	return;

end


just paste them into cogpad, save and insert your variables in JED. Hope this helps. Maybe someone has a better cog?

↑ Up to the top!