• 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 All you can eat info on how to mod KF2 with a gameinfo class

xmrmeow

Grizzled Veteran
  • Mar 23, 2015
    1,009
    11
    Basic steps:

    1. Download the sdk off steam to get the original source code of the game, which will be found in steam/steamapps/common/killingfloor2/development/src

    2. Find your MyDocuments/MyGames/Killingfloor2/KFGame folder (this should be autogenerated if you run the sdk I believe) and create a folder called "Src", then in that, make another folder with whatever you want your package to be named, AND in that, put a folder named Classes. (so now you have mydocs/mygames/killingfloor2/kfgame/src/MyPackage/Classes)

    3. Create a .uc file (can be done with any text editor program, might I recommend notepad++) and name it whatever you want your gameinfo class to be called. In this file, the first line should be "class MyGameInfo extends KFGameInfo_Survival;" (MyGameInfo can be whatever you want as long as it's the same name as the file, the rest must be as is). Below that put "defaultproperties" with curly brackets under it.

    Now you've got your basic setup, skip through the next few steps depending on what you want to do:

    4 - Altering zeds:
    To make changes to a zed, make a class that extends the zed you want to change (E.g. class KFPawn_Husk2 extends KFPawn_Husk). Now in your gameinfo class, in the brackets, add a line with the class path for your zed so your gameinfo knows to use this instead of the original. The lines are as follows

    AIClassList(0)=Cyst
    AIClassList(1)=Slasher
    AIClassList(2)=Clot
    AIClassList(3)=Crawler
    AIClassList(4)=Gorefast
    AIClassList(5)=Stalker
    AIClassList(6)=Scrake
    AIClassList(7)=Fleshpound
    AIClassList(8)=Bloat
    AIClassList(9)=Siren
    AIClassList(10)=Husk
    AIBossClassList(0)=Hans
    AIBossClassList(1)=Patriarch

    Add the line for the zed you changed, and past the equals sign, put " Class'Mypackage.Myzed' " (E.g. AIClassList(0) = Class'KFRebalanced.KFPawn_ZedClot_MyCyst' )

    5 - Altering zed AI:
    In each zed class, there is a variable called ControllerClass which is a path to the aicontroller for that zed. To alter AI, you must do step 4, then in your zed class, add the line ControllerClass=class'KFAIController_MyAIController' (you can name the aicontroller whatever you want). Then just make an AIController class that has the same name you put in that line, have it extend the original AIController class for that zed (unless you don't want it to be able to do the same things as that zed aside from the default properties).

    5 - Altering/creating new Weapons:
    NOTE: If you're altering a weapon that players start with (e.g. caulk n burn) you'll need to create a class that extends the perk that starts with it, and set it to use your weapon in the default properties. See step 6 for altering perks as well.

    Create a class that extends the weapon you want to change or make your own weapon and have it extend one of the basic weapon classes. Might I recommend seeing some existing weapons for getting a feel of what to code to get the effects you want. Once you're happy with your weapon class, create a weapon defintion class for it by creating a class the extends KFWeaponDefinition and in defaultproperties put WeaponClassPath="Mypackage.MyWeaponClass". See existing weapon definition files for other things you'll want to add to this weapon definition such as cost and ammo cost.

    Now compile your code (see step 7)

    Now open up the SDK through steam and, in the content browser, create a new package with any name. Then, find the gameplay package, in that you should see GP_Trader_ARCH, and in that, you'll find DefaultTraderItems (you may need to rightclick the package and click fully load to see it). Now copy this into the package you made(you may need to click save, export, then import it back in because sometime copy is greyed out for some reason). With the DefaultTraderItems copy in your package, double click to edit it, and for an existing weapon, find the weapon in the saleitems list and replace it with your weapon. For a new weapon, click the little + and set it to use your new weapon. Then click the checkbox that says "Build now" or something to finalize your list. Now save your package (right click the package and click save).

    Now you'll need a class that extends KFGameReplicationInfo, and in the default properties, add the line TraderItems=KFGFxObject_TraderItems'MySdkPackage.DefaultTraderItems'

    Now add the line GameReplicationInfoClass=class'Mypackage.MyKFGameReplicationInfo' to the default properties in your gameinfo class.

    Now you can find the package you made in the sdk in your mydocs/mygames/kf2/kfgame/unpublished folder. Copy paste that package into your classes folder with your source code and recompile (otherwise the traderitems line won't know where it is and give a warning/error).

    Next go to your steamapps/kf2/kfgame/localization/int folder and create a .int file with a text editor and name the file the same name as your package with your source code. You'll give your weapon a description here. See the KFGameContent.int for what to put in your int file.

    *NOTE* If the weapon is a projectile or melee, the associated perk info is also in the damage type for that projectile. To get perk effects to apply you must list the perk as a modifier perk in the damage type class for that projectile. E.g. I have a shotgun class: make a new projectile that extends the existing one, set the damage type to a new one that extends the existing damage type, and add a line setting the modifier perk to the perk you want.

    Weapons this applies to:
    All melee weapons
    All shotguns
    All explosive weapons
    All firebug weapons (the place you set to use your new damage type is in an archetype file found in the SDK; for caulk it would be in weapons->caulk->wep_whatever_arch, just copy the archetype into your package and set the damage types to your damage types and set in the weapon class to use your archetype as the flamespray mesh instead of the original)

    6 - Altering Perks:

    Create a Class that extends the perk you want to alter, and change the functions/default properties you want to change.

    Now all weapons this perk uses must have altered weapon classes to set their associated perk with your altered perk (e.g. my altered perk is KFPerk_Commando2, I must go through each assault rifle and make a new weapon class that extends the originals, and in default properties add a line setting the associated perk to KFPerkCommando2 instead of commando). See step 5 for the lengthy process involving altering weapons.

    Now create a PlayerController class that extends KFPlayerController, add lines replacing the original perk with the perk you made to the default properties (see KFPlayerController for what these lines are).

    Now add a line in your gameinfo class PlayerControllerClass = class'MyPackage.MyPlayerController'

    7 - Compiling your code:

    in mydocs/mygames/kf2/kfgame/config open the file KFEditor.ini , scroll near the bottom, and under [ModPackages] add a line ModPackages=MyPackage and save

    Now go to steamapps/kf2/binaries/win64 , shift-rightclick and click open command window here. In it, type KFEditor make and if you did everything right, your code will compile successfully with no warnings and your compiled file will appear in mydocs/mygames/kf2/kfgame/unpublished/script

    To run this, put this file in your KFGame/Brewed pc of your server folder, and add ?game=MyPackage.MyGameinfo to your command line of a server, or for the game, do the same for your steamapps folder, and in the command window you opened before, type KFGame mapname?same as above (e.g. KFGame kf-bioticslab?game=MyPackage.MyGameInfo)

    --------------------------------------------------------------------------------------------------------------------------------------
    Here's the source code for my Rebalance mod if you'd like to see exactly how to do certain things first hand https://www.dropbox.com/s/94b6dupqa8tzdjf/Rebalance Source Code.zip?dl=0 . If you have any questions or things to add, post them here and answer them/update the OP post to include whatever you have to add. I hope, if anything, this saved you some time and headaches that I experienced from sifting through code myself and asking around on the forums to figure all of this out.
     
    Last edited:
    • Like
    Reactions: Patros
    First of all thanks for making this , I find the documentation for KF2 modding is limited and this is nice to see.

    I have a few questions that I would love to have answered:


    1. What is the difference between this method and the "mutator" method ? can someone explain to me what the fundamental differences are ? and more importantly what are the limitations of this method and the mutator method.
    2. Why is it that you cannot just alter the base classes ? like take berzerker perk and change it to start with a pulverizer by changing one line of code? primaryWeaponDef =


    to make sure I understand what you are explaining, if I want to alter Berserker to start with a pulverizer, I would have to:

    • make a class that extends Gameinfo_survival
    • make a class that extends KFPerk_berserker
    • make a change in default properties ( primaryWeaponDef) within new perk class
    • make a class that extends playercontroller and tell it to use my new perk (PerkList.Add((PerkClass=class'MyPerk')))
    • add my new playerController to my gameinfo class (PlayerControllerClass=class'my_package.MyPlayerController')
    • now , because I altered a perk I now have to alter ALL perk weapon classes and tell them about my perk ?
    • then compile this ?


    This seems like a lot of work to make a simple change, in fact its almost a bit overwhelming. I am going to give this a go and see how far I make it. thanks for your help.
     
    Upvote 0
    Personally, I would use a mutator when ever possible. You can stack mutliple mutators into a game. You cannot with gamemodes. Gamemodes should be reserved for gameplay when it cannot be done through a mutator. As for what can and can't be done, that's not something to be written up in a paragraph. You need to learn unrealscript.

    to make sure I understand what you are explaining, if I want to alter Berserker to start with a pulverizer, I would have to:

    This can be done with a mutator instead with a few lines of code.
    Use the ModifyPlayer function. Simple example:

    function ModifyPlayer(Pawn Other) {
    Super.ModifyPlayer(Other);
    Other.CreateInventory(class<Weapon>(DynamicLoadObject("NewWeaponPackage.NewWeapon", class'Class')));
    }

    EDIT: Forum is adding a space in "DynamicLoadObject", should be one word.
     
    Last edited:
    Upvote 0
    Personally, I would use a mutator when ever possible. You can stack mutliple mutators into a game. You cannot with gamemodes. Gamemodes should be reserved for gameplay when it cannot be done through a mutator. As for what can and can't be done, that's not something to be written up in a paragraph. You need to learn unrealscript.



    This can be done with a mutator instead with a few lines of code.
    Use the ModifyPlayer function. Simple example:

    function ModifyPlayer(Pawn Other) {
    Super.ModifyPlayer(Other);
    Other.CreateInventory(class<Weapon>(DynamicLoadObject("NewWeaponPackage.NewWeapon", class'Class')));
    }

    EDIT: Forum is adding a space in "DynamicLoadObject", should be one word.


    This seems like it would affect any perk not just berserker. I will do my best to dig into unrealscript to help simplify this.
     
    Upvote 0
    I find mutators to be less straight forward than gameinfo classes. Mutators you have to have them change existing things in weird ways.

    For example, If I change berserker in a gameinfo class, I'd create a class that extends berserker, overload the functions I want to replace, and change the default properties I want changed. Then I just need to set my default playercontroller to a one that extends player controller and change the perk list for that to include my berserker instead of the original.

    I don't know how you'd do it with a mutator, but looking at code from mutators is a lot harder for me to understand.

    The reason editing the existing classes doesn't work is the game won't replace the existing files unless you overwrite the package. Overwriting packages like KFGame, KFGameContent, etc just cause the game to crash on start. Even if it didn't cause the game to crash, since it changes core files, you'd have to back up and replace files constantly to switch between the original and modified KF.


    To answer your question about how you would make berserker spawn with pulverizer, yes you would need to do all of that and follow the appropriate steps for creating the weapons as well. Keep in mind most of the class creation stuff is fairly simple if nothing about the weapon is changed.

    e.g. creating a pulverizer for your Berserker class would only contain the following code:

    class KFWeap_Blunt_Pulverizer2 extends KFWeap_Blunt_Pulverizer;

    defaultproperties
    {
    AssociatedPerkClass=class'KFPerk_Berserker2'
    }


    and your berserker class would just be

    class KFPerk_Berserker2 extends KFPerk_Berserker;

    DefaultProperties
    {
    PrimaryWeaponDef=class'KFWeapDef_Pulverizer2'
    }

    Even though it looks like a lot of work, most of the steps can be done in a few seconds. Once you got the initial setup, adding new weapons, modifying perks, or changing existing weapons/functions is very quick and easy with a gameinfo mod. Lemme whip up a quick demo program for people to mooch off of.
     
    Last edited:
    Upvote 0
    Ok, Things are starting to click a little.

    I made my first mutator and I am starting to understand the difference between mutator and gameinfo mod.

    The Mutator seems to use altered "objects / files" and swaps them over the original objects/ files. your not altering a weapon , you are swapping said weapon for an altered version , and checking every object and swapping it for your altered is how i understand it. Mutators seem to be an excellent way of altering the game without changing its code directly. Good for something small but seem to be useless for a large overhaul of game content.

    the gameinfo mod seems to be a beefier way of modding the game, your limitations are less than a mutator and your altering of the code is more direct than a mutator. It seems to me if you wanted to make a larger mod that alters a large portion of the game this would be the best method.

    thanks alot for the help guys, I am interested in xmrmeow's further guides as I would like to make a gameinfo mod.
     
    Last edited:
    Upvote 0
    https://www.dropbox.com/s/g856zrvdcrdgi91/Gameinfo mod demo.zip?dl=0

    This isn't finished, but I threw together some stuff. Don't expect it to compile cause some stuff is missing, but this is a basic framework of what a gameinfo mod will look like. I think they have to be all in the same folder, I just added subfolders to make it look nicer, I'm not sure though.

    The package name would be "demo" and the upk file that goes along with this would be "demoPackage". Of course you'll also need an int file for the stuff to appear properly in the shop. I'll add onto it so it's finished later (probably this weekend, got homework due tomorrow and thursday)
     
    Upvote 0
    Hi. Sorry for digging this thread up, but I am having a difficulty in compiling mutator with upk file.
    HfklxKo.png

    I got this when try to compile. There is already a file called "M79Med.upk" contained DefaultTraderItems in the same folder with .uc source codes.
    Here is a picture inside the error file:
    p86iOHy.png
     
    Upvote 0
    linkedparadise;n2286003 said:
    I got this when try to compile. There is already a file called "M79Med.upk" contained DefaultTraderItems in the same folder with .uc source codes.

    upk files go in the BrewedPC folder. You do not compile it inside the classes folder. The classes folder is for code only. However, you can merge the .upk into the .u using the mergepackages parameter. I'm not sure if KF2 supports including other files during compiling or not.
     
    Upvote 0