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 → MP Door Keys, this cog isn't working l@@K
MP Door Keys, this cog isn't working l@@K
2004-06-14, 6:31 PM #1
I am an intermediate cogger, but I can pretty much solve most problems. But I need a way to have a key door which is synched in MP, cause SP key cogs are screwy in MP
Here's what Ive conjured:

SERVER COG:
Code:
# Jedi Knight Cog Script
#
# DoorKEY_Srv.cog
#
# This cog is not made or endorsed by LucasArts Entertainment Co.

symbols

thing		door                                mask=0x405
int		player                local
int      doorID
flex		sleepTime=2.0

int      doorSector	                        local

message	activated
message	arrived
message	timer
message	blocked
message	startup

end

# ========================================================================================
code
startup:
	doorSector = GetThingSector(door);
   SetSectorAdjoins(doorSector, 0);
	Return;
   
# ........................................................................................

activated:
	door = GetSenderRef();
	player = GetSourceRef();
   SendTrigger(-1, 500000 + doorID, door, 4, doorSector, player);
	Return;

# ........................................................................................

arrived:
	if(IsThingMoving(door)) Return;
   
	if(GetCurFrame(door) == 0)
   {
      SendTrigger(-1, 500000 + doorID, door, 3, doorSector, 0);
   }
   else
   {
      SetTimerEx(sleepTime, 2, 0, 0);
   }
   
	Return;

# ........................................................................................

blocked:
   SendTrigger(-1, 500000 + doorID, door, 11, doorSector, 0);
	Return;

# ........................................................................................

timer:
   if(GetSenderId() == 1) SetInvActivated(player, 46 + key, 0);
   else if(GetSenderId() == 2) SendTrigger(-1, 500000 + doorID, door, 2, doorSector, 0);
   Return;

end

CLIENT COG:
Code:
# Jedi Knight Cog Script
#
# DoorKEY_Cli.cog
#
# Key Door Script, Client side
# Use 0 in "key" for the Red Key (default),
# 1 for Blue, and 2 for Yellow
#
# This cog is not made or endorsed by LucasArts Entertainment Co.

flags=0x240

symbols

int      doorID

sound       locked_snd=i00ky73t.wav
sound       wav0=lvrclik2.wav

int         key=0
int         playerguy                        local

flex	   moveSpeed=1.0
flex       lasttime=-1                      local
flex       curtime=-1                       local

message  trigger

end

# ========================================================================================

code

trigger:
   playerguy = jkGetLocalPlayer();
   if(GetSourceRef() != 500000 + doorID) Return;

   if(GetParam(1) == 1)
   {
      SetSectorAdjoins(GetParam(2), 1);
	   MoveToFrame(GetParam(0), 1, moveSpeed);
   }
   else if(GetParam(1) == 11)
   {
	   MoveToFrame(GetParam(0), 1, moveSpeed);
   }
   else if(GetParam(1) == 2)
   {
      MoveToFrame(GetParam(0), 0, moveSpeed);
   }
   else if(GetParam(1) == 3)
   {
      SetSectorAdjoins(GetThingSector(GetParam(0)), 0);
   }
   else if(GetParam(1) == 4)
   {
      if ((GetInv(GetParam(3), 46 + key) == 1.0) || (GetParam(3) != playerguy))
      { 
         if(IsThingMoving(GetParam(0))) Return;
         if(GetCurFrame(GetParam(0)) != 0) Return;
         if(GetCurFrame(GetParam(0)) == 0)
         {
            SetSectorAdjoins(GetParam(2), 1);
            SetInvActivated(GetParam(3), 46 + key, 1);
            SetTimerEx(2, 1, 0, 0);
            MoveToFrame(GetParam(0), 1, moveSpeed)
         }
      }
      else
      {
         PlaySoundThing(wav0, GetParam(0), 1.0, -1, -1, 0);
         curtime = GetLevelTime();
         if( (lasttime == -1) || (curtime - lasttime > 3) )
         {
            PlaySoundThing(locked_snd, GetParam(3), 1.0, -1, -1, 0);
            Print("You don't have the right key!");
            lasttime = curtime;
         }
      }
   }

   Return;

end




But it isnt working & Im stuck on it now. Ideas? Help?!

[This message has been edited by F-Body (edited June 14, 2004).]
This is retarded, and I mean drooling at the mouth
2004-06-15, 1:31 AM #2
Hm... I'll try something... I have a door+key COG, only it's for SP, but I think I can convert it to MP compatible...
Code:
# A door that requires a KEY!
#
# By Edward
symbols

message		startup
message		activated
message		timer

thing		door
sound		locked
sound		keyneeded

int		key=0

int		open=0		local

end
#
code
startup:
	MoveToFrame(door,0,100);
	open=0;
