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 → Force Pull out of Aim
Force Pull out of Aim
2003-07-10, 3:02 AM #1
Hi!
I have changed the Force Pull COG and now the weapon that I pull out of someones hands does not fly directly to me, it goes a lot to the right. Help?
Code:
# Jedi Knight Cog Script
#
# FORCE_PULL.COG
#
# FORCEPOWER Script - Force Pull
#  Basic Power
#  Bin 24
#
# [YB]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved


symbols

template    powerup                          local

int         player                           local
int         victim                           local
int         potential                        local
int         throwThing                       local

flex        cost=20.0                        local
int         rank                             local
flex        mana                             local
flex        dot                              local
flex        maxDot                           local

int         type                             local
int         retval=0                         local

vector      dir                              local

sound       pullSound=ForcePull01.WAV        local

int         IsAFlag=0                        local
keyframe    ugthink=UG_ForceThink.key	     local
int	    key=-1			     local
template    t=+twinkle			     local

message     startup
message     activated
message     deactivated
message     pulse
message     timer
message     newplayer
message     killed
message     deselected
message     selected

end

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

code

startup:
   player = GetLocalPlayerThing();

   Return;

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

activated:
   // Cannot use power if blinded
   key=PlayKey(player,ugthink,1,0x004);
   if(GetActorFlags(player) & 0x800) Return;

   if(IsInvActivated(player, 24)) Return;

   mana = GetInv(player, 14);
   rank = GetInv(player, 24);

   if(mana >= cost)
   {
      victim = -1;
      SetInvActivated(player, 24, 1);
      SetPulse(0.01);
   }
   Return;

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

pulse:
   CreateThingatPos(t,GetThingSector(player),VectorSet( (VectorX(GetThingPos(player)))+(rand()*(0.02*2)-0.02) ,  (VectorY(GetThingPos(player)))+(rand()*(0.02*2)-0.02) ,  (VectorZ(GetThingPos(player))+0.04)+(rand()*(0.02*2)-0.02)) ,(0/0/0));
   // Check all things for our victim.
   victim = -1;
   maxDot = 0;

   // Search for all players, actors and items.
   potential = FirstThingInView(player, 20 + 15 * rank, 5.5, 0x424);
   while(potential != -1)
   {
      if(
         HasLOS(player, potential) &&
         (potential != player) &&
         (VectorDist(GetThingPos(player), GetThingPos(potential)) <= (0.5 + rank / 2)) &&
         !(GetThingFlags(potential) & 0x200) &&
         !(GetActorFlags(potential) & 0x100) &&
         !((jkGetFlags(potential) & 0x20) && !IsInvActivated(player, 23))
        )
      {
         // Hack to avoid targetting a CTF flag...
         IsAFlag = 0;
         if(GetThingType(potential == 5))
         {
            if(GetItemFlags(potential) & 8)
            {
               IsAFlag = 1;
            }
         }

         if(!IsAFlag)
         {
            dot = ThingViewDot(player, potential);
	    CreateThingatPos(t,GetThingSector(potential),VectorSet( (VectorX(GetThingPos(potential)))+(rand()*(0.02*2)-0.02) ,  (VectorY(GetThingPos(potential)))+(rand()*(0.02*2)-0.02) ,  (VectorZ(GetThingPos(potential)))+(rand()*(0.02*2)-0.02)) ,'0 0 0');
            if(dot > maxDot)
            {
               victim = potential;
               maxDot = dot;
	       CreateThingatPos(t,GetThingSector(potential),VectorSet( (VectorX(GetThingPos(potential)))+(rand()*(0.02*2)-0.02) ,  (VectorY(GetThingPos(potential)))+(rand()*(0.02*2)-0.02) ,  (VectorZ(GetThingPos(potential)))+(rand()*(0.02*2)-0.02)) ,'0 0 0');

            }
         }

      }
      potential = NextThingInView();
   }

   // If we have a victim...
   if(victim != -1)
   {
      jkSetTargetColors(18, 19, 20);
      jkSetTarget(victim);
   }
   else
   {
      jkEndTarget();
   }

   Return;

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

deactivated:
	StopKey(player,key,1);
   if((victim == -1) || (GetThingHealth(player) <= 0))
   {
      call stop_power;
      Return;
   }

   SetPulse(0);
   jkEndTarget();

   mana = GetInv(player, 14);

   if(mana >= cost)
   {
      if(HasLOS(player, victim))             // check that we still have a LOS on it...
      {
         PlayMode(player, 24);
         PlaySoundThing(pullSound, player, 1.0, -1, -1, 0x80);
         if((GetInv(player, 64) != 1) && (GetInv(player, 65) != 1)) ChangeInv(player, 14, -cost);
         SetBinWait(player, 24, 0.2);

         throwThing = -1;
         type = GetThingType(victim);
         if(type == 2)                       // ACTOR
         {
            if(GetActorWeapon(victim, 1) != -1)
            {
               // Make victim drop powerup.
               throwThing = SkillTarget(victim, player, 24, 0);
               if(throwThing != -1)
               {
                  SetActorWeapon(victim, 1, -1);
                  AmputateJoint(victim, 3);
               }
            }
            else
            {
               SetInvActivated(player, 24, 0);
               Return;
            }

         }
         else
         if(type == 10)                      // OTHER PLAYER
         {
            if(!(GetThingFlags(victim) & 0x200))
               retval = SkillTarget(victim, player, 24, rank);
            SetInvActivated(player, 24, 0);
            Return;
         }
         else
         if(type == 5)                       // ITEM
         {
            retval = SkillTarget(victim, player, 24, rank);
            if(retval != 0)
            {
               if(!GetLifeLeft(victim)) SetLifeleft(victim, 30.0);
               throwThing = victim;
            }
            else
            {
               SetInvActivated(player, 24, 0);
               Return;
            }
         }

         // Throw item at player.
         if(throwThing != -1)
         {
            SetTimerEx(1.5, 1, throwThing, 0);

            // Duplicate sends for lost packets
            SetTimerEx(3.5, 2, throwThing, 0);
            SetTimerEx(3.6, 2, throwThing, 0);

            if(IsMulti())
            {
               // Kill the thing
               SetTimerEx(4.0, 3, throwThing, 0);
               // Duplicate send for lost packets
               SetTimerEx(4.1, 4, throwThing, 0);
            }

            // Turn off gravity for the thing
            ClearPhysicsFlags(throwThing, 0x1);

            dir = VectorScale(VectorNorm(VectorSub(GetThingPos(player), GetThingPos(throwThing))), 30);

            ApplyForce(throwThing, dir);
         }
      }
   }

   SetInvActivated(player, 24, 0);

   Return;

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

