PDA

View Full Version : Weapon Coding, bullet on ground



legacy-EggXzaB
07-14-2003, 05:14 PM
right, I have my own gun, about the same as assaultrifle, but with headshot function.

Now the problem is, when I copied the Headshot function (from the sniperrifle) the bullet hole / bullet spark on the walls disappeared.

This is my whole glock40Fire.uc :



class glock40Fire extends InstantFire;



var float LastFireTime;
var float ClickTime;

// headshot vars //
var() class<xEmitter> HitEmitterClass;
var() class<xEmitter> SecHitEmitterClass;
var() int NumArcs;
var() float SecDamageMult;
var() float SecTraceDist;
var() float HeadShotDamageMult;
var() float HeadShotRadius;
var() class<DamageType> DamageTypeHeadShot;
// eind HS vars //


function InitEffects()
{
Super.InitEffects();
if ( FlashEmitter != None )
Weapon.AttachToBone(FlashEmitter, 'tip');
}

function FlashMuzzleFlash()
{
local rotator r;
r.Roll = 65536; // Rand(65536);
Weapon.SetBoneRotation('Bone_Flash', r, 0, 1.f);
Super.FlashMuzzleFlash();
}

event ModeDoFire()
{
if ( Level.TimeSeconds - LastFireTime > 0.5 ) // als je pas na een halve seconde weer vuurt
{
Spread = 0.0; // is de spread dus 0
}
else // zo niet, dus binnen halve seconde weer vuren
{
Spread = FMin(Spread+0.02,0.12); // dan is de spread random groter, eigen schuld :P
}

LastFireTime = Level.TimeSeconds;
Super.ModeDoFire();
}

simulated function bool AllowFire()
{
if (Super.AllowFire())
return true;
else
{
if ( (PlayerController(Instigator.Controller) != None) && (Level.TimeSeconds > ClickTime) )
{
PlayerController(Instigator.Controller).PlayOwnedS ound(Sound'WeaponSounds.P1Reload5');
ClickTime = Level.TimeSeconds + 0.25;
}
return false;
}
}

// start Headshot check script //
function DoTrace(Vector Start, Rotator Dir)
{
local Vector X,Y,Z, End, HitLocation, HitNormal, RefNormal;
local Actor Other, mainArcHitTarget;
local int Damage, ReflectNum, arcsRemaining;
local bool bDoReflect;
local xEmitter hitEmitter;
local class<Actor> tmpHitEmitClass;
local float tmpTraceRange, dist;
local vector arcEnd, mainArcHit;

Weapon.GetViewAxes(X, Y, Z);
if ( Weapon.WeaponCentered() )
arcEnd = (Instigator.Location +
Weapon.EffectOffset.X * X +
1.5 * Weapon.EffectOffset.Z * Z);
else
arcEnd = (Instigator.Location +
Instigator.CalcDrawOffset(Weapon) +
Weapon.EffectOffset.X * X +
Weapon.Hand * Weapon.EffectOffset.Y * Y +
Weapon.EffectOffset.Z * Z);

arcsRemaining = NumArcs;

tmpHitEmitClass = HitEmitterClass;
tmpTraceRange = TraceRange;

ReflectNum = 0;
while (true)
{
bDoReflect = false;
X = Vector(Dir);
End = Start + tmpTraceRange * X;
Other = Trace(HitLocation, HitNormal, End, Start, true);

if ( Other != None && (Other != Instigator || ReflectNum > 0) )
{
if (bReflective && Other.IsA('xPawn') && xPawn(Other).CheckReflect(HitLocation, RefNormal, DamageMin*0.25))
{
bDoReflect = true;
}
else if ( Other != mainArcHitTarget )
{
if ( !Other.bWorldGeometry )
{
Damage = (DamageMin + Rand(DamageMax - DamageMin)) * DamageAtten;
if ( (Pawn(Other) != None) && (arcsRemaining == NumArcs)
&& Other.GetClosestBone( HitLocation, X, dist, 'head', HeadShotRadius ) == 'head' )
Other.TakeDamage(Damage * HeadShotDamageMult, Instigator, HitLocation, Momentum*X, DamageTypeHeadShot);
else
{
if ( arcsRemaining < NumArcs )
Damage *= SecDamageMult;
Other.TakeDamage(Damage, Instigator, HitLocation, Momentum*X, DamageType);
}
}
else
HitLocation = HitLocation + 2.0 * HitNormal;
}
}
else
{
HitLocation = End;
HitNormal = Normal(Start - End);
}
hitEmitter = xEmitter(Spawn(tmpHitEmitClass,,, arcEnd, Rotator(HitNormal)));
if ( hitEmitter != None )
hitEmitter.mSpawnVecA = HitLocation;

if( arcsRemaining == NumArcs )
{
mainArcHit = HitLocation + (HitNormal * 2.0);
if ( Other != None && !Other.bWorldGeometry )
mainArcHitTarget = Other;
}

if (bDoReflect && ++ReflectNum < 4)
{
//Log("reflecting off"@Other@Start@HitLocation);
Start = HitLocation;
Dir = Rotator( X - 2.0*RefNormal*(X dot RefNormal) );
}
else if ( arcsRemaining > 0 )
{
arcsRemaining--;

// done parent arc, now move trace point to arc trace hit location and try child arcs from there
Start = mainArcHit;
Dir = Rotator(VRand());
tmpHitEmitClass = SecHitEmitterClass;
tmpTraceRange = SecTraceDist;
arcEnd = mainArcHit;
}
else
{
break;
}
}
}
// eind HS check script //







