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 → the amazing fire command
the amazing fire command
2002-08-09, 4:58 AM #1
GRRRR I have been unsuccessfully trying to create a fire command in my cog that when on primary fire, fires one shot if you hold down fire or even tap it, but another one wont be fired until you hit fire again... with only a very short delay. Secondly I tried to get alternate fire *AT FIRST* to fire a three round burst, but the projectiles all fire at the same time. Now I am trying to work on an alt fire command that toggles between fire modes, one shot and 3rb... The cog is so screwed I decided to just give up and post here [http://forums.massassi.net/html/frown.gif]

------------------
Blue Spandex.
WHEEEEEEEEEE.
2002-08-09, 5:47 AM #2
Could you post a version of your weapon cog without the alt system?

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-08-09, 5:56 AM #3
For your first one, the one with the charge, that is kinda like the crossbow, just reversed and a twist. Post the cog, and I could do that for you.

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

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2002-08-09, 5:58 AM #4
Oh boy.. this is going to be the most embarrasing moment of my cogging career... let me clean it up... ill spare you

------------------
Blue Spandex.
WHEEEEEEEEEE.
2002-08-09, 6:02 AM #5
Okay here goes, this is without custom ammo or any of that (still have yet to get custom ammo to work DP)
Code:
#
#
# WEAP_m16.COG
#
# 
#
#
# This Cog is Not supported by LucasArts Entertainment Co

symbols

model        povModel=vm16.3do                 local                         
model        weaponMesh=gm16.3do               local                         

keyframe     mountAnim=StrVmnt.key              local                         
keyframe     dismountAnim=StrVdis.key           local                         
keyframe     povfireAnim=StrVpst1.key           local                         
keyframe     holsterAnim=kyhlstr.key            local                         

sound        mountSound=df_bry_ready.wav        local                         
sound        dismountSound=PutWeaponAway01.wav  local                         
sound        fireSound=m16.wav                 local                         
sound        outSound=trprout.wav               local                         
sound        clickSound=click.wav               local
sound        reloadsound=rel-1.wav              local
sound        reloadsound1=rel-2.wav             local                         

template     projectile=+repeaterball           local                         

thing        player                             local

vector       randVec                            local                      

flex         fireWait=0.1                       local                    
flex         holsterWait                        local                              

int          dummy                              local                         
int          trackID=-1                         local                         
int          fireChannel=-1                     local                         
int          holsterTrack                       local                         
int          mode                               local                         
int          count=0                            local                         
int          disID                              local                         

message      activated                                                        
message      deactivated                                                      
message      selected                                                         
message      deselected                                                       
message      autoselect                                                       
message      fire                                                             
message      timer                                                            
message      user0                                                            

end                                                                           

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

code

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

   if(count > 29) 
   { 
   PlaySoundThing(clickSound, player, 1.0, -1, -1, 0x80);
   Sleep(1);    
   Return;  
   }

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

   if(GetInv(player, 12) < 1.0)
   {
      PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80);
      if((GetAutoSwitch() & 1))
         SelectWeapon(player, AutoSelectWeapon(player, 1));
      Return;

   }
   if(mode == 0)
   {
     randVec = VectorSet((Rand()-0.5)*5,(Rand()-0.2)*5, 0.0);
   dummy = FireProjectile(player, projectile, fireSound, 8, '0.01 0.12 0', randVec, 1.0, 0x1,    0, 0);
   ChangeInv( player, 12, -1.0 );
   count = count + 1;
   Sleep(1);
   }
   else
   {
        randVec = VectorSet((Rand()-0.5)*5,(Rand()-0.2)*5, 0.0);
   dummy = FireProjectile(player, projectile, fireSound, 8, '0.01 0.12 0', randVec, 1.0, 0x1,    0, 0);
   ChangeInv( player, 12, -1.0 );
   count = count + 1;
   Sleep(1);
     randVec = VectorSet((Rand()-0.5)*5,(Rand()-0.2)*5, 0.0);
   dummy = FireProjectile(player, projectile, fireSound, 8, '0.01 0.12 0', randVec, 1.0, 0x1,    0, 0);
   ChangeInv( player, 12, -1.0 );
   count = count + 1;
   Sleep(1);
     randVec = VectorSet((Rand()-0.5)*5,(Rand()-0.2)*5, 0.0);
   dummy = FireProjectile(player, projectile, fireSound, 8, '0.01 0.12 0', randVec, 1.0, 0x1,    0, 0);
   ChangeInv( player, 12, -1.0 );
   count = count + 1;
   Sleep(1);
   }

   jkPlayPOVKey( player, povfireAnim, 1, 0x38 );
   
   Return;
# ........................................................................................

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

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

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

