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

Coding/Mutators help

tijolol

Grizzled Veteran
Jun 12, 2014
256
0
I searched a lot and couldn't find how to mod KF2. I know a bit about coding in C/C++. I'm asking for a lot but some people might be happy to help. Also this is for anyone else that might want to start modding. The best I found was this guide for KF1 but I didn't figure out how to and if I can apply this knowledge to another engine.

So here goes: Can anyone make a detailed guide explaining things from ground up? Such as "First search what unreal script and OOP is and learn it, download this IDE or this one that I preffer because of... And that's how you make a 'Hello World' from scratch... for further knowledge on more complex stuff see...".

Think of all the mods that might come from your effort, all the smiles on children's faces :D
 
If you have the SDK for kf2, you should see in your killingfloor2 folder a folder called "Development" in that find the "src" folder. This is the folder containing the source code of the game, programmed in unrealscript. If you know java and C++, learning unrealscript should be fairly simple for you since it's basically c++ with object oriented programming from java.

Now, most of this source code is stuff you're probably not interested in changing such as the engine, so you'll probably want to stick to looking for stuff in KFGame or KFGamecontent. KFGame contains most of the base classes of the game, and KFGamecontent has more specific things such as specific weapon classes and zed classes.

In order to modify these, you'll first want to go into your Documents/MyGames/Killingfloor2/KFGame folder and make a folder called Src, and in that make a folder with a name to your liking (one word) for your mod. In that folder, make a folder called Classes. Now you should have a directory Documents/MyGames/Killingfloor2/KFGame/src/MyModFolder/Classes/. This is where you will put the classes for your mod.

Now lets get started on how to actually code one. First you'll need a basic idea of what you want to change. I'd recommend using a gamemode mod instead of a mutator because I find it easier to edit classes as opposed to attempting to make changes to them through another class. To start off making your mod as a gamemode, open up a text editor, think of a name for your mod, then save as "MyModName.uc". In this new .uc file, at the top type

class MyModName extends KFGameinfo;

Keep in mind this MyModName must be the same as the name of your file otherwise it will not work. This will be your main class that will decide what is changed and what isn't.

Now that you have your basic game mode class, find something in KFGame or KFGamecontent you want to change. Modifying these isn't always easy as you always just copy-paste the class over, change a number, and compile it, but for most things in KFGamecontent it is basically this easy with one or two extra steps. In order to edit something and use it in your mod, you'll need to new .uc file that extends the thing you want to change, and in your KFGameinfo file tell the game to use your file instead of the original. The easiest way to explain this is an example.

Say I want to modify the running speed of a character. I'll make a class that extends KFPawn_Human (since that is where the movespeed of players is) like so

(in a file named KFPawn_Human2.uc)

class KFPawn_Human2 extends KFPawn_Human

defaultproperties
{
Sprintspeed=500
}

and in my gamemode class

class MyModName extends KFGameinfo_Survival;//since I want it to be the same game mode not a custom one, I have
//it extend KFGameinfo_Survival instead of KFGameinfo

defaultproperties
{
DefaultPawnClass=class'MyModFolder.KFPawn_Human2'
}

Keep in mind when editing the KFPawn_Human class by making my new human, because it extends the class I want to edit, it gets all the variables and functions for itself at the defaults as they are in KFPawn_Human. This means I only need to put code in my KFPawn_Human2 class that I want to change.

