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 → Got a problem here...
Got a problem here...
2001-07-24, 5:50 PM #1
In my COG, I want it so that if the player is damaged, he falls from the ledge. Take a look at touched: and pulse:

Code:
# Jedi Knight COG Script
#
# CliffHanger_MotS.COG
#
# Created by Emon. E-Mail: emon@coruscant.net - Zone: EJM_Emon - ICQ: 35960628
# Feel free to use this COG as long as credit is given in the readme file.
#
# Allows players to grapple onto ledges, shimmy left or right, fall, or pull themselves
# up. 
#
# Buttons:
# Shimmy Left = Cycle Force left
# Shimmy Right = Cycle Force right
# Drop = Use Force
# Climb Up = Activate / Use
#
# This COG is not supported by LucasArts Entertainment Co.

flags=0x240

symbols

thing        Player                             local                         linkid=2
thing        LeftStop                                                         
thing        RightStop                                                        

keyframe     HangAnim=cliffhang.key             local                         
keyframe     ClimbAnim=cliffclimb.key           local                         
keyframe     ShimmyRight=shimmyright.key        local                         
keyframe     ShimmyLeft=shimmyleft.key          local                         

sound        GrabSound=kylerun01.wav                                          
sound        ShuffleSound=shuffle.wav                                         

surface      Ledge1                             linkid=1                      

int          HangTrack                          local                         
int          Shimmy=0                           local                         
int          Climbing=0                         local                         
int          ShimmyCheck=0                      local                         
int          NoHang=.1                          local                         
int          Hanging=0                          local                         

flex         VecX                               local                         
flex         VecY                               local                         
flex         VecZ=0                             local                         
flex         OldHealth                          local                         
flex         OldShield                          local                         

vector       upVel                              local                         
vector       playerVel                          local                         
vector       newVel                             local                         
vector       sideVel                            local                         
vector       newSideVel                         local                         
vector       OldLook                            local                         

message      startup                                                          
message      touched                                                          
message      playeraction                                                     
message      pulse                                                            
message      timer                                                            

end                                                                           

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

code

startup:

	Player = GetLocalPlayerThing();
	SetCollideType(LeftStop, 0x0);
	SetCollideType(RightStop, 0x0);
	Return;

touched:

	If(GetSenderID() == 1)
	{
	If(GetThingAttachFlags(Player) == 1) Return;
	If(Hanging == 1) Return;
	OldLook = VectorScale(GetSurfaceNormal(Ledge1), -1);
	OldHealth = GetThingHealth(Player);
	PrintFlex(OldHealth);
	OldShield = GetInv(Player, 60);
	PrintFlex(OldShield);
	Hanging = 1;
	SetCollideType(LeftStop, 0x3);
	SetCollideType(RightStop, 0x3);
	PlaySoundLocal(GrabSound, 1, 0, 0);
	SetPulse(.001);
	StopThing(Player);
	SetActorFlags(Player, 0x40000);
	ClearPhysicsFlags(Player, 0x1);
	HangTrack = PlayKey(Player, HangAnim, 1, 0x0);
	SetActionCog(GetSelfCog(), 0x7fffffff);
	}

	else
	If(GetSenderID() == 2)
	{
	Call Detach_Player;
	}

	Return;

playeraction:

	If(GetParam(0) == 3 || GetParam(0) == 7 || GetParam(0) == 8)
        ReturnEx(0);

	else
	If(GetParam(0) == 11)
	{
	  If(GetParam(2) == -1)
	  {
	  ReturnEx(0);
	  Call Shimmy_Left;
	  }
	
	  If(GetParam(2) == 1)
	  {
	  ReturnEx(0);
	  Call Shimmy_Right;
	  }
	}

	else
	If(GetParam(0) == 13)
	{
	ReturnEx(0);
	Call Detach_Player;
	}

	else
	If(GetParam(0) == 2)
	{
	ReturnEx(0);
	If(Shimmy == 1) Return;
	Climbing = 1;
	StopKey(Player, HangTrack, NoHang);
	HangTrack=-1;
	SetActionCog(-1, 0);
	PlayKey(Player, ClimbAnim, 1, 0x38);
	Sleep(.5);
	PlaySoundLocal(ShuffleSound, 1, 0, 0);
	SetPhysicsFlags(Player, 0x1);
	ClearActorFlags(Player, 0x40000);
	upVel = VectorSet(0.0, 0.0, 1.5);
       playerVel = GetThingVel(player);
       newVel = VectorAdd(upVel, playerVel);
	SetThingVel(player, newVel);
	SetPulse(0);
	Climbing = 0;
	SetCollideType(LeftStop, 0x0);
	SetCollideType(RightStop, 0x0);
	Hanging = 0;
	}

	else
	 ReturnEx(1);		
	
	Return;