deactivated:
   player = GetSourceRef();
   jkSetWaggle(player, '10.0 7.0 0.0', 350);
   DeactivateWeapon(player, mode);
   Return;

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

   selected:
   player = GetSourceRef();

   PlayMode(player, 41);
   Print("M16a2 5.56x39mm");
   PlaySoundThing(mountSound, player, 1.0, -1, -1, 0x80);
   jkSetPOVModel(player, povModel);
   SetArmedMode(player, 1);
   jkSetWeaponMesh(player, weaponMesh);
   jkSetWaggle(player, '10.0 7.0 0.0', 350);
   trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
   SetMountWait(player, GetKeyLen(mountAnim));
   jkClearFlags(player, 0x5);
   SetCurWeapon(player, 5);

   Return;

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

   deselected:
   if(fireChannel != -1)
   {
      StopSound(fireChannel, 0.1);
      fireChannel = -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;
# ........................................................................................
   autoselect:
   player = GetSourceRef();

   // If the player has the weapon
   if(GetInv(player, 5) != 0.0)
   {
      // If the player has ammo
      if(GetInv(player, 12) != 0.0)
      {
         ReturnEx(600.0);
      }
      else
      {
         ReturnEx(-1.0);
      }
   }
   else
   {
      ReturnEx(-1.0);
   }

   Return;
 
# ........................................................................................

   user0:
   disID = jkPlayPOVKey(player, dismountAnim, 0, 0x4);
   SetMountWait(player, GetKeyLen(holsterAnim));
   holsterTrack = PlayKey(player, holsterAnim, 1, 0x4);
   if(trackID != -1) { jkStopPOVKey(player, trackID, 0); trackID = -1; }
   PlaySoundThing(reloadsound, player, 1.0, -1, -1, 0x80);
   Sleep(1);
   PlaySoundThing(reloadsound1, player, 1.0, -1, -1, 0x80);
   StopKey(player, holsterTrack, 0);
   PlayMode(player, 41);
   jkStopPOVKey(player, disID, 0);
   trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
   SetMountWait(player, GetKeyLen(mountAnim));
   count = 0;
   Return;

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

   timer:
   StopKey(player, holsterTrack, 0.0);
   Return;

end

dont be to harsh.

would it help if the sleep(1); commands during the fire sequence were shorter? or are they the wrong answer.....

------------------
Blue Spandex.
WHEEEEEEEEEE.

[This message has been edited by sgt_mischa (edited August 09, 2002).]
2002-08-09, 6:43 AM #6
Sleep() commands are alright as long as you don't use more than four sleeps at a time. I added a lock to the activated message in the cog below so there will only be one sleep at a time. Here's the code:
Code:
# WEAP_m16.cog
#
#==============================================================#
symbols

model     povModel=vm16.3do                   local
model     weaponMesh=gm16.3do                 local

keyframe  mountAnim=StrVmnt.key               local
keyframe  dismountAnim=StrVdis.key            local
keyframe  povfireAnim=StrVpst1.key            local
keyframe  holsterAnim=kyhlstr.key             local

sound     mountSound=df_bry_ready.wav         local
sound     dismountSound=PutWeaponAway01.wav   local
sound     fireSound=m16.wav                   local
sound     outSound=trprout.wav                local
sound     clickSound=click.wav                local
sound     reloadsound=rel-1.wav               local
sound     reloadsound1=rel-2.wav              local

template  projectile=+repeaterball            local

thing     player                              local

vector    randVec                             local

flex      wait=0.5                            local
flex      rate=0.1                            local
flex      holsterWait                         local

int       trackID=-1                          local
int       holsterTrack                        local
int       mode                                local
int       count=0                             local
int       disID                               local
int       locked                              local
int       i                                   local

message   startup
message   activated
message   selected
message   deselected
message   autoselect
message   timer
message   user0

end
#==============================================================#
code
#------------------------------------------------------
startup:
	player = GetLocalPlayerThing();
	locked = 0;

Return;
#------------------------------------------------------
activated:
	if(locked) Return;
	locked = 1;
	mode = GetSenderRef();
	if(count > 29)
	{
		PlaySoundThing(clickSound, player, 1.0, -1, -1, 0x80);
		Sleep(1);
		locked = 0;
		Return;
	}
	// Check that the player is still alive.
	if(GetThingHealth(player) <= 0) Return;
	if(GetInv(player, 12) < 1)
	{
		PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80);
		if(GetAutoSwitch() & 1) SelectWeapon(player, AutoselectWeapon(player, 1));
		locked = 0;
		Return;
	}
	if(mode == 0)
	{
		randVec = VectorSet(Rand() - 0.5 * 5, Rand() - 0.2 * 5, 0.0);
		FireProjectile(player, projectile, fireSound, 8, '0.01 0.12 0', randVec, 0, 0, 0, 0);
		ChangeInv(player, 12, -1);
		count = count + 1;
	}
	else if(GetInv(player, 12) >= 3)
	{
		for(i = 0; i < 3; i = i + 1)
		{
			randVec = VectorSet(Rand() - 0.5 * 5, Rand() - 0.2 * 5, 0.0);
			FireProjectile(player, projectile, fireSound, 8, '0.01 0.12 0', randVec, 0, 0, 0, 0);
			Sleep(rate);
		}
		ChangeInv(player, 12, -3);
		count = count + 3;
	}
	jkPlayPOVKey(player, povfireAnim, 1, 0x38);
	Sleep(wait);
	locked = 0;

