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 → Trip Mines
Trip Mines
2005-08-31, 4:44 PM #1
I modified the sequencer charge cog and made it so that fire 1 sets a
trip mine and fire 2 does the normal proximity mine, the trip mine doesnt
use projectiles to see when players or actors are setting it off and there
is no limit to the amount of trip mines a player can set.
I didnt make it so the mine shoots a beam that players can see, you can
add one if you want.
I havent tested it in MP but i think i should work.
If the trip mine is set at ankle level it wont go off, if you find this a problem
then just adjust the part where it finds the SIZE and have it add a little to
the size.
I dont know if it has been done before or if anyone needs it but if anyone
wants to use this cog or parts of it go ahead.
Code:
# Jedi Knight Cog Script
#
# WEAP_SEQCHARGE.COG
#
# WEAPON 8 Script - Sequencer Charge
#
# Heartier than the Thermals and the DF IM Mines these are used by placing them on
#  the ground or on walls.  These have both delayed and proximity options.
#
# - Not affected by MagSealed sectors/surfaces.
#
# [YB & CYW]
# Modified by DSLS_DeathSythe - for trip mines
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved
# ========================================================================================

symbols

model       povModel=seqv.3do             local
model       weaponMesh=seqg.3do           local

keyframe    mountAnim=SeqVmnt.key         local
keyframe    dismountAnim=SeqVdis.key      local
keyframe    povfireAnim=SeqVpst1.key      local
keyframe    holsterAnim=kyhlstr.key       local

flex        mountWait                     local
flex        fireWait=0.8                  local
flex        holsterWait                   local

template    projectile_tpl=+seqchrg       local
template    projectile_tpl2=+seqchrg2     local
int         projectile                    local

material    flashing=seq0mtp3.mat         local
int         cel                           local
int         mode                          local

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

int         selectMode=1                  local

message     startup
message     activated
message     deactivated
message     selected
message     deselected
#message     newplayer
message     autoselect
message     fire
message     timer
#----------------------------------
message	pulse

thing		mine=-1		local
thing		victim=-1		local

vector	vec			local
vector	vec2			local

int		a=0			local
flex		size=0.0		local
flex		dist=0.0		local
flex		dot=0.0		local

sound		trip_snd=schargecountdown02.wav	local
template	exp_tpl=+sequencer_exp	local
#----------------------------------
end
#========================================================================================
code

startup:
   // Setup delays and variables.
   mountWait    = GetKeyLen(mountAnim);

   // Start the material flashing.
   MaterialAnim( flashing, 4, 1 );
return;
#-----------------------------------------------------------------------------------------
fire:
//Print("firing message");
	player = GetSourceRef();
	mode = GetSenderRef();

	// Check that the player is still alive.
	if(GetThingHealth(player) <= 0)
		{
		return;
		}

	projectile = FireProjectile(player, projectile_tpl[mode], -1, 16, '0 0.05 0.00', '0 0 0', 1.0, 0, 0.0, 0.0);
	jkPlayPOVKey(player, povfireAnim, 1, 0x38);
	ChangeInv(player, 8, -1.0);

	if(mode == 0)
		{
Print("Trip Mine Set");
		CaptureThing(projectile);
		SetTimerEx(2.0, projectile, GetThingSignature(projectile), 0);
		//SetThingPulse(projectile, 2.0);
		SetLifeLeft(projectile, 60.0);
		}

	// If out of ammo try to autoswitch to another weapon
	// if autoswitch is enabled else just switch to fists.
	if(GetInv(player, 8) < 1)
		{
		if(GetAutoSwitch() & 1)
			{
			SelectWeapon(player, AutoSelectWeapon(player, 1));
			}
		else
			{
			SelectWeapon(player, 1);
			}
		}
return;
#-----------------------------------------------------------------------------------------
activated:
   player = GetSourceRef();
   mode = GetSenderRef();

   if(mode > 1) Return;

   jkSetWaggle(player, '0.0 0.0 0.0', 0);
   ActivateWeapon( player, fireWait, mode );

   Return;

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

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

   jkSetWaggle(player, '10.0 7.0 0.0', 350);
   DeactivateWeapon( player, mode );
   Return;

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

selected:
   player = GetSourceRef();

   PlayMode(player, 40);
   jkSetPOVModel(player, povModel);
   SetArmedMode(player, 0);
   jkSetWeaponMesh(player, weaponMesh);
   trackID = jkPlayPOVKey(player, mountAnim, 0, 20);

   jkSetWaggle(player, '10.0 7.0 0.0', 350);

   SetMountWait(player, GetKeyLen(mountAnim));
   jkClearFlags(player, 0x5);
   SetCurWeapon(player, 8);

   Return;

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

