hey im still new to unrealscript and i am having a difficult time getting this stamina regen to work and show in the HUD. can someone guide me to where is the problem.
class StaminaPawn extends UTPawn;
//Variables for movement speed
var const float WalkSpeed;
var const float SprintSpeed;
//Variables for controlling and displaying Stamina
var float Stamina;//log(stamina) var const float MaxStamina; var array<string> StaminaMsgArray; var string StaminaMsg;//
log(stamina)
//Variables for how stamina is affected by different activities
var const float StamRegenRate;
var const float StamWalkRegenRate;
var const float StamRunPenalty;
var const float StamJumpPenalty;
enum E_MoveState
{
EMS_Idle,
EMS_Walking,
EMS_Running,
EMS_Jumping,
};
var E_MoveState move_state;
simulated function PostBeginPlay()
{
super.PostBeginPlay();
Stamina = MaxStamina;
}
exec function StartSprint()
{
PlayerController(Controller).bRun = 0x01;
}
exec function StopSprint()
{
PlayerController(Controller).bRun = 0x00;
}
function bool DoJump( bool bUpdating )
{
if (Stamina - StamJumpPenalty > 0 && super.DoJump(bUpdating))
{
Stamina -= StamJumpPenalty;
return true;
}
return false;
}
function CalculateStamina(float DeltaTime)
{
//if player controller is walking, take away from stamina
if(move_state == EMS_Walking)
{
Stamina -= Stamina + DeltaTime * StamWalkRegenRate;
}
//if player controller is jumping, take away from stamina
if(move_state == EMS_Jumping)
{
Stamina -= DeltaTime * StamJumpPenalty;
}
//If player controller is running, take away from stamina.
if (move_state == EMS_Running)
{
Stamina -= DeltaTime * StamRunPenalty;
}
//If player is running and stamina reaches zero, stop them from running
if (Stamina <= 0.0 && move_state == EMS_Running)
{
StopSprint();
}
//If player not moving, regenerate stamina at full speed
if (move_state == EMS_Idle)
{
Stamina = Stamina + DeltaTime * StamRegenRate;
}
//Cap the stamina to MaxStamina, when regenerating
if(Stamina < MaxStamina)
{
Stamina = MaxStamina;// `log(Stamina)
}
//stamina value
if(Stamina >= 0 && Stamina < 25)
{
StaminaMsg = StaminaMsgArray[1];
}
if(Stamina >= 25 && Stamina < 50)
{
StaminaMsg = StaminaMsgArray[2];
}
if(Stamina >= 50 && Stamina < 75)
{
StaminaMsg = StaminaMsgArray[3];
}
if(Stamina >= 75 && Stamina <= 100)
{
StaminaMsg = StaminaMsgArray[4];
}
}
/**
-
Small function to affect speed depending on if the player is running or not.
*/
function CalculateSpeed()
{
local PlayerController PC;
PC = PlayerController(Controller);
GroundSpeed = WalkSpeed;{
GroundSpeed = SprintSpeed;
}
}
event Tick(float DeltaTime)
{
local PlayerController PC;
local bool moving;
super.Tick(DeltaTime);
//Work out how player moving, store in a variable for convenience, this is used in "CalculateStamina"
PC = PlayerController(Controller);
move_state = EMS_Idle;
moving = Physics == PHYS_Walking && (VSize(Velocity * vect(1,1,0)) > (WalkSpeed/2));
if(moving && PC.bRun == 0x00)
{
move_state = EMS_Walking;
}
if(moving && PC.bRun > 0x00)
{
move_state = EMS_Running;
}
// `log(“Movement:”@move_state);
//If we're not dead, calculate the stamina, and affect the player's speed.
if (Health > 0)
{
CalculateStamina(DeltaTime); // `log(CalculateStamina(DeltaTime);
CalculateSpeed();
}
}
/**
-
Default values for all the class variables
*/
DefaultProperties
{
MaxStamina=100WalkSpeed=140
SprintSpeed=480StamRegenRate=10.0
StamWalkRegenRate=5.0
StamRunPenalty=10.0
StamJumpPenalty=20.0StaminaMsgArray=(“Exhausted”, “Tired”, “Puffed”, “Fully rested”)
}