KF Error in custom code, probably a noob mistake

  • Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

oozinator

FNG / Fresh Meat
Jan 9, 2014
15
0
0
I keep getting a bad expression at the 'MeleeDamage *= ' line because I don't know how to properly grab my custom variable (that comes from a different class file).

Code:
class ChargeSwordFire extends KFMeleeFire;
var() array<name> FireAnims;

function ChargeDamageCalc()
{     
      
      if ( !ChargeSword(Weapon).bNoHit )
      {
            [COLOR="Red"]MeleeDamage *= (1 + MCharged );[/COLOR]
            MCharged = 0.0;
      }  
}

simulated event ModeDoFire()
{
    local int AnimToPlay;

    if(FireAnims.length > 0)
    {
        AnimToPlay = rand(FireAnims.length);
        FireAnim = FireAnims[AnimToPlay];
    }

    Super.ModeDoFire();

}

defaultproperties
{
     FireAnims(0)="fire"
     FireAnims(1)="fire2"
     FireAnims(2)="fire3"
     FireAnims(3)="fire4"
     FireAnims(4)="fire5"
     FireAnims(5)="fire6"

     MeleeDamage=210
     ProxySize=0.150000
     weaponRange=110.000000
     DamagedelayMin=0.63
     DamagedelayMax=0.63
     hitDamageClass=Class'KFMod.DamTypeClaymoreSword'
     FireRate=1.05
     BotRefireRate=1.00000
     MeleeHitSoundRefs(0)="KF_ClaymoreSnd.Claymore_Impact_Flesh"
     HitEffectClass=class'AxeHitEffect'
     //bWaitForRelease=True // Turned off in Balance Round 1 to allow Auto Fire again
     WideDamageMinHitAngle=0.65
}

Here's the other class from where the first class is grabbing MCharged.

Code:
class ChargeSwordFireB extends WeaponFire;

var travel float MCharged;
var float MaxMCharged;

function ChargeUp()
{
      local float StartTime;
      local float EndTime;

      if( bIsFiring && ( MCharged < MaxMCharged ) )
      {
            StartTime = Level.Timeseconds;
      }
      if ( !bIsFiring || ( MCharged >= MaxMCharged ))
      {
            EndTime = Level.Timeseconds;  
      }

      MCharged += ( EndTime - StartTime );
      // return MCharged; 
}

function DrawMuzzleFlash(Canvas Canvas)
{
}

function FlashMuzzleFlash()
{
}

function StartMuzzleSmoke()
{
}

event ModeDoFire()
{
}

event ModeHoldFire()
{
}

simulated function bool AllowFire()
{
    return false;
}

function ServerPlayFiring()
{
}

function PlayPreFire()
{
}

function PlayFiring()
{
}

function PlayFireEnd()
{
}

function float MaxRange()
{
	return 0;
}

defaultproperties
{
      MCharged=0.0
      MaxMCharged=10.0
}

User experience: I only took an intro to C# course. I did well but that was many years ago. Please explain what's wrong to me as if I were 5.

EDIT: For those wondering what I want the weapon to do, I am hoping that holding down the middle mouse will charge up the primary damage. When the primary fire does a hit, all the stored charge is dumped onto whatever is hit.
 
Last edited:

Dr_Killjoy

FNG / Fresh Meat
Sep 30, 2012
260
0
0
Code:
function ChargeDamageCalc()
{     
	local KFMeleeGun KFMG;
	local ChargeSwordFireB SecondFire;
	if (Weapon != none)
		KFMG = KFMeleeGun(Weapon);
	if (KFMG == none)
		return;
	if (KFMG.FireMode[1] != none)
		SecondFire = ChargeSwordFireB(KFMG.FireMode[1]);
	if (!KFMG.bNoHit && SecondFire != none)
	{
		MeleeDamage *= (1 + SecondFire.MCharged);
		SecondFire.MCharged = 0.0;
	}  
}
But you doing things in wrong direction. If your plan won't work, tell me I have some idea how to do what you need.
 
Last edited:

oozinator

FNG / Fresh Meat
Jan 9, 2014
15
0
0
Hey thanks for the quick response, Dr._Killjoy.

So I tried your code and got an error at Line 21: Error, Can't access protected variable 'FireMode' in 'Weapon'

I would like to hear your suggestion. I am probably approaching it the wrong way.