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 → *grumbls* been working on this it seems like forever.......
*grumbls* been working on this it seems like forever.......
2003-07-27, 5:47 PM #1
Anyone seen Eraser? Like that cool scope on that EMP gun? Well I've been trying to recreate something like that. Zooming throu walls. But I got this great idea, instead of the old fasion way of FireProjectile with offset vector. Do some math and calculate the pos of the scope and move it there. Good in theory, no? SetThingPos shouldn't change the sector and delete the thing, no? Well, here's what I have so far. See if you can help me.
Code:
# Jedi Knight Cog Script
#
# WEAP_CONCRIFLE.COG
#
# WEAPON 9 Script - Sniper Rifle
#
# Sniper Rifle
#
# - Not affected by MagSealed sectors/surfaces.
#
# [DP]
#

symbols

model       povModel=conv.3do                   local
model       weaponMesh=cong.3do                 local

keyframe    mountAnim=ConVmnt.key               local
keyframe    dismountAnim=ConVdis.key            local
keyframe    povfireAnim=ConVpst1.key            local
keyframe    holsterAnim=kyhlstr.key             local

sound       mountSound=df_rif_ready.wav         local
sound       dismountSound=PutWeaponAway01.wav   local
sound       fireSound=srfire.wav                local
sound       outSound=concuss1.wav               local
sound       zoomSound=scope.wav                 local

flex        fireWait=1.5                        local
flex        powerBoost                          local
flex        autoAimFOV=30                       local
flex        autoAimMaxDist=5                    local
flex        holsterWait                         local

int         dummy                               local

template    projectile=+sniperbullet            local
template    camera=+zoom                        local

thing       player                              local
int         trackID=-1                          local
int         mode                                local
int         holsterTrack                        local
int         selectMode=1                        local

flex        mag=0.25                            local
flex        zoom=0                              local
flex        temp                                local
int         reloading=0                         local
int         moving=0                            local
int         count=0                             local
int         scope=-1                            local
int         oldCam                              local
int         on=0                                local
int         zoomChannel=-1                      local
int         justOn                              local
vector      tempVec                             local
vector      zoomVec                             local

message     activated
message     deactivated
message     selected
message     deselected
message     autoselect
message     user1
message     timer
message     pulse

end

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

code

User1:
   If(reloading) Return;
   // Check that the player is still alive.
   If(GetThingHealth(player) <= 0)
      Return;

   // Check Ammo - If we are out, autoselect best weapon.
   If(GetInv(player, 12) < 1)
   {
      PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80);
      if(GetAutoSwitch() & 1)
         SelectWeapon(player, AutoSelectWeapon(player, 1));
      Return;
   }

   SetPOVShake('0 -.03 0', '4 0 0', .05, 80);
   //FireProjectile(player, projectile, fireSound, 8, '0.02 0.15 0.0', '0 0 0', 1.0, 0x20,
   autoAimFOV, autoAimMaxDist);
   FireProjectile(player, projectile, fireSound, 8, '0 0 0.037', '0 0 0', 1, 0x0, 0, 0);
   ChangeInv(player, 12, -1);
   reloading = 1;

   jkPlayPOVKey(player, povfireAnim, 1, 0x38);

   powerBoost = GetInv(player, 63);
   SetTimerEx(fireWait/powerBoost, 1, 0, 0);

   Return;

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

Activated:
   player = GetSourceRef();
   mode = GetSenderRef();

   If(!on)
   {
      oldCam = GetCurrentCamera();
      If(mode == 1) mag = 5;
      justOn = 1;
   }
   Else justOn = 0;
   jkSetWaggle(player, '0 0 0', 0);
   zoomChannel = PlaySoundLocal(zoomSound, 1, 0, 0x1);
   count = 0;
   moving = 1;
   on = 1;
   zoom = .5 - mode;
   SetPulse(0.01);

   Return;

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

