In order to set the attribute, go into your install folder, then open up "Player.ini", and simply add the attribute in there. For using a speed attribute, you don't want the lowest amount of your attribute to be 0, because then your player won't move at all unless his/her attribute is increased. The best way to define your speed attribute looks a little something like this:
Code: Select all
[speed]
initial=20
low=20
high=100
This will ensure that your attribute won't decrease below 20, which will therefore be your players starting speed. 100 will be the max speed that your player will eventually run at. In terms of the code, to explain it to you would be quite a lengthy process. I would suggest that you play around with the GenericPlayer example script. Thats how i learnt the basics of coding. You can add this segment of code to that script under the RunPlayer[() order.
This portion of code is already in the RunPlayer[() order and is the command which tells your pawn to walk forward. All I have changed is hilighted in red.
Code: Select all
if(IsKeyDown(K_FOR))
{
ANIM=StringCopy(WALKANIM); ///Predifined animation for walking.
ANC=2;
[color=#FF0000]SPEED=Integer(GetAttribute("speed","Player")/1.5)[/color]
}
Basically I have added the GetAttribute command to the SPEED=Integer command. GetAttribute returns the amount of the specified attribute (in this case, "speed"), therefore telling the pawn that his speed is whatever the attribute "speed" is.
You will need to add the second portion of code:
Code: Select all
if(IsKeyDown(K_FOR))
{
if(run_time < time)
{
if(random(1,10)>7)
{
ModifyAttribute("speed",1,"Player");
run_time = time + [color=#FF0000]0.5[/color];
}
}
}
Directly under the first portion. Basically what this does is modify the attribute "speed" by 1 unit every 0.5 seconds that you've been holding down the walk button. You can increase/decrease the amount of time it takes to pick up speed by changing the numeric highlighted in red.
I forgot to add this in my previous response, but you will also need to add this under the first two portions of code:
Code: Select all
if(IsKeyDown(K_FOR)=false)
{
ModifyAttribute("speed",-100,"Player");
}
This will return your speed back to normal once you release the forward key.
Hope this helps with your learning. Once you gain an understanding of coding, RF is pretty much limitless!
A good warrior knows his limits, but a great warrior finds his way around them.