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 → GetSenderID
GetSenderID
2001-05-24, 5:43 AM #1
OK, this is Jeff Walters swinging door cog which I've added a switch to

Code:
# Jedi Knight Cog Script
#
# Swing_Sr.cog
#
# Generic Swinging Door Script, C/S version, Server side
#
# [JW]
#
# (C) 1998 Jeff Walters
#
# modified by SlingsRat. Added switch.

symbols
   message     activated
   message     blocked
   message     arrived
   message     timer

   thing       Door   

   surface     switch 

   sound       on_snd=set_hi2.wav	local
  
   flex        Time=4.0
   flex        AutoCloseDelay=0.0

   int         doorID
   int         Rotating=0        	local

end


## Code Section
code

activated:
   
   if (Rotating) return;                  // Rotation already in progress
   Rotating = 1; 
   if (GetSenderID() != 0) return;	
   SetWallCel(switch, 1);
   PlaySoundPos(on_snd, SurfaceCenter(switch), 1.0, 5.0, 10.0, 0);
   SendTrigger(-1, 500000 + doorID, door, 1, Time, 0);
   return;

blocked:
   Time = -Time;
   SendTrigger(-1, 500000 + doorID, door, 1, Time, 0);
	Return;

delayed:
   if (Rotating) return;                  // Rotation already in progress
   Rotating = 1;
   SendTrigger(-1, 500000 + doorID, door, 1, Time, 0);
   return;

arrived:
   if (!Rotating) return;                 // Rotation already finished
   SetWallCel(switch, 0);
   PlaySoundPos(on_snd, SurfaceCenter(switch), 1.0, 5.0, 10.0, 0);
   Time = -Time;                          // Negate time for invers rotation
   Rotating = 0;

   if (AutoCloseDelay > 0.0  &&  Time < 0)
      SetTimer(AutoCloseDelay);           // Prepare delayed automatic closing
   return;

timer:
   call delayed;                          // Delayed closing
   return;

end



trouble is the door still opens when you press on the door itself. I dont really understand the GetSender ID reference. Any help would be great. Thanks.
JK:DFII Editing
ALHan
PSP
2001-05-24, 11:07 AM #2
Since the activated code has the line:
if (GetSenderID() != 0) return;
That means that if the senderID is not equal to 0 then the cog exits, and the door is not opened.

So leave everything the same BUT in your symbols section add a linkid for the DOOR as so:
Code:
thing       Door   linkid=1

Since the id for the door is now 1 and not 0 (or lacking) then touching (activating) the door won't cause it to open. Since the switch lacks a linkid it is the same as 0 and will activate the door.

The other way to do this which is probably what I would actually do is have in symbols:
Code:
thing       Door   linkid=0
surface     switch linkid=1

and change the line in the code section to:
Code:
if (GetSenderID() != 1) return;

This is better because if you add other things or surfaces to the cog, then the switch will still be the only thing that activates the door.


------------------
Sylvicolus JK homepage
If I have ever made any valuable discoveries, it has been owing more to
patient observation than to any other reason. -Isaac Newton
Sylvicolus JK homepage
If I have ever made any valuable discoveries, it has been owing more to
patient observation than to any other reason. -Isaac Newton
2001-05-24, 8:00 PM #3
OK, so far so good. The suggestions work BUT theres a problem. As long as you just use the switch it works fine. If you activate the door itself the door doesnt open BUT from then on not even the switch will work! This seems strange to me. Is it some c/s thing?
JK:DFII Editing
ALHan
PSP
2001-05-25, 8:06 AM #4
You see the lines directly after the activated message? 'If (rotating) return;
roating = 1;' Put those after 'if (GetSenderId() != 1)' (I assume you made the changes already suggested.)
That will fix your not opening later problem.
Heres what was happening:
When you activated the door, the variable rotating was informed that the door was opening and set accordingly. Then, getsenderid shut down the code before the doors actually began to move. Since the doors are in fact not moving, the arrived message nor blocked message are never called and thus rotating is never reset to 0. When you activate it another time, the cog thinks the door is in motion and stops.

Here is the completed cog, atleast how I would do it:

Code:
# Jedi Knight Cog Script
#
# Swing_Sr.cog
#
# Generic Swinging Door Script, C/S version, Server side
#
# [JW]
#
# (C) 1998 Jeff Walters
#
# modified by SlingsRat. Added switch.
# fixed 2001 [JM]

symbols   
message     activated   
message     blocked   
message     arrived   
message     timer   

thing       Door    
surface     switch 	linkid=1  //Anything with a linkid of 1 will open the door  

sound       on_snd=set_hi2.wav	local     
flex        Time=4.0   
flex        AutoCloseDelay=0.0   
int         doorID   
int         Rotating=0        	local
end

## Code Section

code

activated:      

	if (GetSenderID() != 1) return;	   
	if (Rotating != 0) return;                  // Rotation already in progress   
	Rotating = 1;    
	
	SetWallCel(switch, 1);   
	PlaySoundPos(on_snd, SurfaceCenter(switch), 1.0, 5.0, 10.0, 0);   
	SendTrigger(-1, 500000 + doorID, door, 1, Time, 0);  //Tells the client to open the door
	return;

blocked:   
	Time = -Time;   
	SendTrigger(-1, 500000 + doorID, door, 1, Time, 0);	
	Return;

arrived:   
	
	if (Rotating != 1) return;                 // Rotation already finished   
	SetWallCel(switch, 0);   
	PlaySoundPos(on_snd, SurfaceCenter(switch), 1.0, 5.0, 10.0, 0);   
	Time = -Time;                          // Negate time for invers rotation   
	Rotating = 0;   
	if (AutoCloseDelay > 0.0  &&  Time < 0)      
	SetTimer(AutoCloseDelay);           // Prepare delayed automatic closing  
	return;

timer:   
	//call delayed;  -Why call it?                         // Delayed closing   

	//delayed:   
	if (Rotating != 0) return;                  // Rotation already in progress 
	//if this is set to 1, the door will trigger an arrived message when it closes, 
	//and open, then close, then open, then close...  
	Rotating = 2;   
	SendTrigger(-1, 500000 + doorID, door, 1, Time, 0);   
	return;

end
2001-05-25, 12:35 PM #5
Jah JM in cogging ?!
2001-05-25, 5:33 PM #6
Yay it works! Thanks a lot JM and thank you too Sylvicolus.

------------------
Jedi Shopping Mall
JK:DFII Editing
ALHan
PSP
2001-05-26, 6:28 AM #7
Seifer - There is not a part of JK editing in which I am not knowledgable.
2001-05-26, 6:31 AM #8
At least you're modest.

------------------
Together we stand.
Divided we fall.

↑ Up to the top!