defaultproperties
{
FireSound=Sound'WeaponSounds.AssaultRifle.AssaultR ifleFire'
FireForce="AssaultRifleFire" // jdf

TraceRange=17000 //Maximum range of the weapon.
Momentum=1000 //How much the victim is pushed when hit.
AmmoClass=class'glock40Ammo'
AmmoPerFire=1
DamageType=class'glock40DamType'
DamageMin=30 //Min and Max can be different, to do a random damage between the two, or the same to do consistent damage.
DamageMax=32

FireAnim=Fire
FireEndAnim=None
FireLoopAnim=None
FireAnimRate=1.0

// FlashEmitterClass=class'XEffects.AssaultMuzFlash1s t'
FlashEmitterClass=class'XEffects.MinigunMuzFlash1s t'

Spread=0.020
SpreadStyle=SS_Random
PreFireTime=0.0
bModeExclusive=true


FireRate=0.3 //How fast it fires.
BotRefireRate=0.3 //How fast bots should try to fire.
AimError=800 //How accurate bots are.
bPawnRapidFireAnim=false

//These settings controll how your vire shakes when you fire.
ShakeOffsetMag=(X=-15.0,Y=0.0,Z=10.0)
ShakeOffsetRate=(X=-4000.0,Y=0.0,Z=4000.0)
ShakeOffsetTime=1.6
ShakeRotMag=(X=0.0,Y=0.0,Z=0.0)
ShakeRotRate=(X=0.0,Y=0.0,Z=0.0)
ShakeRotTime=2

HeadShotDamageMult=10.0
HeadShotRadius=10.0
DamageTypeHeadShot=class'DamTypeSniperHeadShot'
}





Well, before that i just had the bullet holes on the ground, standing in my attachment class :



class glock40Attachment extends xWeaponAttachment;

var byte OldSpawnHitCount;
var class<xEmitter> mMuzFlashClass;
var xEmitter mMuzFlash3rd;
var xEmitter mMuzFlash3rdAlt;

simulated function Destroyed()
{
if (mMuzFlash3rd != None)
mMuzFlash3rd.Destroy();
if (mMuzFlash3rdAlt != None)
mMuzFlash3rdAlt.Destroy();
Super.Destroyed();
}

/* UpdateHit
- used to update properties so hit effect can be spawn client side
*/
function UpdateHit(Actor HitActor, vector HitLocation, vector HitNormal)
{
SpawnHitCount++;
mHitLocation = HitLocation;
mHitActor = HitActor;
mHitNormal = HitNormal;
}