In order to run this in game, you need to go into your Documents/MyGames/Killingfloor2/KFGame/config folder, scroll to the bottom and find [Modpackages] and below the 2 lines that are under that, type "ModPackages=MyModFolder", then you need to go into your steam/steamapps/common/killingfloor2/binaries/win64 folder, shift-rightclick and open command prompt in this directory. Type
kfeditor make
and if you did everything right it should compile fine and if you go into your Documents/MyGames/Killingfloor2/KFGame/Unpublished/BrewedPC/Script/ folder you should see your compiled mod as a .u file. You can go ahead and either brew it (not sure if this does anything besides move it to the other folder, or just copy paste it into your Documents/MyGames/Killingfloor2/KFGame/published/brewedpc/ folder, and type on the command prompt you opened before
kfeditor kf-burningparis?game=MyModFolder.MyModName

Now, there is different code making your gamemode class tell the game to use your files instead of the originals, and certain things have weird workarounds you might not think of, such as changing weapons, so feel free to ask specifics on how to do each thing you want because explaining everything in detail in one post would make it be another 5 pages lol.
 
Last edited:
Upvote 0
I prefer ConTEXT for scripting. http://wiki.beyondunreal.com/ConTEXT
UnCodeX for organizing all the classes and see what inherits what from where: https://udn.epicgames.com/Three/UnCodeX.html
How to compile for KF2: http://forums.tripwireinteractive.com/showthread.php?t=107928

You need to learn unrealscript. Forget for a moment that it's KF2 or any other game out there. You need to learn the scripting language first. You should look at http://udn.epicgames.com/Three/UnrealScriptHome.html. There are lots of tutorials out there. Not many specifically for KF1 or KF2, because well, it's still UnrealScript regardless of what the game is. You'll find a lot are designed for the UDK. Which is ok, because that will carry over to KF2. BeyondUnreal has a lot of good info too.

Once you know some unrealscript, how to do you know what classes do what, and what is done differently? By looking at the games source code and seeing how the game was coded. Looking at other peoples mods and seeing how they went about doing it.
 
Last edited:
Upvote 0
Thank you so much for the responses. I'm using UnCodeX to find and figure out how the weapon selection system works and how I can change it. My initial goal is to set a key for each weapon tier or just add more weapon buttons, depending on how it is. My second one is to find a way to implement toggle sprint. The third one is to either change the real-time tracers speed to be much much higher or make hits detection not hitscan as it is already implemented in zed time. This might take me until the release of KF3 :p

Edit: first I tried the sprint change and set it to 1000, a few steps in the guide were a bit off but I got it working. Thanks :D
 
Last edited:
Upvote 0
You want to increase the speed of projectiles in Zed time? I believe changing the speed in KFProj_AssaultRifle or whatever it's called (it's in KFGameContent), making new rifle classes that extend all the weapons you want this change to apply to and setting the default projectile to be your new projectile with the enhanced speed, THEN changing the shop so it sells your rifles instead of the originals would achieve this.... kind of a pain... Not sure how you would get your edited shop to work over the original though; it's probably a simple swap in your game mode class; just check KFGameInfo or KFGameInfo_Survival for something that would do this.


If you want to increase the speed of the non-zedtime shots; check for some class that it uses for the shots out of zed time and modify those classes instead, then follow the same 2nd and 3rd steps above.




As for togglable sprinting, find the method that switches sprinting on or off when you press the key, then give it a Boolean and set it equal to !itself whenever you press the key (easier and less processing than making if statements to check if it's true or false and setting it equal to the opposite). Of course declare it at the top of the class and set it in the defaultproperties to false(or true if you want people to sprint by default). Honestly now that I think of this, I feel I should just change my mod so you're always moving sprint speed and remove sprinting because I hate the move slow on reloading and healing. Only really an issue on HOE where if you stop running for one second you lose start losing health fast, including if you stop running to heal...
 
Upvote 0
You want to increase the speed of projectiles in Zed time?

No. I don't like to mess around with stuff that makes the game easier (other than for testing). All my goals circle around trying to make them better/nicer. Thanks for the ideas though.

But again, what I'm trying to find and will be experimenting until I, TWI or someone else gets it done is:

1)More bind options for primary, secondary and tertiary weapons. So getting a weapon on the map to sell or using 3+ weapons in the same slot isn't so annoying.

2)Some form of toggle sprint as it is used whenever you're not aiming or firing.

3)Keep the NON-zed-time projectiles as hitscan and change their animation speed to as high as possible to still be visible so we don't get the bullets that killed zeds missing some time later OR use the same mechanic for projectiles as ZED time uses. I preffer the latter but I imagine it will be infinitely harder to do. That's why I want it for last, when I have a little more experience with this. By the way, if anything the ballistic option will only make the game harder and more reallistic, which is nice.
 
Upvote 0
Hi guys,