Deactivated:
   player = GetSourceRef();
   mode = GetSenderRef();

   jkSetWaggle(player, '10 7 0', 350);
   moving = 0;
   If(zoomChannel != -1)
   {
      StopSound(zoomChannel, 0);
      zoomChannel = -1;
   }

   If(count <= 3) // If the zoom keys are tapped
   {
      If(mode == 1)
      {
         If(justOn) mag = 5;
         Else If(mag < 5) call scope_off;
         Else mag = 2.5;
      }
      Else
      {
         If(mag < 2.5) mag = 2.5;
         Else If(mag < 5) mag = 5;
         Else call scope_off;
      }
   }
   Return;

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

Selected:
   player = GetSourceRef();

   // Play external mounting animation
   PlayMode(player, 41);

   // Setup the meshes and models.
   jkSetPOVModel(player, povModel);
   SetArmedMode(player, 1);
   jkSetWeaponMesh(player, weaponMesh);
   jkSetWaggle(player, '10.0 7.0 0.0', 350);

   // Play mounting sound.
   PlaySoundThing(mountSound, player, 1.0, -1.0, -1.0, 0x80);

   // Play the animation (NOLOOP + UNIQUE + ENDPAUSE).
   // The animation is held at the last frame after it is played.
   trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
   SetMountWait(player, GetKeyLen(mountAnim));

   // Clear saber flags, and allow activation of the weapon
   jkClearFlags(player, 0x5);
   SetCurWeapon(player, 9);

   // Check Ammo - If we are out, autoselect best weapon.
   If(GetInv(player, 12) < 2)
   {
      PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80);
      if(GetAutoSwitch() & 1)
         SelectWeapon(player, AutoSelectWeapon(player, 1));
   }
   mag = 0.25;
   If(reloading) SetTimerEx(fireWait/powerBoost, 1, 0, 0);

   Return;

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

Deselected:
   player = GetSourceRef();
   If(on) call scope_off;
   If(reloading) KillTimerEx(1);

   PlaySoundThing(dismountSound, player, 1.0, -1, -1, 0x80);
   jkPlayPOVKey(player, dismountAnim, 0, 18);

   holsterWait = GetKeyLen(holsterAnim);
   SetMountWait(player, holsterWait);
   holsterTrack = PlayKey(player, holsterAnim, 1, 0x4);
   SetTimerEx(holsterWait, 2, 0.0, 0.0);
   If (trackID != -1)
   {
      jkStopPOVKey(player, trackID, 0);
      trackID = -1;
   }
   jkSetWaggle(player, '0.0 0.0 0.0', 0);

   Return;

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

//newplayer:
// player = GetSourceRef();
//
// // Make sure that if the player is respawning, the old mount isn't playing anymore.
// if (trackID != -1)
//    jkStopPOVKey(player, trackID, 0);
//
// Return;

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

Autoselect:
   selectMode = GetSenderRef();
   player = GetSourceRef();

   // If the player has the weapon
   if(GetInv(player, 9) != 0.0)
   {
      // If the player has ammo
      if(GetInv(player, 12) > 7.0)
      {

         // query for ammo
         if(selectMode == -1)
         {
            ReturnEx(1000.0);
            Return;
         }

         if((selectMode == 0) && !(GetAutoPickup() & 2))
         {
            ReturnEx(1000.0);
            Return;
         }

         if((selectMode == 1) && !(GetAutoSwitch() & 2))
         {
            ReturnEx(1000.0);
            Return;
         }

         if((selectMode == 2) && !(GetAutoPickup() & 2))
         {
            ReturnEx(1000.0);
            Return;
         }

         ReturnEx(-2.0);
         Return;

      }
      else
      {
         ReturnEx(-1.0);
      }
   }
   else
   {
      ReturnEx(-1.0);
   }

   Return;

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

Timer:
   If(GetSenderID() == 1)
   {
      reloading = 0;
      Return;
   }
   StopKey(player, holsterTrack, 0.0);
   Return;

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

Scope_off:
   If(zoomChannel != -1)
   {
      StopSound(zoomChannel, 0);
      zoomChannel = -1;
   }
   SetPulse(0);
   mag = 0.25;
   on = 0;
   SetCameraFocus(0, player);
   If(oldCam) CycleCamera();
   Return;

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

