PDA

View Full Version : Change weapon fire rate



[PSI]PsySniper
11-26-2007, 09:34 AM
I am trying to bring back an old feature from the old Rifle Mutators for UT2004
( Pro-Sniper Zark Rifle ), I want to be able to change the fire rate, so when
players run, Rifle Rifle Fire-Rate becomes slow, when you crouch, the fire rate
becomes fast.


Here is the problem, I actually managed to Increase and Decrease Fire-Rate,
the problem is, as long I hold the Fire button, Fire-Rate will continue to be fast
or slow no mater what I do...

Example:
When I crouch and fire, fire rate will be fast, but then if I start to run,
it will continue to be fast as long I hold the fire button.


Here is the code I have been working on:

simulated function ProcessInstantHit( byte FiringMode, ImpactInfo Impact )
{
local float Scaling;
local int HeadDamage;

if( (Role == Role_Authority) && !bUsingAimingHelp )
{
if (Instigator == None || VSize(Instigator.Velocity) < Instigator.GroundSpeed * Instigator.CrouchedPct)
{
Scaling = SlowHeadshotScale;
FireInterval[0] = 0.150000;
FireInterval[1] = 0.150000;
}
else
{
Scaling = RunningHeadshotScale;
FireInterval[0] = 0.900000;
FireInterval[1] = 0.900000;
}

HeadDamage = InstantHitDamage[FiringMode]* HeadShotDamageMult;
if ( (UTPawn(Impact.HitActor) != None && UTPawn(Impact.HitActor).TakeHeadShot(Impact, HeadShotDamageType, HeadDamage, Scaling, Instigator.Controller)) ||
(UTVehicleBase(Impact.HitActor) != None && UTVehicleBase(Impact.HitActor).TakeHeadShot(Impact , HeadShotDamageType, HeadDamage, Scaling, Instigator.Controller)) )
{
SetFlashLocation(Impact.HitLocation);
return;
}
}

super.ProcessInstantHit( FiringMode, Impact );
}


And here is another version, but with the same results...



simulated function ProcessInstantHit( byte FiringMode, ImpactInfo Impact )
{
local float Scaling;
local int HeadDamage;

If( Instigator.bIsCrouched || VSize(Instigator.Velocity) <= 300.0 )
{
FireInterval[0] = 0.150000;
FireInterval[1] = 0.150000;
}
else
{
FireInterval[0] = 0.900000;
FireInterval[1] = 0.900000;
}

if( (Role == Role_Authority) && !bUsingAimingHelp )
{
if (Instigator == None || VSize(Instigator.Velocity) < Instigator.GroundSpeed * Instigator.CrouchedPct)
{
Scaling = SlowHeadshotScale;
}
else
{
Scaling = RunningHeadshotScale;
}

HeadDamage = InstantHitDamage[FiringMode]* HeadShotDamageMult;
if ( (UTPawn(Impact.HitActor) != None && UTPawn(Impact.HitActor).TakeHeadShot(Impact, HeadShotDamageType, HeadDamage, Scaling, Instigator.Controller)) ||
(UTVehicleBase(Impact.HitActor) != None && UTVehicleBase(Impact.HitActor).TakeHeadShot(Impact , HeadShotDamageType, HeadDamage, Scaling, Instigator.Controller)) )
{
SetFlashLocation(Impact.HitLocation);
return;
}
}

super.ProcessInstantHit( FiringMode, Impact );
}


Can anyone tell me what I am doing wrong?

Even if the code I added is bad, I have a feeling the original head-shot scale
function will also be affected by holding the fire button....

Xyx
11-26-2007, 09:57 AM
I can't immediately spot the problem and I still have to get started on UT3 uscript... but here are some general tips:

Write something to the log or broadcast it to the chat to see if the function actually runs when nothing seems to happen.
If you merely wish to add something to the functionality of the ProcessInstantHit function, don't override the entire function. Just do your own specific thing and then call the super.

[PSI]PsySniper
11-26-2007, 10:27 AM
Well, both functions seems to do the job, the main problem is that
the action of holding the fire button prevents the function to work
properly.


I can crouch... then fire, and my fire rate will be fast.
I can run...then fire, and my fire rate will be slow.



But....

I can run.. fire, fire rate will be slow... but then if I crouch
and stop moving, my fire rate will continue to be slow until I release
the fire button and press the button again.

Xyx
11-26-2007, 04:14 PM
Are you certain ProcessInstantHit runs every time you fire when holding down the button? Place some debug lines in the if statement to see which branch is selected. In fact, have those lines display VSize(Instigator.Velocity) and Instigator.bIsCrouched while you're at it so you can verify the proper choices are made.

SwaTz0rs
11-26-2007, 05:32 PM
i have exactly the same problem...

Tonester
11-26-2007, 06:26 PM
I haven't looked at the code, but the problem seems to be as follows:

You need to find some way to put a check for fire rate permissions after every attack, not just the first one. Haven't looked at the code, but you might have to do something with regards to tick() to get this to work if they don't have anything built-in with regards to "while holding fire down, and between each shot... what to do". Be careful using computations every tick, but if it is just a simple boolean check, it shouldn't be too much overhead... if you want a bit less precision, try using timer() (is that correct?) instead of tick(). Now that I think about it, you probably don't want to check a boolean value for every char dozens of times per second. :)

czard
11-27-2007, 03:45 AM
well I don't know how far into you want to go but this is what im using to modify it. I am working on a freeze tag for ut3, early alpha play test should be available soon.

I put this in my extended pawn.



simulated event EndCrouch( float HeightAdjust )
{
FireRateMultiplier = default.FireRateMultiplier;
FireRateChanged();
Super.EndCrouch(HeightAdjust);
}


simulated event StartCrouch( float HeightAdjust )
{
FireRateMultiplier = default.FireRateMultiplier * ftcgame(worldinfo.game).FreezeRifleCrouchModifier;
FireRateChanged();
Super.StartCrouch(HeightAdjust);
}


ftcgame(worldinfo.game).FreezeRifleCrouchModifier
=====
can be any float, its just a reference to my ini file settings.


and I think that using the fireratemultiplier and fireratechanged() you can still use your exisiting functions possibly. try it out and tell me how it goes.

[PSI]PsySniper
11-27-2007, 11:43 AM
Thanks czard, your idea to work this issue from the pawn Class works.

The only issue i see:


It affects all weapons.
I still need to figure how to do rapid Fire when pawn is just standing.


Here is what I end up with:




simulated event StartCrouch( float HeightAdjust )
{
if((Weapon != None) && Weapon.IsA('PSI_SniperRifle'))
{
FireRateMultiplier = default.FireRateMultiplier / 6.0;
FireRateChanged();
}

Super.EndCrouch(HeightAdjust);
}

simulated event EndCrouch( float HeightAdjust )
{
if((Weapon != None) && Weapon.IsA('PSI_SniperRifle'))
{
FireRateMultiplier = default.FireRateMultiplier;
FireRateChanged();
}
Super.StartCrouch(HeightAdjust);
}

Pfhoenix
11-27-2007, 02:02 PM
Look carefully at Weapon.uc. Notice that it uses states to know how it should be firing. Notice that every Weapon has a dynamic array for setting the state per firemode.

schizoslayer
11-28-2007, 08:15 AM
The weapon firing is done on a timer (I love me the new timers) which loops. Check out the function Weapon::TimeWeaponFiring() for where it's setup.

In order to change this you would have to wait for a shot to be fired then clear the timer and restart it with the new fireinterval when you crounch/uncrouch.