First of all, takes a lot xmrmeow for your guidelines, it helped me to start doing stuff in the right direction.

I'm encountering some trouble about the KFGame package, maybe someone can help me out.

I just wanted to change the serynge ammo and reload speed.
In a nutshell, here's what I did:

1. Copied steamapps\common\killingfloor2\Development\Src\KFGame\Classes\KFWeap_HealerBase.uc
to
My Games\KillingFloor2\KFGame\src\KFGame\Classes\KFWeap_HealerBase.uc

2. Edited the .uc file and changed:
Line 216: HealingIncrement -= 1.0; to HealingIncrement -= 50.0;
Line 779: MagazineCapacity[0]=100 to MagazineCapacity[0]=1000

3. Registered the package in My Games\KillingFloor2\KFGame\Config\KFEditor.ini:
Under [ModPackages] I added ModPackages=KFGame, so this part looks like:
[ModPackages]
ModPackagesInPath=..\..\KFGame\Src
ModOutputDir=..\..\KFGame\Unpublished\CookedPC\Script
ModPackages=KFGame

4. did a kfeditor make:
Launched cmd.exe, went to \steamapps\common\killingfloor2\Binaries\Win64 and typed kfeditor make

5. Grabbed the generated KFGame.u file in \My Games\KillingFloor2\KFGame\Unpublished\Unpublished\Unpublished\BrewedPC\Script
and copied to \My Games\KillingFloor2\KFGame\Unpublished\BrewedPC\Script

6. Brewed the mutator:
kfeditor brewcontent -platform=PC KFGame
It opened the kfeditor which tells me it's a success - 0 errors, 0 warning.
However i've the windows message "Killing Floor 2 has stopped working".
Note that file KFGame.u is successfully generated in the folder \My Games\KillingFloor2\KFGame\Unpublished\BrewedPC\Script

7. Launched kf2:
kfeditor kf-burningparis?mutator=KFGame.KFWeap_HealerBase

And killing floor 2 crashes...

It's weird, if I perform the exact same modifications on KFGameContents files, it works perfectly... Any thoughts?? :confused:
 
Upvote 0
You're not meant to recompile game files, you should never do it this way. You will run into a lot of issues such as this with breaking the game.

Modding isn't fully supported yet. You might be able to use checkreplacement through a mutator to do what you want to do. Or you can create a new weapon and use cheats to give it to yourself.

To get an idea on how modding is done, look at the KF1 guide:
http://forums.tripwireinteractive.com/showthread.php?t=43534
 
Last edited:
Upvote 0
Thanks for your reply Slie.

So if I read correctly, I shouldn't start from KFGame at all or should I just wait for "real modding" to come out?

I admit I took the quick and dirty way by directly messing with the KFGame as I'm pretty new to KF2 modding.

Would using the method described by xmrmeow (that is, creating a brand new game type and/or not overriding the standard classes) work?
 
Upvote 0
Modifying the game files like that only works with KFGameContent; trying to do it with KFGame causes a lot of compiler errors and usually just ends up in the game crashing on launch anyway.

For modifying healer base your best bets for minimizing work would be to make new classes that extend the classes of everything that heals and set your human player to spawn with your syringe class if you want it to apply to the syringe, and change the trader to sell your modified weapon classes instead of the old ones.

You could just do things the way you were doing it for the KFGameContent files that heal by adding in their default properties the changes you had, but this is not the traditional way of doing it as it can cause some issues with running the unmodded game, causing you to have to move files around to turn the mod on or off. Main differences between this method and the recommended method of making mods is this is simpler, but the recommended method is easier to install and works with all game files not just gamecontent ones.
 
Upvote 0
Thanks a bunch for your support guys, it really helped.

My main goal at first was to add new dialog options in the voice comm menu, I started to tweak KFGame\Classes\KFGFxWidget_VoiceComms.uc but ended up in errors. So I tried a more basic thing by changing serynges-related stuff in KFGame, just to check if it was KFGame related.

Thanks to your input, I now know that's indeed related to KFGame.

I think I'll wait for more modding options to come out. Thanks again for your time!
 
Upvote 0