simulated event ThirdPersonEffects()
{
local rotator r;

if ( Level.NetMode != NM_DedicatedServer )
{
if (FiringMode == 0)
{
WeaponLight();
if ( OldSpawnHitCount != SpawnHitCount )
{
OldSpawnHitCount = SpawnHitCount;
GetHitInfo();
Spawn(class'HitEffect'.static.GetHitEffect(mHitAct or, mHitLocation, mHitNormal),,, mHitLocation, Rotator(mHitNormal));
}
if (mMuzFlash3rd == None)
{
mMuzFlash3rd = Spawn(mMuzFlashClass);
AttachToBone(mMuzFlash3rd, 'tip');
}
mMuzFlash3rd.mStartParticles++;
r.Roll = Rand(65536);
SetBoneRotation('Bone_Flash', r, 0, 1.f);
}
else if (FiringMode == 1 && FlashCount > 0)
{
WeaponLight();
if (mMuzFlash3rdAlt == None)
{
mMuzFlash3rdAlt = Spawn(mMuzFlashClass);
AttachToBone(mMuzFlash3rdAlt, 'tip2');
}
mMuzFlash3rdAlt.mStartParticles++;
r.Roll = Rand(65536);
SetBoneRotation('Bone_Flash02', r, 0, 1.f);
}
}

Super.ThirdPersonEffects();
}

defaultproperties
{
Mesh=mesh'Weapons.AssaultRifle_3rd'
mMuzFlashClass=class'XEffects.AssaultMuzFlash3rd'
bHeavy=false
bRapidFire=true
bAltRapidFire=false

bDynamicLight=false
LightType=LT_Pulse
LightEffect=LE_NonIncidence
LightPeriod=3
LightBrightness=150
LightHue=30
LightSaturation=150
LightRadius=4.0
}


So this worked untill I put in the HeadShot function..

anyone has ideas to solve this?

thx a lot :)

legacy-Shakuurn
07-14-2003, 06:00 PM
Delete all the code in the headshot function except for local variables and this line:

Other.GetClosestBone( HitLocation, X, dist, 'head', HeadShotRadius ) == 'head' )
Other.TakeDamage(Damage * HeadShotDamageMult, Instigator, HitLocation, Momentum*X, DamageTypeHeadShot);

legacy-EggXzaB
07-14-2003, 06:45 PM
Right, then it's just :




// start Headshot check script //
function DoTrace(Vector Start, Rotator Dir)
{
local Vector X,Y,Z, End, HitLocation, HitNormal, RefNormal;
local Actor Other, mainArcHitTarget;
local int Damage, ReflectNum, arcsRemaining;
local bool bDoReflect;
local xEmitter hitEmitter;
local class<Actor> tmpHitEmitClass;
local float tmpTraceRange, dist;
local vector arcEnd, mainArcHit;

Other.GetClosestBone( HitLocation, X, dist, 'head', HeadShotRadius ) == 'head' ;
Other.TakeDamage(Damage * HeadShotDamageMult, Instigator, HitLocation, Momentum*X, DamageTypeHeadShot);

}
// eind HS check script //