Return;
#------------------------------------------------------
selected:
	PlayMode(player, 41);
	Print("M16a2 5.56x39mm");
	PlaySoundThing(mountSound, player, 1.0, -1, -1, 0x80);
	jkSetPOVModel(player, povModel);
	SetArmedMode(player, 1);
	jkSetWeaponMesh(player, weaponMesh);
	jkSetWaggle(player, '10.0 7.0 0.0', 350);
	trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
	SetMountWait(player, GetKeyLen(mountAnim));
	jkClearFlags(player, 0x5);
	SetCurWeapon(player, 5);

Return;
#------------------------------------------------------
deselected:
	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;
#------------------------------------------------------
autoselect:
	// If the player has the weapon
	if(GetInv(player, 5) != 0)
	{
		// If the player has ammo
		if(GetInv(player, 12) != 0)
		{
			ReturnEx(600);
		}
		else ReturnEx(-1);
	}
	else ReturnEx(-1);

Return;
#------------------------------------------------------
user0:
	disID = jkPlayPOVKey(player, dismountAnim, 0, 0x4);
	SetMountWait(player, GetKeyLen(holsterAnim));
	holsterTrack = PlayKey(player, holsterAnim, 1, 0x4);
	if(trackID != -1)
	{
		jkStopPOVKey(player, trackID, 0);
		trackID = -1;
	}
	PlaySoundThing(reloadsound, player, 1.0, -1, -1, 0x80);
	Sleep(1);
	PlaySoundThing(reloadsound1, player, 1.0, -1, -1, 0x80);
	StopKey(player, holsterTrack, 0);
	PlayMode(player, 41);
	jkStopPOVKey(player, disID, 0);
	trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
	SetMountWait(player, GetKeyLen(mountAnim));
	count = 0;

Return;
#------------------------------------------------------
timer:
	StopKey(player, holsterTrack, 0.0);

Return;
#------------------------------------------------------
end