Pulse:
   If(GetThingHealth(player) <= 0)
   {
      call scope_off;
      Return;
   }

   If(GetCurrentCamera()) CycleCamera();
   If(moving)
   {
      mag = mag + zoom * count * 0.005;
      If(mag > 5) mag = 5;
      If(mag < .25) mag = .25;
      count = count + 1;
   }
   If(mag == 5 && zoom > 0)
   {
      StopSound(zoomChannel, 0);
      zoomChannel = -1;
   }
   If(mag <= 0.25 && zoom < 0)
   {
      call scope_off;
      Return;
   }
   scope = FireProjectile(player, camera, -1, -1, '0 0 0.037', '0 0 0', 1, 0, 0, 0);
   tempVec = VectorAdd(GetThingPos(scope), VectorScale(VectorNorm(GetThingLVec(scope)), mag));
   SetThingPos(scope, tempVec);
   SetCameraFocus(0, scope);

   Return;

end

Code:
The template
+zoom   _weapon   size=0.001 movesize=0.001 vel=(0/0/0) timer=0.015 thingflags=0x0
damageclass=0x0 typeflags=0x0 collide=0
My math is right, but for some reason the scope, whenever it enters another sector, goes to HOM. Ideas or more explanation?

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

The 2 riddle!

[This message has been edited by SaberMaster (edited July 27, 2003).]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-07-27, 6:00 PM #2
First, LVecs returned by verbs like GetThingLVec() are always normalized. Second, SetThingPos() doesn't change the sector. So, when you put the fired weapon in another sector with SetThingPos() it will have the wrong sector - and your HOM is probably caused when the camera tries to look in the wrong sector.

