Tutorial Two : Extending and Overriding PerksWe will start simply to begin with. Now you can find ALL the functions you need in other files, both in the original perks in the KFMod folder in your .../killingfloor/ directory and in Marco’s ServerPerksV5 source files which are still available on his thread.
Returning to our new Commando class, there is a gun that he’s always enjoyed but finds very expensive. So let’s give him a discount on a weapon.
Now there are two ways we can do this, we can either extend the function or overwrite the function.
Extending a FunctionI’m going to opt to extend the function to start with because it’s less coding and I don't need to do it from scratch. Our weapon shall be the G36C by Flux.
First download the mod and install it. You’ll need the files to be able to compile the perk.
This is what we are going to add to our perk to give it a discount for the weapon.
Code:
#exec obj load file="FX-KFG36C.u"
// Change the cost of particular items
static function float GetCostScaling(KFPlayerReplicationInfo KFPRI, class<Pickup> Item)
{
if ( Item == class'G36CPickup' )
{
return 0.9 - fmin(0.10 * float(KFPRI.ClientVeteranSkillLevel),0.6f); // Up to 70% discount on Assault Rifles
}
return super.GetCostScaling(KFPRI, Item);
}
Let us break it down:
Code:
#exec obj load file="FX-KFG36C.u"
This line loads the package we need.
Code:
// Change the cost of particular items
Comment so we know what we are doing here.
Code:
static function float GetCostScaling(KFPlayerReplicationInfo KFPRI, class<Pickup> Item)
Calling the function to scale the cost of the weapon.
Code:
if ( Item == class'G36CPickup' )
IF statement, if the gun is a G36C then perform this process.
Code:
return 0.9 - fmin(0.10 * float(KFPRI.ClientVeteranSkillLevel),0.6f); // Up to 70% discount on Assault Rifles
Easy bit of maths to create the discount. With comment so you can see at a glance what is going on.
Code:
return super.GetCostScaling(KFPRI, Item);
Return value to the super class which means it returns this value to its parent class so that both work together rather than this function overwriting that of its parent.
Compile and test by adding the weapon to the store and switching between perks to see the effect on the discount.
Overriding a FunctionOverriding is ideal if you want replace a function completely, for example removing all damage bonues; like so.
Code:
//Remove Damage Boosts
static function int AddDamage(KFPlayerReplicationInfo KFPRI, KFMonster Injured, KFPawn DamageTaker, int InDamage, class<DamageType> DmgType)
{
return InDamage;
}
This simply overrides the parent function so our new commando doesn't have his damage boosts and we have still not touched the base ServerPerk package.
Perk as it stands now:
Code:
class WVetCommando extends SRVetCommando
abstract;
#exec obj load file="FX-KFG36C.u"
// Change the cost of particular items
static function float GetCostScaling(KFPlayerReplicationInfo KFPRI, class<Pickup> Item)
{
if ( Item == class'G36CPickup' )
{
return 0.9 - fmin(0.10 * float(KFPRI.ClientVeteranSkillLevel),0.6f); // Up to 70% discount on Assault Rifles
}
return super.GetCostScaling(KFPRI, Item);
}
//Remove Damage Boosts
static function int AddDamage(KFPlayerReplicationInfo KFPRI, KFMonster Injured, KFPawn DamageTaker, int InDamage, class<DamageType> DmgType)
{
return InDamage;
}
defaultproperties
{
VeterancyName="Whisky Commando"
}
----------------