HTWeapon: Part 1 – Adding Ammo   46 comments

Video Version

Subject: HTWeapon: Part 1 – Adding Ammo
Skill Level: Beginner
Run-Time: 30 minutes
Author: Michael Allar
Notes: How to implement a very basic ammo system in our custom weapon class, taking code from UTWeapon.

Streaming:     720×480 1920×1080

Download:     Low-Res (66MB) Hi-Res (200MB)

Written Version

Subject: HTWeapon: Part 1 – Adding Ammo
Skill Level: Beginner
Author: Michael Allar
Notes: How to implement a very basic ammo system in our custom weapon class, taking code from UTWeapon.

See video for an in-depth explanation. Sorry about the indentation, it seems like my indentation will not survive copy paste… D:

HTWeapon

/*******************************************************************************
 HTWeapon

 Creation date: 08/03/2010 06:21
 Copyright (c) 2010, Allar

*******************************************************************************/

class HTWeapon extends UDKWeapon;

/** Current ammo count */
var repnotify int AmmoCount;

/** Max ammo count */
var int MaxAmmoCount;

/** Holds the amount of ammo used for a given shot */
var array<int> ShotCost;

/** Offset from view center */
var(FirstPerson) vector    PlayerViewOffset;

replication
{
 // Server->Client properties
 if ( bNetOwner )
 AmmoCount;
}

simulated event ReplicatedEvent(name VarName)
{
 if ( VarName == 'AmmoCount' )
 {
 if ( !HasAnyAmmo() )
 {
 WeaponEmpty();
 }
 }
 else
 {
 Super.ReplicatedEvent(VarName);
 }
}

simulated function int GetAmmoCount()
{
 return AmmoCount;
}
 /*
 * Consumes some of the ammo
 */
function ConsumeAmmo( byte FireModeNum )
{
 // Subtract the Ammo
 AddAmmo(-ShotCost[FireModeNum]);
}

/**
 * This function is used to add ammo back to a weapon.  It's called from the Inventory Manager
 */
function int AddAmmo( int Amount )
{
 AmmoCount = Clamp(AmmoCount + Amount,0,MaxAmmoCount);
 return AmmoCount;
}

/**
 * Returns true if the ammo is maxed out
 */
simulated function bool AmmoMaxed(int mode)
{
 return (AmmoCount >= MaxAmmoCount);
}

/**
 * This function checks to see if the weapon has any ammo available for a given fire mode.
 *
 * @param    FireModeNum        - The Fire Mode to Test For
 * @param    Amount            - [Optional] Check to see if this amount is available.  If 0 it will default to checking
 *                              for the ShotCost
 */
simulated function bool HasAmmo( byte FireModeNum, optional int Amount )
{
 if (Amount==0)
 return (AmmoCount >= ShotCost[FireModeNum]);
 else
 return ( AmmoCount >= Amount );
}

/**
 * returns true if this weapon has any ammo
 */
simulated function bool HasAnyAmmo()
{
 return ( ( AmmoCount > 0 ) || (ShotCost[0]==0 && ShotCost[1]==0) );
}

/**
 * This function retuns how much of the clip is empty.
 */
simulated function float DesireAmmo(bool bDetour)
{
 return (1.f - float(AmmoCount)/MaxAmmoCount);
}

/**
 * Returns true if the current ammo count is less than the default ammo count
 */
simulated function bool NeedAmmo()
{
 return ( AmmoCount < Default.AmmoCount );
}

/**
 * Cheat Help function the loads out the weapon
 *
 * @param     bUseWeaponMax     - [Optional] If true, this function will load out the weapon
 *                              with the actual maximum, not 999
 */
simulated function Loaded(optional bool bUseWeaponMax)
{
 if (bUseWeaponMax)
 AmmoCount = MaxAmmoCount;
 else
 AmmoCount = 999;
}

/**
 * Called when the weapon runs out of ammo during firing
 */
