PDA

View Full Version : trying to write a simple sprint mutator



Aksen
12-04-2007, 04:37 PM
I plan to extend this after i get it working. It compiles with no errors (first time i got it on first try, yay!) but it doesn't work. What am I doing wrong?

I went to my config ini's and bound leftshift to SetSprint.



Class SimpleSprint extends UTMutator;

function ModifyPlayer(Pawn Other)
{
local UTPawn P;

P = UTPawn(Other);
if (P != None)
{

var bool P.bSprinting; // whether pawn is currently sprinting
var() bool P.bCanSprint; // does pawn have the ability to run fast?
var() float P.SprintRatio; // how much faster sprinting speed is over the ground speed

function P.SetSprint( bool bEnabled )
{
if( P.bCanSprint && (P.bSprinting != bEnabled) )
{
else
P.bSprinting = bEnabled;
if( bSprinting )
P.GroundSpeed = default.GroundSpeed * P.SprintRatio;
else
P.GroundSpeed = default.GroundSpeed;
}
}
P.SprintRatio=1.7;
P.bStopOnDoubleLanding=False;
P.bCanSprint=True
}
Super.ModifyPlayer(Other);
}

defaultproperties
{
bExportMenuData=False
GroupNames(0)="SimpleSprint"
Begin Object Name=Sprite ObjName=Sprite Archetype=SpriteComponent'UTGame.Default__UTMutato r:Sprite'
ObjectArchetype=SpriteComponent'UTGame.Default__UT Mutator:Sprite'
End Object
Components(0)=Sprite
Name="Sprint"
ObjectArchetype=UTMutator'UTGame.Default__UTMutato r'
}

Xyx
12-04-2007, 05:14 PM
Wow, does that compile? If so, uscript changed more than I heard. Can you declare new vars and functions inside an object? That'd be very interesting. And scary.

Or... perhaps you didn't get any compile errors because you're not compiling correctly...

Aksen
12-04-2007, 07:55 PM
Wow, does that compile? If so, uscript changed more than I heard. Can you declare new vars and functions inside an object? That'd be very interesting. And scary.

Or... perhaps you didn't get any compile errors because you're not compiling correctly...


bless me, i don't know what i'm doing. but it compiled! .......... after looking again :( nope, i were doin it rong.


I have a few questions.

1.) what's the proper way to add this function? I'd like to peruse a similar mutator but i can't find one.

2.) Extending UTPawn is the only way I know to do this. I've heard it's bad practice in a mutator. Is it okay in this case?

3.) I would make two files. Is this correct:
SimpleSprint\Classes\SimpleSprint.uc &
SimpleSprint\Classes\SimpleSprintPawn.uc

Dark[NSF]
12-04-2007, 09:49 PM
yikes, i really hope that didn't compile. i will not bless you but i will help with direction.

Take a look at this:
http://wiki.beyondunreal.com/wiki/MutTutorial

UT2004Addict
12-04-2007, 10:27 PM
Well, here's what I did back in UT2004 to make a xPawn faster:


function SetBoostedPawn(xPawn XP)
{

if (XP == none)
{
Destroy();
return;
}

BoostedPawn = XP;

if (BoostedPawn.Controller != none)
BoostedController = BoostedPawn.Controller;

// Give all the proper boosts
BoostedPawn.AirControl = FMax(BoostedPawn.default.AirControl * BoostAmount, BoostedPawn.AirControl);
BoostedPawn.GroundSpeed = FMax(BoostedPawn.default.GroundSpeed * BoostAmount, BoostedPawn.GroundSpeed);
BoostedPawn.WaterSpeed = FMax(BoostedPawn.default.WaterSpeed * BoostAmount, BoostedPawn.WaterSpeed);
BoostedPawn.AirSpeed = FMax(BoostedPawn.default.AirSpeed * BoostAmount, BoostedPawn.AirSpeed);
BoostedPawn.JumpZ = FMax(BoostedPawn.default.JumpZ * BoostAmount, BoostedPawn.JumpZ);

}


This was handled by a separate Actor, which de-activated all this stuff and destroyed itself when the time was up.

Xyx has had a lot of success with making such actors a member of a Pawn's Inventory. I always thought there was a danger in that, since a Pawn's inventory can be discarded by other operations, hence destroying the powerup or penalty -- but Xyx is way better at this stuff than me, so he's probably got the right idea. :)

Aksen
12-04-2007, 11:02 PM
Thanks guys, this is a lot of help.

To be clear, my goal is pretty simple. Holding shift would multiply groundspeed by 1.7.

ElShotte
04-30-2008, 01:32 PM
That does not compile for me man, you sure about that? Gives an error on line 11 "var not allowed here"

ambershee
04-30-2008, 03:01 PM
Make it an exec function, then you can bind it to a key.

There's no point trying to make it a mutator, because GameSpy will over-write that key binding at some point anyway; and as you said, you shouldn't subclass UTPawn in a mutator :)

k0sm0s
05-01-2008, 02:06 PM
Elshotte, look at the date..

i really like the first example :D a function inside a function

ElShotte
05-01-2008, 04:22 PM
Yeah yeah I saw it ;)