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 online now
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-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
  #9  
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
  #10  
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 02:05 PM.


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