Tripwire Interactive Forums

Go Back   Tripwire Interactive Forums > Killing Floor Forums > Killing Floor Modifications > Coding

Reply
 
Thread Tools Display Modes
  #1  
Old 07-10-2012, 03:20 AM
Vallo Vallo is offline
Junior Member
 
Join Date: Jul 2012
Posts: 6
Default [Help] First Mutator

Hey guys,

I thought I'd try to write my first mutator today and start simple but I am lost. It compiles but does nothing in game. From searching the forums it looks like I'm meant to to use ModifyVelocity in some form but I have no idea how.

In the end I'm hoping to make it a sprint function but right now I'm just trying to change the player speed overall for the whole match. Anyway, here is the bit of code I tried:

Code:
class SprintMutator extends Mutator;

function PostBeginPlay()
{
    local KFHumanPawn Player;
    
    foreach DynamicActors(class 'KFHumanPawn', Player)
    {
        Player.GroundSpeed = 2000.0; //high to make sure I just wasn't noticing the increase
    }
}


defaultproperties
{
    GroupName="KFSprintMutator"
    FriendlyName="Allow Sprint"
    Description="More Speed"
}
Thanks for any help you can give me
Reply With Quote
  #2  
Old 07-10-2012, 08:22 AM
Gartley's Avatar
Gartley Gartley is offline
Senior Member
 
Join Date: Dec 2010
Location: UK
Posts: 2,152
Default

Hey Vallo, good to see a new face learning the ropes.

Sorry there hasn't been much response. My recommendation to you is think simpler. You've got the correct function. But there is a much easier way to change a classes default value. You would have already seen it if following the tutorials on this board.

Shout back if you are still stuck.
__________________
Whisky's Workshop

"As you can see here, I'm -ALL ON MY F***ING OWN! Guys where the hell are you?!"
Reply With Quote
  #3  
Old 07-10-2012, 09:27 AM
TheMutant's Avatar
TheMutant TheMutant is offline
Senior Member
 
Join Date: May 2012
Location: Germany
Posts: 253
Default

Good for the first approach. The mutator code does work, but it has no effect and that is logical.
You have to consider when PostBeginPlay() will be called. UnrealWiki

PostBeginPlay() will be called when your Mutator will be created. So this happens at level start up. But at this time no player (Playerpawn) exists.
So your iteration won't find any suitable object to modify.

Therefore you should use the Mutator's "ModifyPlayer(Pawn Other)" function. This function will be called every time a "Pawn" spawns.
Then modify the value directly in there and you will get the result you want to.
Reply With Quote
  #4  
Old 07-10-2012, 09:53 AM
Gartley's Avatar
Gartley Gartley is offline
Senior Member
 
Join Date: Dec 2010
Location: UK
Posts: 2,152
Default

PostBeginPlay() function will still work as he desires as it changes the variable at the beginning of the game.

Code:
simulated function PostBeginPlay()
{
	//Increase base speed value.
 	class'KFHumanPawn'.default.GroundSpeed = 2000; //200	
}
Although your way would be equally as valid.
__________________
Whisky's Workshop

"As you can see here, I'm -ALL ON MY F***ING OWN! Guys where the hell are you?!"
Reply With Quote
  #5  
Old 07-10-2012, 10:07 AM
braindead's Avatar
braindead braindead is offline
Senior Member
 
Join Date: Aug 2009
Location: Merry Ol' England
Posts: 911
Default

Quote:
Originally Posted by Gartley View Post
PostBeginPlay() function will still work as he desires as it changes the variable at the beginning of the game.

Code:
simulated function PostBeginPlay()
{
	//Increase base speed value.
 	class'KFHumanPawn'.default.GroundSpeed = 2000; //200	
}
Although your way would be equally as valid.
lol you are both right. Except, Whisky, yours would have issues because as said, the Pawn isn't loaded at that point (I think), so a timer would be required.....

taken from Benjamins, mutator tutorial thread

Code:
class ExampleMutator extends Mutator;

function PostBeginPlay()
{
	SetTimer(1, true);
}

function Timer()
{
	local KFHumanPawn Player;
	
	foreach DynamicActors(class 'KFHumanPawn', Player)
	{
          Player.default.GroundSpeed = 2000.0; //high to make sure I just wasn't noticing the increase
	}
}

defaultproperties
{
    GroupName="KFExampleMutator"
    FriendlyName="Example Mutator"
    Description="Mutator description here"
}

or

Code:
class ExampleMutator extends Mutator;

ffunction ModifyPlayer(Pawn Other)
{


    local xPawn ThePawn;

	
    if(Other.IsA('xPawn'))
    {
    	ThePawn = xPawn(Other);
        ThePawn.default.GroundSpeed = 2000.0; //high to make sure I just wasn't noticing the increase
    }
}
defaultproperties
{
    GroupName="KFExampleMutator"
    FriendlyName="Example Mutator"
    Description="Mutator description here"
}
__________________
Reply With Quote
  #6  
