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 → Since there is cog, I guess its cog related
Since there is cog, I guess its cog related
2005-07-08, 8:44 PM #1
Alright, I have a "small" problem here. The dummyThing that represents the player will not move around the emplaced gun when it rotates along a horizontal (XY in JED) plane. I need ideas or reasons why.
Code:
# Jedi Knight Cog Script
#
# CLASS_EMPLACED.COG
#
# CLASS WEAPON Script - Emplaced Gun
#
# [DP]
#

symbols
thing       emplaced
flex        acc=3
flex        fireWait=0.15
int         clipsize=100
int         tracerper=5
int         warning=10
sound       fireSound=92FS.wav
sound       outSound=concuss1.wav
template    projectile=+bullet50cal
template    projectileT=+bullet50tracer
flex        offsetdist=.1
keyframe    standingAnim=50calstand.key

thing       player                              local
thing       dummything                          local
int         mode                                local
int         holsterTrack                        local
int         rounds                              local
int         reloading                           local
int         dummy                               local
int         inUse=0                             local
int         canFire=1                           local

vector      tempVec                             local
vector      randVect                            local
template    dummytpl=dummyplayer                local
template    chdummy=+chdummy                    local

message     startup
message     activated
message     trigger
message     timer
message     pulse

end

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

code

Startup:
   rounds = clipsize;
   Return;

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

Pulse:
   If(GetThingHealth(player) <= 0) Return;
   dummy = FireProjectile(player, chdummy, -1, -1, '0 0 0', '0 0 0', 0,0,0,0);
   tempVec = GetThingLVec(dummy);
   If(VectorDot(tempVec, GetThingLVec(player)) < .707)
   {
      // Players LVec is only X,Y
      // Since all LVecs distance = 1
      // (x, y)1, 1 is a 45 angle
      If(VectorZ(tempVec) > 0)
         tempVec = VectorAdd(GetThingLVec(player), '0 0 1');
      Else
         tempVec = VectorAdd(GetThingLVec(player), '0 0 -1');
      tempVec = VectorNorm(tempVec);
   }
   SetThingLook(emplaced, tempVec);
   DestroyThing(dummy);

   tempVec = VectorScale(GetThingLVec(player), -offsetdist);
   tempVec = VectorAdd(tempVec, GetThingPos(emplaced));
   SetThingPos(player, tempVec);
   SetThingPos(dummyThing, tempVec);
   SetThingLook(dummyThing, GetThingLVec(player));
   Return;

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

Activated:
   If(!inUse)
   {
      player = GetSourceRef();
      SetInv(player, 10, 1);
      SelectWeapon(player, 10);
      inUse = 1;
      canFire = 1;
      SendMessageEx(GetInvCog(player, 10), User2, emplaced, 0, 0, 0);
      AttachThingToThing(player, emplaced);
      ClearPhysicsFlags(player, 0x1);
      SetThingCurGeoMode(player, 0);
      dummyThing = FireProjectile(emplaced, dummytpl, -1, -1, VectorSet(0, -offsetdist, 0), '0 0 0', 0,0,0,0);
      SetThingModel(dummyThing, GetThingModel(player));
      PlayKey(dummyThing, standingAnim, 1, 0x0);
   }
   Else If(GetSourceRef() == player)
   {
      call backoff;
   }
   Return;

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

Timer:
   If(GetSenderID() == 0 && canFire)
   {
      If(rounds <= 0)
      {
         PlaySoundThing(outSound, emplaced, 1.0, -1, -1, 0x80);
         Return;
      }
      randvect = VectorSet((.5-Rand())*acc, (.5-Rand())*acc, 0);
      If(IsThingCrouching(player)) randvect = VectorScale(randvect, .9);
      // PlayMode(player, 8);
      SendTrigger(-1, 10, 0, 0.02, 0.1, 0);
      If((rounds % tracerper == 0 || rounds <= warning))
         SendTrigger(-1, 11, emplaced, projectileT, VectorX(randvect), VectorY(randvect));
      Else
         SendTrigger(-1, 11, emplaced, projectile, VectorX(randvect), VectorY(randvect));
      // SendTrigger(-1, 10, 0.0135, 0.09, 0.02, 0);
      // SendTrigger(-1, 12, player, case, 0, 0);
      rounds = rounds - 1;
      PlaySoundThing(fireSound, emplaced, 1, -1, -1, 0x80);
      SetInv(player, 14, (rounds/clipsize)*400);
      KillTimerEx(0);
      SetTimerEx(fireWait, 0, 0, 0);
   }
   Return;

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

