Can't Switch Weapon after Shooting

Discussions about Coding and Scripting
Post Reply
User avatar
'Zac
Experienced
Posts: 111
Joined: Tue Jul 29, 2014 9:35 pm
Personal rank: Who knows.
Location: NC

Can't Switch Weapon after Shooting

Post by 'Zac »

I'm working on a simple rifle and there's a small problem, after I shoot once I can't switch my weapon. I can still shoot and everything, but when I throw my weapon everything is back to normal.
Here's the code...

Code: Select all

class Zeus expands TournamentWeapon;

function Projectile ProjectileFire(class<projectile> ProjClass, float ProjSpeed, bool bWarn)
{
	local Vector Start, X,Y,Z;
	local Pawn PawnOwner;

	PawnOwner = Pawn(Owner);
	Owner.MakeNoise(PawnOwner.SoundDampening);
	GetAxes(PawnOwner.ViewRotation,X,Y,Z);
	Start = Owner.Location + CalcDrawOffset() + FireOffset.X * X + FireOffset.Y * Y + (FireOffset.Z - 20) * Z; 
	AdjustedAim = PawnOwner.AdjustAim(ProjSpeed, Start, AimError, True, bWarn);	
	return Spawn(ProjClass,,, Start,AdjustedAim);	
}

simulated function PlayFiring()
{
	PlayAnim('Fire', 0.3, 0.04);
	Owner.PlaySound(FireSound, SLOT_None, Pawn(Owner).SoundDampening);
}

simulated function PlayAltFiring()
{
	PlayFiring();
}


function Fire( float Value )
{
	if ( AmmoType == None )
	{
		// ammocheck
		GiveAmmo(Pawn(Owner));
	}
	if (AmmoType.UseAmmo(1))
	{
		GotoState('Fire');
		bCanClientFire = true;
		bPointing=True;
		ClientAltFire(Value);
		ProjectileFire(ProjectileClass, AltProjectileSpeed, bAltWarnTarget);
	}
}


function AltFire( float Value )
{
	if ( AmmoType == None )
	{
		GiveAmmo(Pawn(Owner));
	}
	if (AmmoType.UseAmmo(1))
	{
		GotoState('Fire');
		bCanClientFire = true;
		bPointing=True;
		ClientAltFire(Value);
		ProjectileFire(ProjectileClass, AltProjectileSpeed, bAltWarnTarget);
	}
}

defaultproperties
{
    AmmoName=Class'moBullets'
    PickupAmmoCount=400
    bWarnTarget=True
    bAltWarnTarget=True
    bSplashDamage=True
    bRecommendSplashDamage=True
    FireOffset=(X=0.00,Y=-5.00,Z=-5.00),
    ProjectileClass=Class'ProjZeus'
    AltProjectileClass=Class'ProjZeus'
    shakemag=350.00
    shaketime=0.20
    shakevert=7.50
    AIRating=0.70
    RefireRate=0.1
    AltRefireRate=0.1
    FireSound=Sound'UnrealI.Rifle.RifleShot'
	AltFireSound=Sound'UnrealI.Rifle.RifleShot'
    SelectSound=Sound'UnrealShare.AutoMag.Reload'
    DeathMessage="%o got fucked up by %k's %w"
    AutoSwitchPriority=9
    InventoryGroup=9
	MultiSkins(1)=Texture'GenFX.Palettes.Glowy'
    MultiSkins(2)=Texture'GenFX.Palettes.Glowy'
    PickupMessage="You got the Zeus"
    ItemName="Zeus"
	BobDamping=1.04
    PlayerViewOffset=(X=3.200000,Y=-1.200000,Z=-1.700000)
    PlayerViewMesh=LodMesh'UnrealI.RifleM'
    PickupViewMesh=LodMesh'UnrealI.RiPick'
    ThirdPersonMesh=LodMesh'UnrealI.Rifle3rd'
    PickupSound=Sound'UnrealShare.Pickups.WeaponPickup'
    Mesh=LodMesh'UnrealI.RiPick'
    bNoSmooth=False
    CollisionHeight=10.00
}
Prophunt for UT99!!!
Image
Github
User avatar
EvilGrins
Godlike
Posts: 9690
Joined: Thu Jun 30, 2011 8:12 pm
Personal rank: God of Fudge
Location: Palo Alto, CA
Contact:

Re: Can't Switch Weapon after Shooting

Post by EvilGrins »

Don't know code, but I've seen this problem before. Most recently with Nali Weapons 2 (no, not NW3) where with some weapons if you fired all ammo down to 0 you couldn't fire anymore, even with an ammo regenerator, and you couldn't switch weapons. There's a simple, in-game, fix for this.... drop the weapon.

I assume you have some key assignment setup to toss a weapon out of your inventory if you don't want it anymore.

Least that should solve the problem in-game until you get the code worked out.
http://unreal-games.livejournal.com/
Image
medor wrote:Replace Skaarj with EvilGrins :mrgreen:
Smilies · viewtopic.php?f=8&t=13758
User avatar
papercoffee
Godlike
Posts: 10447
Joined: Wed Jul 15, 2009 11:36 am
Personal rank: coffee addicted !!!
Location: Cologne, the city with the big cathedral.
Contact:

Re: Can't Switch Weapon after Shooting

Post by papercoffee »

We had in Food Fight a nearly similar bug. One weapon (I cant recall which one), if emptied to 0 bullets and you didn't picked up a ammo pack before, got stuck in your roster and you couldn't switch to another weapon.
After tossing it away was everything ok again.

I bet it has something to do with the ammo count.
Spectra
Masterful
Posts: 542
Joined: Tue Jan 22, 2013 5:23 pm
Personal rank: Nullified!
Location: (X) Unable To Locate....