Old 07-10-2012, 10:16 AM
TheMutant's Avatar
TheMutant TheMutant is offline
Senior Member
 
Join Date: May 2012
Location: Germany
Posts: 253
Default

Quote:
Originally Posted by Gartley View Post
PostBeginPlay() function will still work as he desires as it changes the variable at the beginning of the game.

Code:
simulated function PostBeginPlay()
{
    //Increase base speed value.
     class'KFHumanPawn'.default.GroundSpeed = 2000; //200    
}
Although your way would be equally as valid.
Yeah, I know that method as well, but I try to avoid that wherever I can.
The problem is when you host several different modded servers (on the same machine) these values does affect both servers.
Futhermore, when the client changes from Internet play to Solo these values remain being stored.
Moreover, it does only change the defaults from 'KFHumanPawn', so if a modded server uses a subclass it won't have any effect on them.

@braindead, it should work as Gartley described, but it brings along some issues as I described above.

Last edited by TheMutant; 07-10-2012 at 03:21 PM.
Reply With Quote
  #7  
Old 07-10-2012, 11:19 AM
Gartley's Avatar
Gartley Gartley is offline
Senior Member
 
Join Date: Dec 2010
Location: UK
Posts: 2,152
Default

Ah yes, it worked fine in solo, just not multi player. Derp point for me for not double checking.
__________________
Whisky's Workshop

"As you can see here, I'm -ALL ON MY F***ING OWN! Guys where the hell are you?!"
Reply With Quote
  #8  
Old 07-10-2012, 08:17 PM
YoYoBatty's Avatar
YoYoBatty YoYoBatty is online now
Senior Member
 
Join Date: Dec 2009
Location: Canada
Posts: 3,319
Default

The thing about this is that KFPawn or KFHumanPawn has a ModifyVelocity function which alters the pawn's groundspeed, I discovered while trying to make my character run in my mod I had to play around with that function to get it to work properly. I set the groundspeed to multiply by a value of 1.5 whenever you sprint and it didn't end up working so I used my method said before. I'm not sure how actually setting to the value to a certain number will work out or if it has changed since then.
__________________
Reply With Quote
  #9  
Old 07-11-2012, 06:12 AM
Vallo Vallo is offline
Junior Member
 
Join Date: Jul 2012
Posts: 6
Default

Thanks for your help guys. I tried braindead's second implementation and it worked perfectly for me.

Just a few questions:
1. With ModifyPlayer(Pawn Other) I'm having trouble working out what "Other is in reference to (or what references it)

2. xPawn is used instead KFHumanPawn which from what I can see has some different values stored in it. How interchangeable are they, or should I use one over the other?

3. Would it work online? (From what I can see it worked on my listen server but I am clueless in every way when it comes to networking so I'm not sure if it would work fine for other players)

If you could answer any of these or at least point me in the right direction where I can work it out myself it would be very much appreciated. And one last question about the forum... If I continue working on this mutator and need help should I start a new thread or just keep going with this one?

Anyway, I'm going back to trawling through the wiki
Reply With Quote
  #10  
Old 07-11-2012, 03:26 PM
FluX FluX is offline
Senior Member
 
Join Date: Oct 2010
Posts: 3,729
Default

Quote:
Originally Posted by Vallo View Post
Thanks for your help guys. I tried braindead's second implementation and it worked perfectly for me.

Just a few questions:
1. With ModifyPlayer(Pawn Other) I'm having trouble working out what "Other is in reference to (or what references it)

2. xPawn is used instead KFHumanPawn which from what I can see has some different values stored in it. How interchangeable are they, or should I use one over the other?

3. Would it work online? (From what I can see it worked on my listen server but I am clueless in every way when it comes to networking so I'm not sure if it would work fine for other players)

If you could answer any of these or at least point me in the right direction where I can work it out myself it would be very much appreciated. And one last question about the forum... If I continue working on this mutator and need help should I start a new thread or just keep going with this one?

Anyway, I'm going back to trawling through the wiki
I think I have the correct answers so i'll try to explain them.

1.) 'Other' is referenced in the function itself as a parameter.
Code:
ModifyPlayer(Pawn Other)
Basically, what parameters do is say "this is also known as" or it is "type and name" so basically Other is known as Pawn. This doesn't pick just a specific pawn but all pawns (which means all the children classes that come off the 'Pawn' aswel).
Another example of this would be inside KFVeterancyTypes.uc at the reload modifier function (static function float GetReloadSpeedModifier(KFPlayerReplicationInfo KFPRI, KFWeapon Other) ). Now to show how this is the same, look at the parameters. Parameters are used for "this is known as this" to shorten code down which has too many advantages to describe here. KFPlayerReplicationInfo will be known as KFPRI in the function and KFWeapon will be known as Other in this function. This goes back to the child classes as they all will be affected, specially shown in the KFWeapon = Other and Pawn = Other examples.

2.) xPawn has the same values as KFHumanPawn but KFHumanPawn has more in it. KFHumanPawn extends some Pawn class, which keeps getting extended up to xPawn. Each version that is extended has new functions, variables and other important information which is sometimes best seperated so you could extend off of a specific Pawn class and not have to redo the code and have it do something completely different to another Pawn class extending the same one.

