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:
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.
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.