timer:

   if(GetSenderId() == 1)
   {
      // We MUST set gravity whatever the original setting,
      // else objects might just float around...
      SetPhysicsFlags(GetParam(0), 1);
      Return;
   }
   else
   if(GetSenderId() == 2)
   {
      // Set back to no gravity after the object had a chance to
      // settle down for next time they respawn...
      ClearPhysicsFlags(GetParam(0), 1);
      Return;
   }
   else
   if(GetSenderId() == 3)
   {
      // SITH_TF_DISABLED
      SetThingFlags(GetParam(0), 0x80000);
      SetLifeLeft(GetParam(0), 26);
      Return;
   }
   else
   if(GetSenderId() == 4)
   {
      SetThingFlags(GetParam(0), 0x80000);
      SetLifeLeft(GetParam(0), 25.9);
      Return;
   }

   Return;

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

selected:
   jkPrintUNIString(player, 24);
   Return;

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

deselected:
   call stop_power;
   Return;

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

killed:
   if(GetSenderRef() != player) Return;

newplayer:
   call stop_power;

   Return;

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

stop_power:
   SetPulse(0);
   SetInvActivated(player, 24, 0);
   victim = -1;
   jkEndTarget();

   Return;

end

And something else... The twinkles that I want aren't covering the things that just stand there...

/Edward
Edward's Cognative Hazards
2003-07-11, 4:52 PM #2
*Might* be that random thing at the top. You also need to change that vector - (0/0/0) - to '0 0 0'. The "/" tells the cog to divide, and everyone knows you can't divide by 0.

------------------
"The Just shall live by faith." - Galatians 3:11
To edit is human... To COG is divine!!

pegasus_1984: Stop bushing that dang suck button.
guitarofgold: NOOOOOOOOO!!!!
-------[end post]-------
Catloaf, meet mouseloaf.
My music
2003-07-11, 10:30 PM #3
It's not your problem, Edward. LEC's cog does the same thing. Add this right before the dir assignment.
Code:
oldRotVel=GetThingRotVel(throwThing);
SetThingRotVel(throwThing, '0 0 0');

And put this in one of the timers
Code:
SetThingRotVel(GetParam(0), oldRotVel);


And that will fix it. [http://forums.massassi.net/html/wink.gif]

Oh, and replace your huge CreateThingAtPos() with something like:
Code:
vec = VectorAdd(GetThingPos(player), VectorScale(RandVec(), yourRandDist));
CreateThingAtPos(t, GetThingSector(player), vec, '0 0 0');


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

[This message has been edited by SaberMaster (edited July 12, 2003).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-07-13, 1:09 AM #4
Hurray! It worked! Thanks! Although, sometimes the weapon does not get released from a guy's hands.

Help please?

/Edward
Edward's Cognative Hazards
2003-07-14, 6:20 PM #5
If a force power is not working on an actor, the first thing I'd check is the skill message of the actor's class cog.

------------------
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-14, 10:41 PM #6
It says nothing in the skill about enemy managing to hold on to his weapon. I guess it is just that, sometimes I can pull, sometimes not...

/Edward
Edward's Cognative Hazards
2003-07-16, 8:07 AM #7
Code:
skill:
   bin = GetParam(0);
   if(bin == 24)                             // Force Pull
   {
      senderref = GetSenderRef();
      newThing = CreateThing(powerup, GetSenderRef());
      SetLifeleft(newThing, 30.0);
      ReturnEx(newThing);

      AISetClass(senderref, flee_ai);
      AIFlee(senderref, GetLocalPlayerThing());

      Return;
   }
   else
   if(bin == 31)                             // Force Grip
   {
      ReturnEx(10);                          // return base damage that is taken by this actor.
      Return;
   }
   else
   if(bin == 34)                             // Deadly Sight
   {
      ReturnEx(10);                          // return base damage that is taken by this actor.
      Return;
   }

   ReturnEx(-1);
   return;


The code block for bin 24 is needed for force pull to work. Without a message like this,
force pull cannot work, because all it does is send a message to the actor's cog telling
him that force pull has been used on him.

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

[This message has been edited by SaberMaster (edited July 16, 2003).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.

↑ Up to the top!