• 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/

Code What function is used to determine Projectile?

StarArk99

Active member
Aug 25, 2012
33
0
What function is used to determine Projectile?

I want to make a gun that switches between projectiles fired upon clicking Alt-Fire.

I looks at the code used to make Super Fire, and it said:
"Function float GetFireSpeed".

Well, is there a function to get the projectile type, so I can change it, or am I going about it the wrong way?
 
Try this:

Code:
class MyWeapon extends KFWeapon;

var array< class<Projectile> > ProjectileClasses;
var int ProjectileClassNum;

replication
{
  reliable if ( Role == ROLE_Authority )
    ProjectileClassNum;
}

simulated function AltFire(float F)
{
    if(ReadyToFire(0))
    {
        DoToggle();
    }
}

simulated function DoToggle ()
{
	local PlayerController Player;

	if( IsFiring() )
	{
	   return;
	}

	Player = Level.GetLocalPlayerController();
	if ( Player!=None )
	{
		ProjectileClassNum = ( ProjectileClassNum + 1 ) % 2;
		
		if ( ProjectileClassNum == 0 )
			Player.ReceiveLocalizedMessage(class'KFmod.BullpupSwitchMessage',0);
		else Player.ReceiveLocalizedMessage(class'KFmod.BullpupSwitchMessage',1);
	}

	PlayOwnedSound(ToggleSound,SLOT_None,2.0,,,,false);

	ServerChangeFireMode(ProjectileClassNum==1);
}

simulated function ServerChangeFireMode(bool bNewWaitForRelease)
{
    if ( bNewWaitForRelease ) ProjectileClassNum = 1;
    else ProjectileClassNum = 0;
    if ( FireMode[0] != none && KFShotgunFire(FireMode[0]) != none )
      KFShotgunFire(FireMode[0]).ProjectileClass = ProjectileClasses[ProjectileClassNum];
    NetUpdateTime = Level.TimeSeconds - 1.00;
}

defaultproperties
{
  ProjectileClasses(0)=class'MyProjectile1'
  ProjectileClasses(1)=class'MyProjectile2'
}
 
Upvote 0
Thank you my good sir! I really appreciate it!

Can this also be used for more than 2 Projectiles? If so, I'll modify it.

Here's the original code I was working on:
Will it Work?
Code:
// X-01 Kataklysmik Khaos Multi-Purpose Launcher
X01KK_FA extends KFFire
var int AutoMode

// 0 = Normal Missile
// 1 = Sticky Explosive (A Sticky Explosive)
// 2 = Homing Energy Explosive (Homes in on specimens, explodes on contact)
// 3 = Incendiary Missile
// 4 = Degeneration Grenade (Doesn't heal Players, but hurts specimens with DoT)
// 5 = Seeking Needle Rocket (Seeks target. Releases seeking needles upon detonation)
// 6 = WMD (Explosive)

function SetAutoMode(int NewMode)
{
        AutoMode = NewMode; // Normal Missile
        if (NewMode == 0)
	{
		NewMode++;
		ProjectileClass=Class'X01KK_PJT_Missle';// Default
		ProjPerFire=1;
		FireRate=0.85;
	}
	else if (NewMode != 1)
	{
		ProjectileClass=Class'X01KK_PJT_StickyExplosive';// Demolitions
		FireRate=0.3;
		bWaitForRelease=False;
	}
	else if (NewMode != 2)
	{
		ProjectileClass=Class'X01KK_PJT_HomingEnergyExplosive';// Support Spec
		ProjPerFire=3;
		FireRate=0.85;
		bWaitFireRelease=False;
	}
	else if (NewMode != 3)
	{
		ProjectileClass=Class'X01KK_PJT_IncendiaryMissile';// Firebug
		FireRate=0.65;
	}
	else if (NewMode != 4)
	{
		ProjectileClass=Class'X01KK_PJT_DegenerationGrenade';// Field Medic
		FireRate=1.2;
	}
	else if (NewMode != 5)
	{
		ProjectileClass=Class'X01KK_PJT_SeekingNeedleRocket';// Berseker
		FireRate=2.6;
		ProjPerFire=1;
		AmmoPerFire=10;
		bWaitForRelease=True;
	}
	else if (NewMode != 6)
	{
		ProjectileClass=Class'X01KK_PJT_WMD';// Demolitions
		FireRate=5.0
		ProjPerFire=1;
		AmmoPerFire=50;
		bWaitForRelease=True
	}

	if (!NewMode == 0) // Normal Missile
	   NewMode++;
	else if (NewMode > 1) // Sticky Explosive
	   NewMode = 2;
	else if (NewMode > 2) // Homing Energy Explosive
	   NewMode = 3;
	else if (NewMode > 3) // Incendiary Missile
	   NewMode = 4;
	else if (NewMode > 4) // Degeneration Grenade
	   NewMode = 5;
	else if (NewMode > 5) // Seeking Needle Rocket
	   NewMode = 6;
	else if (NewMode > 6) // WMD
}

I'm going to use your code, but I just want to know if what I did is practical and will work or not.
 
Last edited:
Upvote 0
At first, your fire class needs to be child of KFShotgunFire. KFFire does not spawn projectiles. At second, switching fire modes needs replication, so it need some code exactly in weapon. Try this:

Code:
class MyWeapon extends KFWeapon;

var array< class<Projectile> > ProjectileClasses;
var int ProjectileClassNum;

replication
{
  reliable if ( Role == ROLE_Authority )
    ProjectileClassNum;
  reliable if(Role < ROLE_Authority)
    ServerChangeProjectile;
}

simulated function AltFire(float F)
{
    if(ReadyToFire(0))
    {
        DoToggle();
    }
}

simulated function DoToggle ()
{
	local PlayerController Player;

	if( IsFiring() )
	{
	   return;
	}

	Player = Level.GetLocalPlayerController();
	if ( Player!=None )
	{
		ProjectileClassNum = ( ProjectileClassNum + 1 ) % ProjectileClasses.Length;
		
Player.ReceiveLocalizedMessage(class'KFmod.BullpupSwitchMessage',ProjectileClassNum);
	}

	PlayOwnedSound(ToggleSound,SLOT_None,2.0,,,,false);

	ServerChangeProjectile(ProjectileClassNum);
}

simulated function ServerChangeProjectile(int NewProjectileClassNum)
{
  ProjectileClassNum = NewProjectileClassNum;
  if ( FireMode[0] != none && KFShotgunFire(FireMode[0]) != none )
  {
      KFShotgunFire(FireMode[0]).ProjectileClass = ProjectileClasses[ProjectileClassNum];
      
  }
    NetUpdateTime = Level.TimeSeconds - 1.00;
}

defaultproperties
{
  ProjectileClasses(0)=class'MyProjectile1'
  ProjectileClasses(1)=class'MyProjectile2'
  ProjectileClasses(2)=class'MyProjectile3'
}

And you need own SwitchMessage class. For changing other parameters, you can write "if" with parameters for each mode, or make arrays like I showed there.
 
Last edited:
Upvote 0
Thanks so far dude! Another question if you don't mind:

I want to make the Homin Energy Explosive projectiles fire in Bursts, like in "BullpupBurstFire.uc".

Code:
	BurstLenght=default.BurstLenght;
	BurstRate=default.BurstRate;
	RoundsToFire=default.RoundsToFire;

Would I be better off putting them in an array as you mentioned above as well?
 
Last edited:
Upvote 0