![]() |
![]() |
|
#1
|
|||
|
|||
|
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"
}
|
|
#2
|
||||
|
||||
|
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?!" |
|
#3
|
||||
|
||||
|
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.
|
|
#4
|
||||
|
||||
|
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
}
__________________
Whisky's Workshop ![]() "As you can see here, I'm -ALL ON MY F***ING OWN! Guys where the hell are you?!" |
|
#5
|
||||
|
||||
|
Quote:
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"
}
|
|
#6
|
||||
|
||||
|
Quote:
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. |
|
#7
|
||||
|
||||
|
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?!" |
|
#8
|
||||
|
||||
|
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.
__________________
|
|
#9
|
|||
|
|||
|
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
|
|
#10
|
|||
|
|||
|
Quote:
1.) 'Other' is referenced in the function itself as a parameter. Code:
ModifyPlayer(Pawn Other) 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). |
|
#11
|
|||
|
|||
|
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.
|
|
#12
|
||||
|
||||
|
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. |
|
#13
|
|||
|
|||
|
Depends on how you implement it.
|
|
#14
|
|||
|
|||
|
Quote:
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
|
|
#15
|
|||
|
|||
|
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
}
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 |
|
#16
|
||||
|
||||
|
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. |
|
#17
|
|||
|
|||
|
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.
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|