But that gives 15 warnings about the variables and then still doesnt work :(

I guess its just another small mistake :(
thx for the help already :)

legacy-EggXzaB
07-15-2003, 08:02 PM
plz help, this will be the base of all further weapon improvements / edits for me

:o

legacy-Shakuurn
07-15-2003, 08:32 PM
Originally posted by EggXzaB
plz help, this will be the base of all further weapon improvements / edits for me

:o

Oops, I forgot, you need an "if" statement there.

If (Other.GetClosestBone( HitLocation, X, dist, 'head', HeadShotRadius ) == 'head' ) {
Other.TakeDamage(Damage * HeadShotDamageMult, Instigator, HitLocation, Momentum*X, DamageTypeHeadShot);
}

legacy-EggXzaB
07-16-2003, 03:06 AM
Like mentioned before :



// start Headshot check script //

function DoTrace(Vector Start, Rotator Dir)
{
local Vector X,Y,Z, End, HitLocation, HitNormal, RefNormal;
local Actor Other, mainArcHitTarget;
local int Damage, ReflectNum, arcsRemaining;
local bool bDoReflect;
local xEmitter hitEmitter;
local class<Actor> tmpHitEmitClass;
local float tmpTraceRange, dist;
local vector arcEnd, mainArcHit;


If (Other.GetClosestBone( HitLocation, X, dist, 'head', HeadShotRadius ) == 'head' )
{
Other.TakeDamage(Damage * HeadShotDamageMult, Instigator, HitLocation, Momentum*X, DamageTypeHeadShot);
}

}

// eind HS check script //


Gives 15 warnings, and doesn't work, now i cant even hit someone .. :(

legacy-EggXzaB
07-16-2003, 09:31 PM
any other ideas ?:o

legacy-Shakuurn
07-16-2003, 10:04 PM
function DoTrace(Vector Start, Rotator Dir)
{
local Vector X,Y,Z, End, HitLocation, HitNormal;
local Actor Other;
local int Damage;
local float tmpTraceRange, dist;

Weapon.GetViewAxes(X, Y, Z);

tmpTraceRange = TraceRange;

while (true)
{
X = Vector(Dir);
End = Start + tmpTraceRange * X;
Other = Trace(HitLocation, HitNormal, End, Start, true);

if ( Other != None && (Other != Instigator || ReflectNum > 0) )
{
else if ( Other != mainArcHitTarget )
{
if Other.GetClosestBone( HitLocation, X, dist, 'head', HeadShotRadius ) == 'head' )
{
Other.TakeDamage(Damage * HeadShotDamageMult, Instigator, HitLocation, Momentum*X, DamageTypeHeadShot);
else
{

Damage *= SecDamageMult;
Other.TakeDamage(Damage, Instigator, HitLocation, Momentum*X, DamageType);
}
}
}
else
{
HitLocation = End;
HitNormal = Normal(Start - End);
}
}
else
{
break;
}
}
}

Basically I just took SniperFire.uc and trimmed it down. Let's see if that will work. There may be too many "}"'s though. so be wary.

legacy-EggXzaB
07-17-2003, 12:01 AM
Yup, there's one } too many.
After I delete it, It gives me a "Bad or missing expression after || "
from the


if ( Other != None && (Other != Instigator || ReflectNum > 0) )
Line
After I deleted the || ReflectNum > 0, it gives a "Error 'else' bad command or expression" in the line


else if ( Other != mainArcHitTarget )

Dunno what to do with that, but it still gives lots of errors :(
thx for the effort you do/did for me ;)

legacy-Geminosity
07-17-2003, 06:18 AM
guys... you've got like 2 'else' statements with no referring 'if's ~blink~


if ( Other != None && (Other != Instigator || ReflectNum > 0) )
{
else if ( Other != mainArcHitTarget )

and


if Other.GetClosestBone( HitLocation, X, dist, 'head', HeadShotRadius ) == 'head' )
{
Other.TakeDamage(Damage * HeadShotDamageMult, Instigator, HitLocation, Momentum*X, DamageTypeHeadShot);
else
{

are just o.O

you can't have an else statement as the first statement nested in an if statement sillies :p

legacy-EggXzaB
07-17-2003, 09:41 AM
Yeah I thougt it looked weird either :D
But when I delete those lines, it gives the || ReflectNum > 0 error again, when I delete that, It gives the "else { break; } "
bad command or expression error..
If I delete that, It compiles, but crashes when I shoot..
argh
:eek:

legacy-Shakuurn
07-17-2003, 08:06 PM
Originally posted by Geminosity
guys... you've got like 2 'else' statements with no referring 'if's ~blink~



and



are just o.O

you can't have an else statement as the first statement nested in an if statement sillies :p

Lmao. I knew there was something I forgot. I didn't go over it as well as I should have because I was itching to play FaceOff. Oops.