• 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/
  • Weve updated the Tripwire Privacy Notice under our Policies to be clearer about our use of customer information to come in line with the EU General Data Protection Regulation (GDPR) rules that come into force today (25th May 2018). The following are highlights of our changes:


    We've incorporated the relevant concepts from the GDPR including joining the EU and Swiss Privacy Shield framework. We've added explanations for why and how Tripwire processes customer data and the types of data that we process, as well as information about your data protection rights.



    For more information about our privacy practices, please review the new Privacy Policy found here: https://tripwireinteractive.com/#/privacy-notice

Simple mutator to take health with a timer

MSB3000

FNG / Fresh Meat
Nov 21, 2008
48
0
0
Hello. I'm trying to recreate a mod I made for KF1 in KF2. It's rather simple, but I just want to set up a timer to take health and play a sound. Here's the code I have so far:

Code:
class MutNightmare extends Mutator
        config(MutNightmare);

//#exec OBJ LOAD FILE="..\Sounds\NightmareSound.uax"

//var() globalconfig string NightmareTakeHealthSound; //the sound package and effect
var() globalconfig int TakeHealthInterval; //how often in seconds health is taken
var() globalconfig int HealthDamage; //how much health should be taken
var() globalconfig int HealthLimit; //how low the player's health will go before stopping
var localized string NightmareMutStr;
//var sound NightmareTakeHealthSoundEffect; //the sound effect to play when health is taken. different from the sound package itself.
//var sound NightmareGrowlEffect; //the growl effect

simulated function PostBeginPlay()
{
    local Object O;
    //local Controller C;
    local KFPawn_Human Player;
    SetTimer(TakeHealthInterval, true);

    foreach DynamicActors(class 'KFPawn_Human', Player) // for each player
    {
        //PlaySound(NightmareGrowlEffect,,60.0);
    }

}

function Timer()
{
    local Controller C;
    for (C = Level.ControllerList; C != None; C = C.NextController)
    {
        if ( C.bIsPlayer && (PlayerController(C)!=None || Bot(C)!=None) && KFPawn(C.Pawn)!=None && C.Pawn.Health>HealthLimit )
        {
            C.Pawn.Health = Max(C.Pawn.Health-HealthDamage,HealthLimit);
        }
    }
}

defaultproperties
{
    bFullVolume=True
    TakeHealthInterval = 5;
    HealthDamage = 5;
    HealthLimit = 25;
    GroupName="KFMutNightmare"
    FriendlyName="Nightmare!"
    Description="Nightmare! mode, based on the Doom 3 difficulty setting. Player's health decreases over time. Highly configurable, multiplayer compatable, includes original Doom 3 Nightmare! sound. Version 1."
    NightmareTakeHealthSound = "NightmareSound.st_takehealth"
    NightmareMutStr="Nightmare"
}
It's basically a rip from the KF1 mod. Right now I just want to modify every player's health all at once. I'm assuming this is pretty basic, but I have no idea how to address players or their health in KF2.
 

Pharrahnox

FNG / Fresh Meat
Feb 3, 2016
268
71
0
Cranny mate
Here's something I had in one of my old mods:
Code:
/** Instantly heals every player by HealthRegenAmount. This will not exceed the players' max health. */
function RegenerateHealth()
{
    local KFPlayerController KFPC;
    local Pawn Player;

    //For all player controllers
    foreach WorldInfo.AllControllers(class'KFPlayerController', KFPC)
    {
        //If they have possessed a pawn (a player)
        if(KFPC.Pawn != None)
        {
            Player = KFPC.Pawn;
            Player.Health = Min(Player.Health + HealthRegenAmount, Player.HealthMax);
        }
    }
}
As you can see, this is for regenerating health, but I think you'll find it pretty simple to adapt it to what you want. If you wanted to put RegenerateHealth() on a loop, you could do:
Code:
SetTimer(Interval, true, nameof(RegenerateHealth));
The third parameter is the name of the function you wish to call when the time is up. I use nameof(RegenerateHealth) instead of 'RegenerateHealth' (yes, including the quotation marks) so that a compiler error will come up if I get the name wrong or if I change it later down the track, instead of the function simply not being called and me not knowing why. Specifying the name of the function to call allows you to have as many timers as you want, and you can give them meaningful names.

If you haven't already done so, you should probably download the KF2 SDK so that you get access to the source code (in Steam\steamapps\common\killingfloor2\Development\Src). The name of the player class is KFPawn_Human.