return;
activated:
	If(GetSenderRef()!=door) return;
	if(GetInv(GetSourceRef(), 46 + key)==1)
	{
		if(open) return;
		open=1;
		SetInvActivated(GetSourceRef(), 46 + key, 1);
		MoveToFrame(door,1,8);
		WaitForStop(door);
		SetTimerEx(3,1,GetSourceRef(),0);
	}
	else
	{
		SetInvActivated(GetSourceRef(), 46 + key, 1);
		PlaySoundThing(locked,door,1,-1,10,0xC0);
		sleep(0.1);
		SetInvActivated(GetSourceRef(), 46 + key, 0);
		SetTimerEx(1,2,GetSourceRef(),0);
	}
return;
timer:
	if(GetSenderID()==1)
	{
		MoveToFrame(door,0,8);
		WaitForStop(door);
		SetInvActivated(GetParam(0), 46 + key, 0);
		open=0;
	}
	else if(GetSenderID()==2)
	{
		PlaySoundThing(keyneeded,GetParam(0),1,-1,-1,0x80);
		print("I require a key...");
	}
return;
end

And, I see that you forgot to test the player for the key... No wait... Ah, I see... OK, you are testing the key. Anyways, I think my COG would be a little easier... Feel free to edit anything you like...

/Edward


[This message has been edited by Edward (edited June 15, 2004).]
Edward's Cognative Hazards
2004-06-15, 6:09 PM #3
Ok Edward, your cog works but not in MP with clients. I used your cog as a guide to help me create these new ones (following). I am pretty sure everything is in check but when I activate the door nothing happens. Its as though it doesn't recognize the player.

SERVER COG:
Code:
# Jedi Knight Cog Script
#
# PTDoorKEY_Srv.cog
#
# [CK] - Tweaked by F-Body
#
# This cog is not made or endorsed by LucasArts Entertainment Co.

symbols

thing		door                                mask=0x405

int		doorID
int		open=0		local

flex		sleepTime=2.0
flex		moveSpeed=1.0

message	activated
message	trigger
message	timer
message	blocked
message	startup

end

# ========================================================================================
code
startup:
   MoveToFrame(door,0,moveSpeed);
   open=0;
   Return;
   
# ........................................................................................

activated:
   If(GetSenderRef()!=door) return;
   SendTrigger(-1, 500000 + doorID, GetLevelTime(), 1, GetSourceRef(), open);
   Return;

# ........................................................................................

blocked:
   MoveToFrame(door,1,moveSpeed);
   Return;

# ........................................................................................

trigger:
   if(GetSourceRef() != 500001 + doorID) Return;

   if(GetParam(1) == 2)
   {
      MoveToFrame(door,1,moveSpeed);
      WaitForStop(door);
      SetTimerEx(sleepTime,1,0,0);
   }

   Return;

# ........................................................................................

timer:
   if(GetSenderID()==1)
   {
      MoveToFrame(door,0,moveSpeed);
      WaitForStop(door);
      open=0;
   }
   Return;

end


CLIENT COG:
Code:
# Jedi Knight Cog Script
#
# PTDoorKEY_Cli.cog
#
# Key Door Script, Client side
# Use 0 in "key" for the Red Key (default),
# 1 for Blue, and 2 for Yellow
#
# [CK] - Tweaked by F-Body
#
# This cog is not made or endorsed by LucasArts Entertainment Co.

flags=0x240

symbols

int      doorID

sound       locked_snd=i00ky73t.wav
sound       wav0=lvrclik2.wav

int         key=0

flex       lasttime=-1                      local
flex       curtime=-1                       local

message  trigger
message  timer

end

# ========================================================================================

code

trigger:
   if(GetSourceRef() != 500000 + doorID) Return;

   if(GetParam(1) == 1)
   {
      if (GetInv(GetParam(2), 46 + key) == 1)
      { 
         if(GetParam(3)) Return;
         GetParam(3)=1;
         SetInvActivated(GetParam(2), 46 + key, 1);
         SendTrigger(-1, 500001 + doorID, 0, 2, GetParam(2), 0);
         SetTimerEx(3,1,GetParam(2),0);
         }
      }
      else
      {
         PlaySoundThing(wav0, GetParam(2), 1.0, -1, -1, 0);
         curtime = GetParam(0);
         if( (lasttime == -1) || (curtime - lasttime > 3) )
         {
            PlaySoundThing(locked_snd, GetParam(2), 1.0, -1, -1, 0);
            Print("You don't have the right key!");
            lasttime = curtime;
         }
      }
   }

   Return;

# ........................................................................................

timer:
   if(GetSenderId() == 1) SetInvActivated(GetParam(0), 46 + key, 0);
   Return;

end



------------------
nil nip nada zip zero naught lip zil
This is retarded, and I mean drooling at the mouth

↑ Up to the top!