Hello people!
Welcome to my (first ever) tutorial on how to code a super simple shotgun in UDK using UScript!
Knowledge needed: Beginner.
In this tutorial we will derive from UT classes, You will create a BaseWeapon class and make a ShotgunWeapon deriving from that class.
1. We will begin with making the BaseWeapon class.
First thing we need to do is to make our class extend the original UTWeapon class.
Now we add the variables used within' our code.
Shells, is the amount of bullets the gun will fire at the same time. This is declared in the BaseWeapon class so that weapons deriving from this class can easily configure this. (NOTE: Consummation of ammo is not in this tutorial!)
bIsShotgun, is a bool that will show if the weapon is a shotgun, which is also declared in the weapon class.
2. Making the fire function shoot more than one bullet!
The functions we will use here are from UTWeapon and are handling instantfire & projectile fire modes.
We will begin with ProjectileFire().
Since we have added "super." before ProjectileFire(), it will do what the function does in the main class. Which is spawn a projectile.
The "for(s=0; s < Shells; s++)" tells the function this: If this weapon is a shotgun, then everytime s IS LESS than Shells, Do this inside {} and add +1 to 's'.
This is why we declared Shells because now we can choose how many shells we want to spawn by simply giving the desired number to Shells since the "for" function will run until 's' hits the same amount as Shells.
3. Final part of base code!
Here we put 'bIsShotgun=false' because mainly the weapons aren't shotguns and it's for learning purpose.
Shells is the amount of bullets to spawn, put it at the standard amount of bullets you want for shotgun weapons.
Congratulations! You are now done with your BaseWeapon class!
To make the actual shotgun now, just make a new class extend it from our base class and add the meshes and add in default properties -
EXAMPLE WEAPON USING OUR BASECLASS & IS A SHOTGUN (simply copy, paste & compile)
Finished!
Now we have a nice rocket shooting... O.O ... shotgun.
Here is the code to make a burst & shotgun weapon, please follow above tutorial to know how to make this work correctly, THANKS TO ACECUTTER69 FOR THIS!
Feel free to ask any questions below!
Credits!
TheAgent & another guy that I can remember his name for unconsiosly helping me.
Acecutter69 for burst fire code.
VendorX for tip on right approaches.
100GPing100 for helping code be cleaner.
Fixer for finding and providing a mistake I did.
Welcome to my (first ever) tutorial on how to code a super simple shotgun in UDK using UScript!
Knowledge needed: Beginner.
In this tutorial we will derive from UT classes, You will create a BaseWeapon class and make a ShotgunWeapon deriving from that class.
1. We will begin with making the BaseWeapon class.
First thing we need to do is to make our class extend the original UTWeapon class.
Code:
class BaseWeapon extends UTWeapon;
Code:
var int Shells; // Amount of bullets to be shot! var bIsShotgun; // Used as a detector if the weapon should fire as a shotgun or normally.
bIsShotgun, is a bool that will show if the weapon is a shotgun, which is also declared in the weapon class.
2. Making the fire function shoot more than one bullet!
The functions we will use here are from UTWeapon and are handling instantfire & projectile fire modes.
We will begin with ProjectileFire().
Code:
simulated function Projectile ProjectileFire() // Main function from UTWeapon { local int s; if(bIsShotGun == true) // Make the function check if our weapon actually is a shotgun. { for(s=0; s < Shells; s++) // Spawn the wanted amount of projectiles. { return super.ProjectileFire(); } } else // If it isn't a shotgun then just do the normal ProjectileFire. { return super.ProjectileFire(); // Link to normal ProjectileFire(). } return None; }
The "for(s=0; s < Shells; s++)" tells the function this: If this weapon is a shotgun, then everytime s IS LESS than Shells, Do this inside {} and add +1 to 's'.
This is why we declared Shells because now we can choose how many shells we want to spawn by simply giving the desired number to Shells since the "for" function will run until 's' hits the same amount as Shells.
3. Final part of base code!
Code:
defaultproperties { bIsShotgun=false Shells=8 }
Shells is the amount of bullets to spawn, put it at the standard amount of bullets you want for shotgun weapons.
Congratulations! You are now done with your BaseWeapon class!
To make the actual shotgun now, just make a new class extend it from our base class and add the meshes and add in default properties -
Code:
defaultproperties { /* Code here */ Shells=5 bIsShotgun=true }
Code:
class TUT_Shotgun extends BaseWeapon; defaultproperties { /* WEAPON FIRE PROPERTIES! */ ShotCost(0)=0 // keep these for testing purpose! ShotCost(1)=0 MaxAmmoCount=1 /* CUSTOM CHECKS FOR SHOTGUN! */ bIsShotgun=true // Tells BaseWeapon this is a shotgun! Shells=5 // We want 5 shells! /* WEAPON FIRING MODES! */ FiringStatesArray(0)=WeaponFiring FiringStatesArray(1)=WeaponFiring WeaponFireTypes(0)=EWFT_Projectile // First fire mode is a projectile WeaponFireTypes(1)=EWFT_InstantHit // second is a instanthit! WeaponProjectiles(0)=class'UTProj_Rocket' // The projectile you want the gun to fire! FireInterval(0)=+0.3 // Fire speed! Spread(0)=0.22 // the spread of the bullets! // Weapon SkeletalMesh Begin Object class=AnimNodeSequence Name=MeshSequenceA End Object AttachmentClass=class'UTAttachment_ShockRifle' // Weapon SkeletalMesh Begin Object Name=FirstPersonMesh SkeletalMesh=SkeletalMesh'WP_ShockRifle.Mesh.SK_WP_ShockRifle_1P' AnimSets(0)=AnimSet'WP_ShockRifle.Anim.K_WP_ShockRifle_1P_Base' Animations=MeshSequenceA Rotation=(Yaw=-16384) FOV=60.0 End Object Begin Object Name=PickupMesh SkeletalMesh=SkeletalMesh'WP_ShockRifle.Mesh.SK_WP_ShockRifle_3P' // either keep this or change to your 3rd person mesh. End Object FireOffset=(X=17,Y=0) PlayerViewOffset=(X=14,Y=0,Z=-10.0) // Correction for Shockrifle }
Now we have a nice rocket shooting... O.O ... shotgun.
Here is the code to make a burst & shotgun weapon, please follow above tutorial to know how to make this work correctly, THANKS TO ACECUTTER69 FOR THIS!
Code:
class UTWeapAdv extends UTWeapon; var bool bIsShotgun; var int Shrapnellcount; var bool bBurst; var int Burst, BurstCount; var float BurstInterval; simulated function InstantFire() // Main function from UTWeapon { local int i; if(bIsShotGun == true) // Make the function check if our weapon actually is a shotgun. { for(i=0; i < ShrapnellCount; i++) // Loop And shoot the amount of shrapnell. { super.InstantFire(); } } else if(bBurst) { Burst(); } else // If it isn't a shotgun then just do the normal Fire. { super.InstantFire(); } } simulated function Burst() { if(bProjectile) //dont have source with me atm but replace with the check if should fire proj of instant trace Super.ProjectileFire(); else Super.InstantFire(); if(BurstCount < Burst) SetTimer(BurstInterval, false, 'Burst'); else BurstCount = 0; } simulated function Projectile ProjectileFire() // Main function from UTWeapon { local int i; local projectile P; if(bIsShotGun == true) // Make the function check if our weapon actually is a shotgun. { for(i=0; i < ShrapnellCount; i++) // Spawn the wanted amount of projectiles. { P = super.ProjectileFire(); } } else // If it isn't a shotgun then just do the normal ProjectileFire. { P = super.ProjectileFire(); // Link to normal ProjectileFire(). } return P; // Return what the super function calls. }
Credits!
TheAgent & another guy that I can remember his name for unconsiosly helping me.

Acecutter69 for burst fire code.
VendorX for tip on right approaches.
100GPing100 for helping code be cleaner.
Fixer for finding and providing a mistake I did.
Comment