simulated function WeaponEmpty()
{
 // If we were firing, stop
 if ( IsFiring() )
 {
 GotoState('Active');
 }

 if ( Instigator != none && Instigator.IsLocallyControlled() )
 {
 Instigator.InvManager.SwitchToBestWeapon( true );
 }
}

/*********************************************************************************************
 * Ammunition / Inventory
 *********************************************************************************************/

function PrintScreenDebug(string debugText)
{
 local PlayerController PC;
 PC = PlayerController(Pawn(Owner).Controller);
 if (PC != None)
 PC.ClientMessage("HTWeapon: " $ debugText);
}

simulated function AttachWeaponTo( SkeletalMeshComponent MeshCpnt, optional Name SocketName )
{
 local HTPawn HTP;

 HTP = HTPawn(Instigator);
 PrintScreenDebug("Attaching Weapon");
 // Attach 1st Person Muzzle Flashes, etc,
 if ( Instigator.IsFirstPerson() )
 {
 AttachComponent(Mesh);
 EnsureWeaponOverlayComponentLast();
 SetHidden(False);
 Mesh.SetLightEnvironment(HTP.LightEnvironment);
 PrintScreenDebug("First Person Weapon Attached");
 }
 else
 {
 SetHidden(True);
 if (HTP != None)
 {
 Mesh.SetLightEnvironment(HTP.LightEnvironment);
 }
 }
 //SetSkin(HTPawn(Instigator).ReplicatedBodyMaterial);
}

simulated event SetPosition(UDKPawn Holder)
{
 local vector DrawOffset, ViewOffset, FinalLocation;
 local rotator NewRotation, FinalRotation, SpecRotation;
 local PlayerController PC;
 local vector2D ViewportSize;
 local bool bIsWideScreen;
 local vector SpecViewLoc;

 if ( !Holder.IsFirstPerson() )
 return;

 Mesh.SetHidden(False);

 foreach LocalPlayerControllers(class'PlayerController', PC)
 {
 LocalPlayer(PC.Player).ViewportClient.GetViewportSize(ViewportSize);
 break;
 }
 bIsWideScreen = (ViewportSize.Y > 0.f) && (ViewportSize.X/ViewportSize.Y > 1.7);

 Mesh.SetScale3D(default.Mesh.Scale3D);
 Mesh.SetRotation(default.Mesh.Rotation);

 ViewOffset = PlayerViewOffset;

 // Calculate the draw offset
 if ( Holder.Controller == None )
 {

 if ( DemoRecSpectator(PC) != None )
 {
 PC.GetPlayerViewPoint(SpecViewLoc, SpecRotation);
 DrawOffset = ViewOffset >> SpecRotation;
 //DrawOffset += UTPawn(Holder).WeaponBob(BobDamping, JumpDamping);
 FinalLocation = SpecViewLoc + DrawOffset;
 SetLocation(FinalLocation);
 SetBase(Holder);

 // Add some rotation leading
 //SpecRotation.Yaw = LagRot(SpecRotation.Yaw & 65535, LastRotation.Yaw & 65535, MaxYawLag, 0);
 //SpecRotation.Pitch = LagRot(SpecRotation.Pitch & 65535, LastRotation.Pitch & 65535, MaxPitchLag, 1);
 //LastRotUpdate = WorldInfo.TimeSeconds;
 //LastRotation = SpecRotation;

 if ( bIsWideScreen )
 {
 //SpecRotation += WidescreenRotationOffset;
 }
 SetRotation(SpecRotation);
 return;
 }
 else
 {
 DrawOffset = (ViewOffset >> Holder.GetBaseAimRotation()) + HTPawn(Holder).GetEyeHeight() * vect(0,0,1);
 PrintScreenDebug("Setting DrawOffset to Holder Info");
 }
 }
 else
 {

 DrawOffset.Z = HTPawn(Holder).GetEyeHeight();
 //DrawOffset += HTPawn(Holder).WeaponBob(BobDamping, JumpDamping);

 if ( HTPlayerController(Holder.Controller) != None )
 {
 DrawOffset += HTPlayerController(Holder.Controller).ShakeOffset >> Holder.Controller.Rotation;
 }

 DrawOffset = DrawOffset + ( ViewOffset >> Holder.Controller.Rotation );
 }

 // Adjust it in the world
 FinalLocation = Holder.Location + DrawOffset;
 SetLocation(FinalLocation);
 SetBase(Holder);

 NewRotation = (Holder.Controller == None) ? Holder.GetBaseAimRotation() : Holder.Controller.Rotation;

 // Add some rotation leading
 //if (Holder.Controller != None)
 //{
 //    FinalRotation.Yaw = LagRot(NewRotation.Yaw & 65535, LastRotation.Yaw & 65535, MaxYawLag, 0);
 //    FinalRotation.Pitch = LagRot(NewRotation.Pitch & 65535, LastRotation.Pitch & 65535, MaxPitchLag, 1);
 //    FinalRotation.Roll = NewRotation.Roll;
 //}
 //else
 //{
 FinalRotation = NewRotation;
 //}
 //LastRotUpdate = WorldInfo.TimeSeconds;
 //LastRotation = NewRotation;

 if ( bIsWideScreen )
 {
 //FinalRotation += WidescreenRotationOffset;
 }
 SetRotation(FinalRotation);
}