Trigger:
   If(GetSourceRef() != 15) Return;
   If(GetParam(0) != player) Return;
   If(GetParam(2) != emplaced) Return;
   If(player == -1) Return;

   If(GetParam(3) == 1)
   {
      SetActorFlags(player, 0x84000);
      SetPulse(0.003);
      SetInv(player, 14, (rounds/clipsize)*400);
      SetInv(player, 13, 6/7*200);
      Return;
   }

   If(GetParam(3) == 2)
   {
      call backoff;
      Return;
   }

   If(GetParam(1) >= 0)
   {
      SetTimerEx(fireWait, 0, 0, 0);
      canFire = 1;
   }
   Else
   {
      canFire = 0;
      If(rounds <= 0) call reload;
   }

   Return;

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

BackOff:
   If(!inUse) Return;
   ClearActorFlags(player, 0x84000);
   SetPulse(0);
   SetInv(player, 10, 0);
   SelectWeapon(player, AutoselectWeapon(player, 1));
   DetachThing(player);
   SetPhysicsFlags(player, 0x1);
   SetThingCurGeoMode(player, GetThingGeoMode(player));
   If(dummyThing != -1) DestroyThing(dummyThing);
   dummyThing = -1;
   player = -1;
   InUse = 0;
   Return;

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

Reload:
   rounds = clipsize;
   SetInv(player, 14, (rounds/clipsize)*400);
   Return;

end

The template
Code:
 dummyplayer       _ghoststructure    model3d=ky.3do size=0.268712 movesize=0.268712 puppet=cr.pup

This is the last thing I need to get some emplaced guns working. PS, using SetThingPos() for the same template works in another cog.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2005-07-08, 10:15 PM #2
I'm not entirely sure what the problem is. Do you mean that, for example, the player is sitting in a chair but when the gun swivels the player doesn't move with it? Or am I completely misunderstanding your question?

If I did understand correctly, try this:
AttachThingToThingEx(player, emplaced, 0xC); instead of the basic attach.

If that doesn't work, try 0x6. Just a warning, datamaster says 0x2 is unstable. That's why I suggested 0xC first.
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"
2005-07-08, 10:39 PM #3
[edit] never mind, I don't think that's the problem
visit my project

"I wonder to myself. Why? Simply why? Why why? Why do I ask why? Why do I need to find out why? Why do I have to ask why as a question? Why is why always used to find out why? Why is the answer to why always why? Why is there no final answer to why? Simply why not? Holy cow, this is pretty deep, meaningful **** I wrote. Glad I wrote it down. Oh man."
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ [slog], Echoman
2005-07-08, 11:08 PM #4
The problem is stated in the original post and should be explained by reading the cog. However, for clarification: the problem is that a dummy object is created to mimick the player, but not using the accual player because of keyframes and headpitch, and that object will not pivot around the gun, however the player itself does just fine. And I've tried AttachThingToThing() of all kinds.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2005-07-08, 11:42 PM #5
For my sake, can you try
Code:
dummyplayer      none    type=cog collide=1 move=path model3d=ky.3do size=0.268712 movesize=0.268712 puppet=cr.pup
as the template?
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"
2005-07-09, 8:59 PM #6
Well, I fixed it, the problem was in the template, the move=path won't accept SetThingPos() it seems. *shugs* stupid JK.... specially for SetThingPos() for sectors, accuallym in all aspects, no matter how handy it is. :mad:
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack

↑ Up to the top!