3.) I would presume it to work as it checks all pawns AFTER everything has been set and then sets the mutator to do it's job. Example of how it wont work would be Gartley's example (no offence here mate honestly but just an example) which is where you force a default value to be changed but then when the game starts, it's overwritten due to the server settings kicking in.
Braindead's example = after initialisation.
Gartley's example = before initialisation.

I hope this has helpped you as it has shown me how much I have actually learnt (if all being correct). If anyone sees any problems with what I said, please comment as I could learn something from it too (if I was incorrect etc).
__________________

Reply With Quote
  #11  
Old 07-14-2012, 07:06 AM
Vallo Vallo is offline
Junior Member
 
Join Date: Jul 2012
Posts: 6
Default

Yeah, that helps a lot thanks. I think I was getting Pawn, xPawn and ThePawn confused and I couldn't work out why it was checking if it was itself but everything is cleared up now at least until I get onto key binds.
Reply With Quote
  #12  
Old 07-14-2012, 07:55 AM
Phada's Avatar
Phada Phada is offline
Senior Member
 
Join Date: Aug 2010
Location: France
Posts: 190
Default

My advice: does something else than trying to control the player speed as your first mutator in KF.
Because the player speed is constantly updated depending on the current weight and health.
In short, this is far more complex than you think.
Reply With Quote
  #13  
Old 07-14-2012, 11:27 AM
FluX FluX is offline
Senior Member
 
Join Date: Oct 2010
Posts: 3,729
Default

Quote:
Originally Posted by Phada View Post
My advice: does something else than trying to control the player speed as your first mutator in KF.
Because the player speed is constantly updated depending on the current weight and health.
In short, this is far more complex than you think.
Depends on how you implement it.
__________________

Reply With Quote
  #14  
Old 07-14-2012, 11:21 PM
Vallo Vallo is offline
Junior Member
 
Join Date: Jul 2012
Posts: 6
Default

Quote:
Originally Posted by Phada View Post
My advice: does something else than trying to control the player speed as your first mutator in KF.
Because the player speed is constantly updated depending on the current weight and health.
In short, this is far more complex than you think.
I agree that it is far more complicated to implement than I first thought, but from what I can tell I am adjusting the speed before the weight and health calculations are done so they still work relative to the speed.

This thread has taught me a lot and I am kind of glad I made the mistake of choosing something more complicated than I thought. I've learned things tutorials and the wiki couldn't get through my thick head.

Thanks for your concern
Reply With Quote
  #15  
Old 07-25-2012, 06:29 AM
Vallo Vallo is offline
Junior Member
 
Join Date: Jul 2012
Posts: 6
Default

Hey guys I'm a bit stuck so if you could help me with any of this it would be appreciated.

Code:
Class SprintBind extends Interaction;

 
Function Initialize()
{
	//Log("Interaction Initialized");
}

function bool KeyEvent(EInputKey Key, EInputAction Action, FLOAT Delta )
{
	local KFHumanPawn Player;

	if ((Action == IST_Press) && (Key == IK_PageUp)) { //checks for keypress
		ViewportOwner.Actor.ClientMessage("Works" @ Key);
                
	
	        ForEach DynamicActors(class 'KFHumanPawn', Player)
	        {
                      Player.default.GroundSpeed = 700.0; //high to make sure I just wasn't noticing the increase
	        }
	}
 
	return false;
}

 
DefaultProperties
{
     bActive=True
}
When I tested the interaction it can read and tell me what key I'm pressing but when I try to get something to react to the 'Shift' key it won't work. It works fine with the PageUp key which was on the tutorial though so I have no idea why it would work for one key and not the other.

I get an error when I try to compile and it says the ForEach need an iterator or something and from what I can tell it wants something like, ForEach something.DynamicActors but I have no idea what to put or even if I'm going about it the right way.

Thanks in advance if you can help in any way
Reply With Quote
  #16  
Old 07-25-2012, 03:49 PM
scary ghost's Avatar
scary ghost scary ghost is offline
Senior Member
 
Join Date: Sep 2010
Location: California
Posts: 779
Default

Interactions are bound to each controller, which in turns gives you access to the pawn, and are handled client side. There's no need to use foreach KFHumanPawn. Using the ViewportOwner.Actor variable gives you access to the PlayerController class of the interaction owner, which in turn gives you access to the Pawn the interaction is bound to.

Last edited by scary ghost; 07-25-2012 at 03:50 PM.
Reply With Quote
  #17  
Old 07-29-2012, 07:42 AM
Vallo Vallo is offline
Junior Member
 
Join Date: Jul 2012
Posts: 6
Default

Thanks, I made the mistake of assuming that ViewportOwner.Actor was just used to show the text so I never looked into it. Anyway it's working perfectly now, I just need to restrict certain things and then it's good to go.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:20 PM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2005 - 2013, Tripwire Interactive, LLC