deselected:
   player = GetSourceRef();

   jkPlayPOVKey(player, dismountAnim, 0, 18);

   holsterWait = GetKeyLen(holsterAnim);
   SetMountWait(player, holsterWait);
   holsterTrack = PlayKey(player, holsterAnim, 1, 0x4);
   SetTimerEx(holsterWait, 1000, 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 ammo
   if(GetInv(player, 8) != 0)
   {
      // query for ammo
      if(selectMode == -1)
      {
         ReturnEx(300.0);
         Return;
      }

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

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

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

      ReturnEx(-2.0);
      Return;

   }
   else
   {
      ReturnEx(-1.0);
   }

   Return;

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

timer:
	if(GetSenderID() == 1000)
		{
		StopKey(player, holsterTrack, 0.0);
		return;
		}
	if(GetParam(0) = GetThingSignature(GetSenderID()))
		{
Print("Trip Mine Armed");
		SetThingPulse(GetSenderID(), 0.05);
		}
return;
#----------------------
pulse:
	mine = GetSenderRef();
	victim = -1;
	//-check for PLAYERS ONLY and check
	// if they are setting the mine off.
//	for(a=0; a<GetNumPlayers(); a=a+1)
//		{
//		victim = GetPlayerThing(a);
//		if(HasLOS(mine, victim))
//			{
//			size = GetThingCollideSize(victim);
//			dist = VectorDist(GetThingPos(mine), GetThingPos(victim));
//			vec = GetThingUVec(mine);
//			vec2 = VectorNorm(VectorSub(GetThingPos(victim), GetThingPos(mine)));
//			vec2 = VectorCross(vec, vec2);
//			dot = VectorLen(vec2)*dist;
//			if(dot<size)
//				{
//Print("BOOOM!!!");
//				PlaySoundThing(trip_snd, mine, 1.0, -1, -1, 0x0);
//				//-exp type 1
//				SetLifeLeft(mine, 0.01);
//				//-exp type 2
//				CreateThing(exp_tpl, mine);
//				//-exp type 3
//				FireProjectile(mine, exp_tpl, -1, -1, '0 0 0', '0 0 0', 1.0, 0, 0.0, 0.0);
//				DestroyThing(mine);
//				a = 1001;
//				}
//			}
//		}
	//-Look through all the things for
	// ACTORS & PLAYERS and check if
	// they are setting off the mine
	for(a=0; a<1000; a=a+1)
		{
		if(GetThingType(a) == 2 || GetThingType(a) == 10)
			{
			victim = a;
			if((victim != -1) && (HasLOS(mine, victim)))
				{
				size = GetThingCollideSize(victim);
				dist = VectorDist(GetThingPos(mine), GetThingPos(victim));
				vec = GetThingUVec(mine);
				vec2 = VectorNorm(VectorSub(GetThingPos(victim), GetThingPos(mine)));
				vec2 = VectorCross(vec, vec2);
				dot = VectorLen(vec2)*dist;
				if(dot<size)
					{
//Print("BOOOM!!!");
					PlaySoundThing(trip_snd, mine, 1.0, -1, -1, 0x0);
					//-exp type 1
//					SetLifeLeft(mine, 0.01);
					//-exp type 2
//					CreateThing(exp_tpl, mine);
					//-exp type 3
					FireProjectile(mine, exp_tpl, -1, -1, '0 0 0', '0 0 0', 1.0, 0, 0.0, 0.0);
					DestroyThing(mine);
					a = 1001;
					}
				}
			}
		}
//	SetThingPulse(mine, 0.05);
return;
#######################
end
Famous last words - "It seemed like a good idea at the time."
2005-09-01, 8:24 PM #2
I think I could use this, at one point in time I was working on something like this, but I gave up since I couldnt find a good way to lay more than 1 good tripmine at a time. It will probably take me a while to test this tho. And yes, if I ever release something with this then your name will surely be on it ;)
This is retarded, and I mean drooling at the mouth
2005-09-02, 10:03 AM #3
Nice vector calculation there.

It's practically nothing in current JK engine but you could use GetThingCount() instead of vague '1000', set it in a variable and put it var + 1 to end 'for' loop.

Also, a very rare case, but you should check for 'mine' existance as in thing signature in fire message upon executing under if(dot>size), as its asynchronously counting 1 minute life could end after entering pulse, making 'mine' variable as 0, which will cause player destruction for crash.
2005-09-02, 1:30 PM #4
Originally posted by Hideki:
Also, a very rare case, but you should check for 'mine' existance as in thing signature in fire message upon executing under if(dot>size), as its asynchronously counting 1 minute life could end after entering pulse, making 'mine' variable as 0, which will cause player destruction for crash.


Nice use of run on sentences there. :confused:
This is retarded, and I mean drooling at the mouth
2005-09-02, 4:11 PM #5
Originally posted by F-Body:
Nice use of run on sentences there. :confused:

Don't you dare make fun of Hideki, he's a legend and english isn't his first language.

/me bows to hideki
your tutorials got me started! Makes me happy to see you posting occasionally.
</sarcasm>
<Anovis> mmmm I wanna lick your wet, Mentis.
__________
2005-09-02, 7:19 PM #6
Originally posted by Hideki:
It's practically nothing in current JK engine but you could use GetThingCount() instead of vague '1000', set it in a variable and put it var + 1 to end 'for' loop.

When i tried to use 'GetThingCount()' it didnt account for actors created by a cog, so they wouldnt set off the mine.
Thats why i used the '1000', it seems to work fine.
Quote:
Also, a very rare case, but you should check for 'mine' existance as in thing signature in fire message upon executing under if(dot>size), as its asynchronously counting 1 minute life could end after entering pulse, making 'mine' variable as 0, which will cause player destruction for crash.

It would be a very very rare case, and i dont see how it could happen. Im not sure about how to test for it the way your saying to.
Could you or someone else demonstrate it?
Famous last words - "It seemed like a good idea at the time."
2005-09-03, 10:57 AM #7
Strange, because GetThingCount() ought to work, because that's the max number of things a level can have at any one time... :confused:

As for the signature checking... something like this
Code:
created:
   it = GetSenderRef();
   sig = GetThingSignature(it);
   SetThingPulse(it, 0.1);
   return;

pulse:
   it = GetSenderRef();
   if(GetThingSignature(it) != sig)   //not the same sender
   {
      return;
   }
   ... <do stuffs>
   return;
May the mass times acceleration be with you.
2005-09-03, 12:53 PM #8
That would work if i wanted the cog to be able to place only one mine at a time.
if more than one mine was place that would mess everything up.
I dont think im going to worry about that problem unless it ever happens.
thanks anyways
Famous last words - "It seemed like a good idea at the time."

↑ Up to the top!