The fire message is very similar to the pulse message. Since you want the player to have to press the key again to fire the next shot, then there's no reason to use it. So in the cog above, only the activated message is used. Ask if you need anything changed. [http://forums.massassi.net/html/wink.gif]

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-08-09, 7:55 AM #7
Once again, Saber owned me [http://forums.massassi.net/html/biggrin.gif] I think I can change the problems, the time between shots to slow and the 3rb only recoils on last shot :O Would I add a "if count = 2 only fire two shots type thing? and "if count = 1 fire one shot only" so that the count cant be exceeded

------------------
Blue Spandex.
WHEEEEEEEEEE.
2002-08-09, 8:06 AM #8
Here's how I'd do it, and extra ammo included.
Code:
#
#
# WEAP_m16.COG
#
# 
#
#
# This Cog is Not supported by LucasArts Entertainment Co

symbols
model        povModel=vm16.3do        local
model        weaponMesh=gm16.3do      local
keyframe     mountAnim=StrVmnt.key    local
keyframe     dismountAnim=StrVdis.key local
keyframe     povfireAnim=StrVpst1.key local
keyframe     holsterAnim=kyhlstr.key  local
sound        mountSound=df_bry_ready.wav     local
sound         dismountSound=PutWeaponAway01.wav     local
sound        fireSound=m16.wav        local
sound        outSound=trprout.wav     local
sound        clickSound=click.wav     local
sound        reloadsound=rel-1.wav    local
sound        reloadsound1=rel-2.wav   local
template     projectile=+repeaterball local
thing        player          local
vector       randVec         local
flex         fireWait=0.1    local
flex         holsterWait     local
flex         delay=.5        local
int          dummy           local
int          trackID=-1      local
int          fireChannel=-1  local
int          holsterTrack    local
int          mode            local
int          count=0         local
int          disID           local
int          oldAmmo         local
int          i               local
int          locked=0        local
int          active=0        local
int          type            local

message      activated
message      selected
message      deselected
message      autoselect
message      timer
message      user0
end

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

code

   Activated:
   player = GetSourceRef();
   mode = GetSenderRef();
   If(active) Return;
   active = 1;
   If(count > 29) 
   { 
      PlaySoundThing(clickSound, player, 1.0, -1, -1, 0x80);
      Sleep(1);    
      Return;  
   }

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

   If(mode == 1)
   {
      type = 1 - type;     // Altranates fire type
      Return;
   }

   If(GetInv(player, 12) < 1.0)
   {
      PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80);
      if((GetAutoSwitch() & 1))
         SelectWeapon(player, AutoSelectWeapon(player, 1));
      Return;

   }

   If(type == 0)
   {
     randVec = VectorSet((Rand()-0.5)*5,(Rand()-0.2)*5, 0.0);
   dummy = FireProjectile(player, projectile, fireSound, 8, '0.01 0.12 0', randVec, 1.0, 0x1,    0, 0);
   ChangeInv( player, 12, -1.0 );
   count = count + 1;
   Sleep(1);
   }
   Else
   {
      locked = 1 - locked;
      If(locked) Return;
      For(i=0;i<3;i=i+1)
      {
         If((GetInv(player, 12) < 1) || (count > 29)) Return;
         randVec = VectorSet(Rand() - 0.5 * 5, Rand() - 0.2 * 5, 0.0);
         FireProjectile(player, projectile, fireSound, 8, '0.01 0.12 0', randVec, 0, 0, 0, 0);
         ChangeInv(player, 12, -1);
         count = count + 1;
         Sleep(rate);
      }
   }
   jkPlayPOVKey( player, povfireAnim, 1, 0x38 );
   Sleep(delay);
   Active = 0;
   Return;

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

   Selected:
   player = GetSourceRef();

   PlayMode(player, 41);
   Print("M16a2 5.56x39mm");
   PlaySoundThing(mountSound, player, 1.0, -1, -1, 0x80);
   jkSetPOVModel(player, povModel);
   SetArmedMode(player, 1);
   jkSetWeaponMesh(player, weaponMesh);
   jkSetWaggle(player, '10.0 7.0 0.0', 350);
   trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
   SetMountWait(player, GetKeyLen(mountAnim));
   oldAmmo = GetInv(player, 12);      // Hold old value of origanal ammo
   SetInv(player, 12, GetInv(player, 118));     // Change to extra ammo
   jkClearFlags(player, 0x5);
   SetCurWeapon(player, 5);

   Return;

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

   Deselected:
   If(fireChannel != -1)
   {
      StopSound(fireChannel, 0.1);
      fireChannel = -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);
   SetInv(player, 118, GetInv(player, 12));     // Changes extra ammo
   SetInv(player, 12, oldAmmo);     // Reset old ammo
   Return;
# ........................................................................................
   Autoselect:
   player = GetSourceRef();

   // If the player has the weapon
   if(GetInv(player, 5) != 0.0)
   {
      // If the player has ammo
      if(GetInv(player, 12) != 0.0)
      {
         ReturnEx(600.0);
      }
      else
      {
         ReturnEx(-1.0);
      }
   }
   else
   {
      ReturnEx(-1.0);
   }

   Return;
 
# ........................................................................................

   User0:
   disID = jkPlayPOVKey(player, dismountAnim, 0, 0x4);
   SetMountWait(player, GetKeyLen(holsterAnim));
   holsterTrack = PlayKey(player, holsterAnim, 1, 0x4);
   if(trackID != -1) { jkStopPOVKey(player, trackID, 0); trackID = -1; }
   PlaySoundThing(reloadsound, player, 1.0, -1, -1, 0x80);
   Sleep(1);
   PlaySoundThing(reloadsound1, player, 1.0, -1, -1, 0x80);
   StopKey(player, holsterTrack, 0);
   PlayMode(player, 41);
   jkStopPOVKey(player, disID, 0);
   trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
   SetMountWait(player, GetKeyLen(mountAnim));
   count = 0;
   Return;

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

   Timer:
   StopKey(player, holsterTrack, 0.0);
   Return;

end


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

The Magician Saber System.

[edit - saw your post and updated it also based on the amount of ammo left on you]

[edit agian - [http://forums.massassi.net/html/redface.gif] I didn't look at what it was. Now it should work how you want it to. [http://forums.massassi.net/html/wink.gif] Sorry SM.]

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

Completed
Judgement Day (HLP), My level pack
2002-08-09, 8:40 AM #9
no no descent, semi auto was the point! m16 isnt automatic [http://forums.massassi.net/html/smile.gif]

------------------
Blue Spandex.
WHEEEEEEEEEE.

↑ Up to the top!