Zooming through walls isn't really a practical thing to try to do, there's no good way in JK to find out if a position is in a sector - so you can't know if you're giving the camera a good viewpoint. You should do some exprimenting with FireProjectile() because as I remember, it has some safeguards for setting its fired thing's sector that might help you.

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-07-28, 8:48 AM #3
PJB, that's a perfect example of an extraneous reply. But since I just wrote out the forum policy, I won't remove it.

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-07-28, 10:16 AM #4
Hehehe. Okay, am I getting good at things or what? [http://forums.massassi.net/html/tongue.gif]
Code:
For(i=0; i<GetSectorCount() && check >= 0; i=i+1)
{
   // Set numbers to center of the sector
   lx = VectorX(GetSectorCenter(i));
   ly = VectorY(GetSectorCenter(i));
   lz = VectorZ(GetSectorCenter(i));
   hx = VectorX(GetSectorCenter(i));
   hy = VectorY(GetSectorCenter(i));
   hz = VectorZ(GetSectorCenter(i));
   check = 0;

   For(j=0; j<GetNumSectorVertices(i); j=j+1)
   {
      // Get the extremes of the sector
      x = VectorX(GetSectorVertexPos(i, j));
      y = VectorY(GetSectorVertexPos(i, j));
      z = VectorZ(GetSectorVertexPos(i, j));
      If(x < lx) lx = x;
      If(y < ly) ly = y;
      If(z < lz) lz = z;
      If(x > hx) hx = x;
      If(y > hy) hy = y;
      If(z > hz) hz = z;
   }
   x = VectorX(GetThingPos(thingy));
   y = VectorY(GetThingPos(thingy));
   z = VectorZ(GetThingPos(thingy));
   If(x >= lx && x <= hx) check = check + 1;
   If(y >= ly && x <= hy) check = check + 1;
   If(z >= lz && x <= hz) check = check + 1;
   If(check == 3) check = -1; // If all checks out, stop loop
}
If(check == -1) check = i;

For those who don't understand what exactly this does. It gets teh farthest vertices' posistions from the center, then checks to see if the thing is within those coords. If so, it must be in that sector.

I'm I good now? [http://forums.massassi.net/html/biggrin.gif] [http://forums.massassi.net/html/cool.gif]

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

The 2 riddle!
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-07-28, 12:05 PM #5
Hate to burst your bubble, Pilot, but consider:
Code:
     +-------+
     |       |
     |       |
     |       |
     |       |
     |       | +-----+
     |       | |     |
     |     @ | |     |
     |       | |     |
     |       | +-----+
     |       |
     |       |
     |       |
     |       |
     |       |
     |       |
     +-------+


If your loop works like it's supposed to, which sector will it return?

I can't think of a way to work this out mathmatically. [http://forums.massassi.net/html/frown.gif]

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.

[This message has been edited by SaberMaster (edited July 28, 2003).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-07-28, 3:36 PM #6
Is it for JK or MOTS?

I'm guessing JK, but if it is MOTS, then you can use FindSectorAtPos(pos); (i think that's the verb)
You can also check if it's -1.
If it's not MOTS, I can't help you.

------------------
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"
2003-07-28, 5:12 PM #7
SM, it would return the sector on the left. Because it goes by sectors and that @ is outside teh one on the right because it is less then the end vertex posistion. SaberMaster, my dear friend and trusted fellow cogger, I've tried it out, it works. Unless you tried it and got that exception....

The math is as follows:
  • 1 - Get the sectors center and set that as the high (positive, right/up) and low (negitive, left/down)
  • 2 - Go by each vertex
    A - Find the pos
    B - Compare its x y z to the lowest x y z seperately, and if for each one that is less, set the low to that
    C - Do the same just the high numbers and greater then
    D - Go on for the next vertex
  • 3 - See if the thing is inside the sector
    A - Check to see if the x y z of the thing is greater than the x y z of the low
    B - Do the same thing execpt with the highs and less than
  • 4 - Abort the loop and the variable i will be the sector


If it was on an adjoin, then it would return the sector with the lowest number. That is the only exception.

edit - JK, because MotS has that verb GetPosSector() or whatever it is. This is basically what the engine does to determine it.

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

The 2 riddle!

[This message has been edited by Descent_pilot (edited July 28, 2003).]

[This message has been edited by Descent_pilot (edited July 28, 2003).]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-07-29, 1:47 AM #8
Quote:
<font face="Verdana, Arial" size="2">Originally posted by Descent_pilot:
...SaberMaster, my dear friend and trusted fellow cogger, I've tried it out, it works. Unless you tried it and got that exception....
</font>


DP, trust me when I say, that WONT WORK.


I dont think there is a flawless way in JK to get a position's sector. In Mots its easy, theres a verb for it, but not in JK. Anyone remember the big fuss I made way back when, when I tried to figure out how to do this? Hell, there is even a chunk of code in the DM resulting from that, but even that code doesnt work properly.


I gave up. I never found a way to do it. If you can, hooray, but dont insult those of us that have tried that method and found it useless.

------------------
Farewell, dear lady...
And when the moment is right, I'm gonna fly a kite.
2003-07-29, 3:56 AM #9
Not really sure I understand it completely but I was thinking:

Code:
   |\
   |  \
   |    \ * 
   |      \   
   |        \
   |__________\


Wouldnt odd shaped sectors mess up your test? Like the above example where the * is outside the sector, but its postions is still less than the extreme vertex positions of the sector?

Im not sure thats really a problem for what your doing since I think it would still find the closest sector, but I dont think it would accurately determine if the * was IN the sector.

------------------
- Wisdom is 99% experience, 1% knowledge. -

[This message has been edited by The_New_Guy (edited July 29, 2003).]
- Wisdom is 99% experience, 1% knowledge. -
2003-07-29, 4:51 AM #10
Point. Edit - I've got it!!!!!!! I don't know how we could do this with cog, but here it is.

What you do is get the vector's to each vertex of the sector, and if all the vectors create a cone, then its not inside the sector. If it creates a hemisphere or a circle (meaning if in 2D it has >= 180ยบ) then that point is therefore inside the sector because no other sector but the current one will pass this. Now just how do we do it..........

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

The 2 riddle!

[This message has been edited by Descent_pilot (edited July 29, 2003).]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack

↑ Up to the top!