Tripwire Interactive Forums

Go Back   Tripwire Interactive Forums > Killing Floor Forums > Killing Floor Modifications > General Modding Discussion

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-11-2010, 09:10 AM
YoYoBatty's Avatar
YoYoBatty YoYoBatty is offline
Senior Member
 
Join Date: Dec 2009
Location: Canada
Posts: 3,319
Default Tutorial: How to make a Gun that can switch from Semi-Auto to Burst firemodes

Ok so today when I was working on my epicly awesome mod for Killing Floor, I want to make a pistol that could switch from semi-automatic firing mode to a three short burst firing mode. After about 30 or so minutes of trial and error I final got it to work! I was so proud of my achievement that I decided to share it with the Killing Floor community! Here is the code for the weapon without all the fancy stuff required to actually make the gun:

Code:
 
class Singleb extends KFWeapon;
 
replication
{
 reliable if(Role < ROLE_Authority)
  ServerChangeFireMode;
}
// Use alt fire to switch fire modes
simulated function AltFire(float F)
{
    if(ReadyToFire(0))
    {
        DoToggle();
    }
}
// Toggle semi/auto fire
simulated function DoToggle ()
{
 local PlayerController Player;
 Player = Level.GetLocalPlayerController();
 if ( Player!=None )
 {
  //PlayOwnedSound(sound'Inf_Weapons_Foley.stg44_firemodeswitch01',SLOT_None,2.0,,,,false);
  SingleFireB(FireMode[0]).bSetToBurst = !SingleFireB(FireMode[0]).bSetToBurst;
  if ( SingleFireB(FireMode[0]).bSetToBurst )
   Player.ReceiveLocalizedMessage(class'KFTestMut.BurstSwitchMessage',0);
  else Player.ReceiveLocalizedMessage(class'KFTestMut.BurstSwitchMessage',1);
 }
 Super.DoToggle();
 ServerChangeFireMode(SingleFireB(FireMode[0]).bSetToBurst);
}
// Set the new fire mode on the server
function ServerChangeFireMode(bool bNewSetToBurst)
{
     SingleFireB(FireMode[0]).bSetToBurst = bNewSetToBurst;
}
exec function SwitchModes()
{
 DoToggle();
}
Here is the code for the fire itself:

Code:
 
 
class SingleFireB extends KFFire;
 
var() int Burstlength;
var() int Normallength;
var() float Burstrate;
var int RoundsToFire;
var bool bBursting;
var bool bSetToBurst;
simulated function bool AllowFire()  //This doesn't really work but it 
//prevents you from firing the rest of the shots in the burst after
//you reload. Pretty handy anyways.
 
{
 if (Singleb(Weapon).MagCapacity <= 2)
  return false;
 return Super.AllowFire();
}
 
event ModeDoFire()
{
 if(bBursting && RoundsToFire > 0)
  RoundsToFire--;
 //If not already firing, start a burst.
 if(!bBursting && AllowFire())
 {
  bBursting = true;
  RoundsToFire = BurstLength;
  SetTimer(BurstRate, true);
 }
 if(RoundsToFire < 1)
 {
  SetTimer(0, false);
  RoundsToFire = 0;
  bBursting = false;
  return;
 }
        if(!bSetToBurst && AllowFire())
 {
  RoundsToFire = Normallength;
  bBursting = true;
        }
 
 Super.ModeDoFire();
}
 
simulated function Timer()
{
 if(bBursting)
  ModeDoFire();
 else SetTimer(0,false);
}
 
defaultproperties
{
     Burstlength=3.000000
     Burstrate=0.100000
     Normallength=1.000000
     bSetToBurst=False
     bWaitForRelease=True
}
And here is the code for the weapon change message:

Code:
 
class BurstSwitchMessage extends CriticalEventPlus;
var() localized string SwitchMessage[10];
static function string GetString (optional int Switch, optional PlayerReplicationInfo RelatedPRI_1, optional PlayerReplicationInfo RelatedPRI_2, optional Object OptionalObject)
{
 if ( (Switch >= 0) && (Switch <= 9) )
  return Default.SwitchMessage[Switch];
}
defaultproperties
{
     SwitchMessage(0)="Set to Three-Short Burst."
     SwitchMessage(1)="Set to Semi-Automatic."
     DrawColor=(B=0,G=0,R=220)
     FontSize=-2
}

Surely the community will find use for this one way or another
__________________

Last edited by YoYoBatty; 08-21-2010 at 05:53 PM.
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:07 PM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2005 - 2013, Tripwire Interactive, LLC