simulated state WeaponEquipping
{
 simulated event BeginState(Name PreviousStateName)
 {
 PrintScreenDebug("Weapon Equipping");
 AttachWeaponTo(Instigator.Mesh);
 Super.BeginState(PreviousStateName);
 }
}

simulated state Active
{
 simulated event BeginState(Name PreviousStateName)
 {
 PrintScreenDebug("Active");
 Super.BeginState(PreviousStateName);
 }
}

simulated state WeaponFiring
{
 simulated event BeginState(Name PreviousStateName)
 {
 PrintScreenDebug("Firing");
 Super.BeginState(PreviousStateName);
 }

 /**
 * We override BeginFire() so that we can check for zooming and/or empty weapons
 */

 simulated function BeginFire( Byte FireModeNum )
 {
 // No Ammo, then do a quick exit.
 if( !HasAmmo(FireModeNum) )
 {
 WeaponEmpty();
 return;
 }
 Global.BeginFire(FireModeNum);
 }
}

defaultproperties
{
 Begin Object Class=UDKSkeletalMeshComponent Name=FirstPersonMesh
 DepthPriorityGroup=SDPG_Foreground
 bOnlyOwnerSee=true
 bOverrideAttachmentOwnerVisibility=true
 CastShadow=false
 bAllowAmbientOcclusion=false
 End Object
 Mesh=FirstPersonMesh

 Begin Object Class=SkeletalMeshComponent Name=PickupMesh
 bOnlyOwnerSee=false
 CastShadow=false
 bForceDirectLightMap=true
 bCastDynamicShadow=false
 CollideActors=false
 BlockRigidBody=false
 bUseAsOccluder=false
 MaxDrawDistance=6000
 bForceRefPose=1
 bUpdateSkelWhenNotRendered=false
 bIgnoreControllersWhenNotRendered=true
 bAcceptsStaticDecals=FALSE
 bAcceptsDynamicDecals=FALSE
 bAllowAmbientOcclusion=false
 End Object
 DroppedPickupMesh=PickupMesh
 PickupFactoryMesh=PickupMesh

 MessageClass=class'UTPickupMessage'
 DroppedPickupClass=class'UTDroppedPickup'

 FiringStatesArray(0)=WeaponFiring
 FiringStatesArray(1)=WeaponFiring

 WeaponFireTypes(0)=EWFT_InstantHit
 WeaponFireTypes(1)=EWFT_InstantHit

 WeaponProjectiles(0)=none
 WeaponProjectiles(1)=none

 FireInterval(0)=+0.3
 FireInterval(1)=+0.3

 Spread(0)=0.0
 Spread(1)=0.0

 ShotCost(0)=1
 ShotCost(1)=1

 AmmoCount=5
 MaxAmmoCount=5

 InstantHitDamage(0)=0.0
 InstantHitDamage(1)=0.0
 InstantHitMomentum(0)=0.0
 InstantHitMomentum(1)=0.0
 InstantHitDamageTypes(0)=class'DamageType'
 InstantHitDamageTypes(1)=class'DamageType'
 WeaponRange=22000

 ShouldFireOnRelease(0)=0
 ShouldFireOnRelease(1)=0

 DefaultAnimSpeed=0.9

 EquipTime=+0.45
 PutDownTime=+0.33
}