pulse:

	SetThingLook(Player, OldLook);
	
	If(GetInv(Player, 60) != OldShield || GetThingHealth(Player) != OldHealth)
	{
	PrintFlex(OldHealth);
	PrintFlex(OldShield);
	Call Detach_Player;	
	}

	else
	If(GetAttachFlags(Player) == 1)
	{	
	Call Detach_Player;
	}

	Return;

Shimmy_Left:
	
	If(Climbing == 1 || ShimmyCheck == 1) Return;
	Shimmy = 1;
	ShimmyCheck = 1;
	sideVel = VectorScale((VectorNorm(VectorSub(GetThingPos(RightStop), GetThingPos(Player)))), 1.05);
	VecX = VectorX(sideVel);
	VecY = VectorY(sideVel);
	newSideVel = VectorSet(VecX, VecY, VecZ);
	StopKey(Player, HangTrack, NoHang);
	HangTrack=-1;
	PlayKey(Player, ShimmyLeft, 1, 0x38);
	PlaySoundLocal(ShuffleSound, 1, 0, 0);
	Sleep(.15);
	HangTrack = PlayKey(Player, HangAnim, 1, 0x0);
	SetThingVel(Player, newSideVel);
	Sleep(.1);
	StopThing(Player);
	SetTimer(.3);
	Shimmy = 0;
	Return;
	
	
Shimmy_Right:

	If(Climbing == 1 || ShimmyCheck == 1) Return;
	Shimmy = 1;
	ShimmyCheck = 1;
	sideVel = VectorScale((VectorNorm(VectorSub(GetThingPos(LeftStop), GetThingPos(Player)))), 1.05);
	VecX = VectorX(sideVel);
	VecY = VectorY(sideVel);
	newSideVel = VectorSet(VecX, VecY, VecZ);
	AntiHang=1;
	StopKey(Player, HangTrack, NoHang);
	HangTrack=-1;
	PlayKey(Player, ShimmyRight, 1, 0x38);
	PlaySoundLocal(ShuffleSound, 1, 0, 0);
	Sleep(.15);
	HangTrack = PlayKey(Player, HangAnim, 1, 0x0);
	SetThingVel(Player, newSideVel);
	Sleep(.1);
	StopThing(Player);
	SetTimer(.3);
	Shimmy = 0;
	Return;

timer:
	
	ShimmyCheck = 0;
	Return;

Detach_Player:

	StopKey(Player, HangTrack, NoHang);
	HangTrack=-1;
	SetActionCog(-1, 0);
	SetPhysicsFlags(Player, 0x1);
	ClearActorFlags(Player, 0x40000);
	SetPulse(0);
	SetCollideType(LeftStop, 0x0);
	SetCollideType(RightStop, 0x0);
	Hanging = 0;
	Return;

	

end


As you can see, I'm using a pulse check to see if the player's health or shields change. It sort of works, but I need to get hit like 2 times before it knocks me off.

Any help would be great. Thanks.
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2001-07-24, 6:45 PM #2
Well, couple things.

If(GetInv(Player, 60) != OldShield || GetThingHealth(Player) != OldHealth)

Should be:

If(GetInv(Player, 60) < OldShield || GetThingHealth(Player) < OldHealth)
I mean, you'd want them to be able to use a

bacta tank, right ? [http://forums.massassi.net/html/smile.gif]

Other than that, I'm not sure what the problem would be.. try taking out the else between the if statements in the pulse section..
2001-07-25, 1:32 PM #3
Can't you just put a damaged message in , or put a message under damaged in kyle.cog to send a message to that cog, saying he's damaged.
2001-07-25, 4:48 PM #4
Damaged in this COG doesn't work. And damaged in kyle.cog would lag. That requires sending a message everytime you get hit.
Bassoon, n. A brazen instrument into which a fool blows out his brains.

↑ Up to the top!