Re: Can't Switch Weapon after Shooting

Post by Spectra »

Here I fixed them:

Code: Select all

    class Zeus expands TournamentWeapon;

    function Projectile ProjectileFire(class<projectile> ProjClass, float ProjSpeed, bool bWarn)
    {
       local Vector Start, X,Y,Z;
       local Pawn PawnOwner;

       PawnOwner = Pawn(Owner);
       Owner.MakeNoise(PawnOwner.SoundDampening);
       GetAxes(PawnOwner.ViewRotation,X,Y,Z);
       Start = Owner.Location + CalcDrawOffset() + FireOffset.X * X + FireOffset.Y * Y + (FireOffset.Z - 20) * Z;
       AdjustedAim = PawnOwner.AdjustAim(ProjSpeed, Start, AimError, True, bWarn);   
       return Spawn(ProjClass,,, Start,AdjustedAim);   
    }

    simulated function PlayFiring()
    {
       PlayAnim('Fire', 0.3, 0.04);
       Owner.PlaySound(FireSound, SLOT_None, Pawn(Owner).SoundDampening);
    }

    simulated function PlayAltFiring()
    {
       PlayAnim('Fire', 0.3, 0.04);
       Owner.PlaySound(AltFireSound, SLOT_None, Pawn(Owner).SoundDampening);
    }


    function Fire( float Value )
    {
       if ( AmmoType == None )
       {
          // ammocheck
          GiveAmmo(Pawn(Owner));
       }
       if (AmmoType.UseAmmo(1))
       {
          GotoState('NormalFire');
          bCanClientFire = true;
          bPointing=True;
          ClientAltFire(Value);
          ProjectileFire(ProjectileClass, AltProjectileSpeed, bAltWarnTarget);
       }
    }
	
	state NormalFire
	{
		Begin:
				FinishAnim();
				Finish();
	}


    function AltFire( float Value )
    {
       if ( AmmoType == None )
       {
          GiveAmmo(Pawn(Owner));
       }
       if (AmmoType.UseAmmo(1))
       {
          GotoState('AltFiring');
          bCanClientFire = true;
          bPointing=True;
          ClientAltFire(Value);
          ProjectileFire(ProjectileClass, AltProjectileSpeed, bAltWarnTarget);
       }
    }
	
	state AltFiring
	{
		Begin:
			FinishAnim();
			Finish();
	}

   defaultproperties
{
     AmmoName=Class'moBullets'
     PickupAmmoCount=400
     bWarnTarget=True
     bAltWarnTarget=True
     bSplashDamage=True
     bRecommendSplashDamage=True
     FireOffset=(Y=-5.000000,Z=-5.000000)
     ProjectileClass=Class'ProjZeus'
     AltProjectileClass=Class'ProjZeus'
     shakemag=350.000000
     shaketime=0.200000
     shakevert=7.500000
     AIRating=0.700000
     RefireRate=0.100000
     AltRefireRate=0.100000
     FireSound=Sound'UnrealI.Rifle.RifleShot'
     AltFireSound=Sound'UnrealI.Rifle.RifleShot'
     SelectSound=Sound'UnrealShare.AutoMag.Reload'
     DeathMessage="%o got fucked up by %k's %w"
     AutoSwitchPriority=9
     InventoryGroup=9
     PickupMessage="You got the Zeus"
     ItemName="Zeus"
     PlayerViewOffset=(X=3.200000,Y=-1.200000,Z=-1.700000)
     PlayerViewMesh=LodMesh'UnrealI.RifleM'
     BobDamping=1.040000
     PickupViewMesh=LodMesh'UnrealI.RiPick'
     ThirdPersonMesh=LodMesh'UnrealI.Rifle3rd'
     PickupSound=Sound'UnrealShare.Pickups.WeaponPickup'
     Mesh=LodMesh'UnrealI.RiPick'
     bNoSmooth=False
     MultiSkins(1)=Texture'GenFX.Palettes.Glowy'
     CollisionHeight=10.000000
}
The firing rate is pretty slow, you can increase it if you want. And had to multiskin it via Editor.
User avatar
papercoffee
Godlike
Posts: 10447
Joined: Wed Jul 15, 2009 11:36 am
Personal rank: coffee addicted !!!
Location: Cologne, the city with the big cathedral.
Contact:

Re: Can't Switch Weapon after Shooting

Post by papercoffee »

What went wrong?
User avatar
Sp0ngeb0b
Adept
Posts: 376
Joined: Wed Feb 13, 2008 9:16 pm
Location: Cologne
Contact:

Re: Can't Switch Weapon after Shooting

Post by Sp0ngeb0b »

Looks like he forgot to implement state code in the first buid; resulting in the weapon getting stuck in 'Fire' state :wink:
Website, Forum & UTStats

Image
******************************************************************************
Nexgen Server Controller || My plugins & mods on GitHub
******************************************************************************
User avatar
*Kr!D_o)
Average
Posts: 67
Joined: Thu May 02, 2013 2:55 am

Re: Can't Switch Weapon after Shooting

Post by *Kr!D_o) »

yessir. that'll do it too. i had similar issue with minigun when i was working on earlier versions of EnhancedUT. Trying to est the next fire interval like UTPure's minigun code, to get it switch more quickly for FWS ...
User avatar
'Zac
Experienced
Posts: 111
Joined: Tue Jul 29, 2014 9:35 pm
Personal rank: Who knows.
Location: NC

Re: Can't Switch Weapon after Shooting

Post by 'Zac »

Ok thanks guys!
Prophunt for UT99!!!
Image
Github
Post Reply