HTWP_M16

/*******************************************************************************
 HTWP_M16

 Creation date: 08/03/2010 06:48
 Copyright (c) 2010, Allar

*******************************************************************************/

class HTWP_M16 extends HTWeapon;

defaultproperties
{
 // Weapon SkeletalMesh
 Begin Object Name=FirstPersonMesh
 SkeletalMesh=SkeletalMesh'ALWP_M16.Mesh.SK_WP_M16_1P'
 AnimSets(0)=AnimSet'ALWP_M16.Anims.K_WP_M16_1P'
 Scale=1.0
 FOV=60.0
 End Object

 // Pickup staticmesh
 Begin Object Name=PickupMesh
 SkeletalMesh=SkeletalMesh'ALWP_M16.Mesh.SK_WP_M16_3P'
 End Object

 PlayerViewOffset=(X=17,Y=10.0,Z=-8.0)
}

Posted March 9, 2010 by Allar in Unreal

Tagged with , , , , , , ,

46 responses to HTWeapon: Part 1 – Adding Ammo

Subscribe to comments with RSS.

  1. Hey dude, I really love your tutorials, and I think you are doing a great job. However I am having trouble compiling the files and making errors in the codes when I copy and paste. Is it alright if you post a zip file with all the class files? No content is needed, haha.

  2. I was thinking about doing this as well. You suggested it, so I will do so with all future tutorials. Because the working code I am using for these tutorials has evolved, I no longer have this iteration of code. Forcing me to create .zip files of these iterations will allow me to go back to specific versions in the future, so its a good idea all around. If you are using the March build with this tutorial, you will get errors about variables being already declared in their super classes as Epic decided to move some variables up to parent classes. If thats the case, I recommend following and reading until you get to the February to March tutorial, and use that code in these classes. You should get no errors and be able to compile just fine after that. Later tonight or this week I will work on reformatting this code along with posting a .zip

    Can you reply with specific errors? Just so I know its a pure code formatting thing instead of the actual code… The last thing I want to post is not functional code :D

  3. I have followed the tutorials from the beginning but somewhere from "Beginning your game part" 3 to "HTWeapon: Part 1" some thing has goes wrong. Everything is working fine except i am unable to contiune with the tutorial because my First Person mesh does not load when i type the command "giveweapon UDKGame.SMWP_Cannon" (which would be my script name). Everything recompiles nicely, but even when i change the skeletalmesh and anims to the proper shockrifle files it does not work. Hopefully you will have an idea as to what i am talkin about and some thoughts as to how to fix it. besides this litte issue Thank You for Awsome Tutorials!!

    • Thats odd, trying placing a

      `log("Weapon attached");

      in the AttachWeaponTo and see if it spits out Weapon attached in your log files when you use giveweapon

      EDIT:

      I totally just remembered that the ShockRifle is facing down the wrong axis and in Epic's code it is rotated in its default properties. Check the defaultproperties block of UTWeap_ShockRifle for this.

      You can either fix it by rotating it the same way they did, or copying the shockrifle asset, save it into your own package, and then adjust its Rot Origin.

  4. I believe that mine is already suppose to be spiting out the weapon state, since iv been following both the written and video versions so it should be already telling me that the weapon is attached, has this function been removed in the Written Version?
    It just doesnt seem to load the mesh. I am using a weapon that has the X axis facing facing the same as your M-16 so i shouldn't have to rotate the origin.

    • Interesting. I'll perform the rare occasion of looking at your code + package if you send me your UDKGame directory and the package containing your weapon if you are willing to email it to me. Email is on my about page.

    • Your code is working, however you put that `log function in the wrong spot, it belongs inside the curly brackets and somewhere after the local variable declarations.

      Heres the issue: You named the folder with all your code RedRain, which means your code package is RedRain, not UDKGame.

      Which means as you follow this tutorial, things like UDKGame.UDKGame will be RedRain.UDKGame. Things like UDKGame.HTWeapon will be RedRain.HTWeapon. And in your case, UDKGame.SMWP_Cannon will become RedRain.SMWP_Cannon.

      Try using the command giveweapon RedRain.SMWP_Cannon

  5. That makes sense but where did you see UDKGame where it was suppose to be RedRain? The console command I was typing in wrong, but still seems to not work even with RedRain.SMWP_Cannon.

  6. Beautiful, Ok the problem seemed to be just the "config (UDKGame)" which was suppose to be "config (RedRain)". Thanks for the help!
    I can continue with ur tutorials now : ). I dont wanna bug you all day but in the tutorial will it go into using the animset for the gun, with Reload and Alternate fire and what not?

    • I have not covered how to implement custom characters or animations yet, but a few tutorials about that should be going up within the next few eeks about it.

  7. emergency :)

    now I do a Make for game there are errors:

    Warning/Error Summary
    ———————
    D:UDKUDK-2010-03DevelopmentSrcUDKGameClassesHTWeapon.uc(326) : Error, BEGIN OBJECT: No base template named FirstPersonMesh found in parent class UDKWeapon: Begin Object Name=FirstPersonMesh
    D:UDKUDK-2010-03DevelopmentSrcUDKGameClassesHTWP_M16.uc(14) : Error, BEGIN OBJECT: No base template named FirstPersonMesh found in parent class HTWeapon: Begin Object Name=FirstPersonMesh
    D:UDKUDK-2010-03DevelopmentSrcUDKGameClassesHTWeapon.uc(11) : Warning, Variable declaration: 'AmmoCount' conflicts with previously defined field in 'UDKWeapon'

    here is the link for my code:
    http://www.4shared.com/file/258310476/9bc308a5/UD

    • Too busy to look at your code, but I don't need to either.

      Code listing for HTWeapon updated and fixed.

      You can also rip out line 11 of your code to get rid of that warning. The code above works with the Feb build but causes that warning on the March build, as you'll see in the next few tutorials.

  8. i'll try help U soon…

    I'll check the code now

  9. sorry I can't …
    maybe allar help U

  10. U seem to buuussssssy…

  11. Getting a warning when I compile in:

    warning : ObjectProperty Engine.SkeletalMeshComponent:SkeletalMesh: unresolved reference to 'SkeletalMesh 'AvaWeapons.Mesh.SK_WP_Thompson''

    I copied everything from both of the weapon files and just changed the names to match the ones in my project. Not to sure why I'm getting these warnings.

    Also the part where it says "AvaWeapons.Mesh.SK_WP_Thompson" is the AvaWeapons part the .upk in the contents package?

    • Launch the editor and find the skeletal mesh in your package that you want to use (SK_WP_Thompson).

      Right click it, and click copy full name to clipboard.

      Now paste that over your SkeletalMesh'AvaWeapons…' line.
      :D

    • I'm not to sure if you went over it in a previous Tutorial. My problem just had to do with: AvaWeapons.Mesh.SK_WP_Thompson
      I didn't name my group Mesh so I had to change that. Also I noticed you said to make it so the gun is on the X axis does that mean I have to have the PlayerViewOffset still or no?

  12. oops totally didn't see your post. So I got that to work but I can't seem to get it in the game. A few things I am doing differently is I'm not deriving from the same Game info class just cause for my project it's easier to use unreal code thats already there. Anyway I went into my GameInfo class and added:

    DefaultInventory(0)=class'AvaWeapon_Thompson'

    But I keep loading up my map with the link gun. Any thoughts as to why?

    • Hmm, that should do it… You might need to look in-depth at some of their default inventory code and see if they are using this array or some other means to give inventory items in the mode you are deriving from. I don't know of any reason for that to not work but… I suppose you can always override the function that gives players their default inventory directly.

      • I think what I will try to do is go back and just do my Game info class the same as yours and see if I can get it to work like that. I was doing some testing last night with my pawn class and changed my character so it was the Human male. When I ran the game the character stayed as that robot character. Which to me is a little confusing because I know I am running my Game info class because when I changed my class to derive from just GameInfo I didn't have a gun or anything opposed to the UTGameinfo class.

        Also you have a character in your game right?

  13. So I went back and changed everything but all I get is a floating camera when I load up my Game. I feel like it isn't using my pawn or anything but I have double checked my code to make sure that my GameInfo class is using my default pawn and player controller. Is there any way for me to check if my pawn class is even being called on level start up? and same when I use the give weapon?

    • in your Pawn class you can hook the PostBeginPlay or Spawned events and use `log("Im a Pawn!") within these functions to log some text to your log files. Then you can check your latest log file in UTGameLogs and see if that text shows up. If not, then your Pawn class isn't being used.

  14. Just to make sure I am calling the function the postbegin play looks like this:

    function PostBeginPlay()
    {
    Super.PostBeginPlay();

    `Log("I'm in the pawn class");
    }

    Trying that right now. let me know If I did anything wrong

  15. I'm assuming that right when I load up the game somewhere in my log file it should say I am in my pawn class, but I don't see it there. It does say in there though:

    Log: Game class is 'AvaGameInfo'

    So why isn't it calling my pawn class?

  16. So I tried putting the script log in my Player controller class and it worked so I guess that narrows a few things down.

    Sorry about all the posts just really confused as to why this wouldn't be working if the script log comes up for my player controller

  17. I'm in the same boat as GregC. I have redone the tutorial twice, and both times at this stage I simply end up with a floating camera and any time I call "giveweapon" nothing happens. My code is identical to the code you provide, Allar, so I've no idea why it isn't working. It's like it isn't recognising my UDKGame classes. Do you have any idea what might be causing this?

    • Which build yall using?

      • I have the same problem. I only get a camera which i can fly around with. When I try GiveWeapon this fails as well, although I use [the right packagename].[WeaponClass]

        I have tried as you mentioned to check it using the log. I did this and it turned out my pawn class didn't work. I have no clue how, since I used all your code, only different prefixes for classes. My build is october 2010.

  18. Good tutorial. Still, I think you need to focus a little more on the udk aspect of things instead of having us copy-paste, but your getting better and this tutorial has less filler and more info than your previous. Congrats.

  19. Actually you explained variables and some of the statements such as repnotify so you actually improved ALOT from the last video. I'm quite impressed and to be brutally honest…your more helpful than hourence's although I still use his map making tuts. You really should check out the site. We've got are game in acceleration now and we have an interview series for all my homies.

  20. Sorry for the tripple post, but I'm giving you cred. on the next video we do (For the "Official" channel (not the behind-the-scenes one)). It'll be about our progress in the engine and even though part 4 was actually the hardest of your tutorials I stuck through it, you still did wonders to explain Unreal Script. Even though I ranted I still thought it was better for me to get my hands dirty and take a look at the code my self, instead of complaining that someone else should do it for me. Although it would be nice to see some more explanation of Unreal Scripts syntax, these are still VERY good tutorials and I'd keep watching regardless. Props man.

    • This entire series is far sub-par in quality as to where I want them to be.

      I'm already in the process of recreating this whole series, just got my brand new microphone, and kind of know what I'm talking about now.

      The series is meant to also go along with my book, so we'll see how that goes. Its going to go pretty in-depth, most likely so in-depth its annoying but whatever.

  21. Hey allar that interview with the developers part 3 is going to be remade. That was Tree_gnome and he kinda fails at videos so after class Im making him redo his video

  22. Hey just got a quick question my gun is showing up black when I run the game and I tried just bringing in the unreal Link gun and it was black to. I'm not to sure where to look to solve this problem. I was thinking it had to do with the dynamic light for the gun but everything seems to be the same as your code. Do you have any places that I could look for this problem.

  23. Awesome thanks for the quick response.

  24. Hey Allar,

    - First off – THANK YOU SO MUCH for these tutorials, I have learned more in a short time than I ever expected.

    - Second – I would like to throw out some info that may help anyone doing a 3rd Person style. I had an insanely horrid time mucking around with positioning the weapon (I'm just using the default mesh "Liam" and the Link gun from the UT stuff provided.
    Rather than deal with offsetting and rotating and blah blah blah with the 3P weapon, I found it all worked sooooo much better to attach the gun to a socket (in the default case – WeaponPoint was there and worked well.

    For any interested individuals, take the following steps to implement the 3rd person weapon:

    1) If you're using a UT weapon (i.e. not your own custom mesh), make sure to use the 3P verson (in my case this was SK_WP_LinkGun_3P), otherwise the gun appears incomplete as the 1P is meant for "1st Person".
    a) For UT guns, copy the original to your own package
    b) Using the Anim Set Viewer (Right click on your copied gun in UDK content browser) –
    UT guns should have a point of origin of 0,0,0, (X,Y,Z) and orientation of 0,0,0 (pitch, roll, yaw). By default the Link gun had a -90 degree rotation and was offset by a bit.
    c) For NON-UT characters, add a Socket (again, Anim Set Viewer) in your character's hand where you want to fix the gun to. The default "liam" robot guy has one already named 'WeaponPoint'. The Sockets can be manipulated by menu item [MESH]->[SocketManager] and viewed there or by the item in the View menu "view sockets".

    2) Change the "SetPosition" function in HTWeapon.uc as follows:
    a) Add: var name WeaponPoint;
    at the top, within your class variables. We programmers sometimes call these "class members" btw…
    b) Change SetPosition event handler function to be:
    simulated event SetPosition(UDKPawn Holder)
    {
    Mesh.SetHidden(False);

    super.SetPosition(Holder);
    return;
    }
    (And I don't think you probably need it at all, but I kept it in place as I'm source controlling my files and want the point of reference.)

    3) In your AttachWeaponTo function, remove the line: AttachComponent(Mesh);
    Add a new line (before any "is first person" thing since I'm talking about 3rd person here:

    MeshCpnt.AttachComponentToSocket(Mesh, WeaponPoint);

    4) In the default properties section, add a line:
    WeaponPoint=WeaponPoint
    (This is similar to the muzzleflash stuff, obviously)

    That's it. When I did that, my klunky offset weapon was no more and I have a spectacularly slick looking robot with a gun. For free, you'll also get weapon bobbing, but best of all, you'll avoid the several hours of hassle trying to set the gun in the 3rd Person characters' hands.

    BTW – I never would've thought to do that without the muzzleflash working so beautifully… so again, thank you Allar – you have taught me well sir.

    Thanks,
    PatHenry52

  25. hey! anyone got a solution for that floating camera-giveweapon-nothing happens kind of problem?

  26. Yeah, that would be mighty helpful considering i have the same problem :(

  27. hi sir good day!

    can i ask where do you exactly put your gun mesh? do you put it on its own package (ex:m4 package) to be called for by the engine itself? or did you put it inside your map package?

    I'll await your reply, thank you sir!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>