Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Sprint limit or none?
DnALANGE Offline
Banned

Posts: 1,549
Threads: 73
Joined: Jan 2012
#7
RE: Sprint limit or none?

Here is a script function;
Put this OnStart \ OnEnter.
PHP Code: (Select All)
stamina_obj.Start(); 
PHP Code: (Select All)
//////////////////////////// Running breath ///////////////////////////

const string STAMINA_TIMER_CALLBACK_NAME "STAMINA_TIMER_CALLBACK";
const 
string STAMINA_PLAYER_SPEED "STAMINA_PLAYER_SPEED";
const 
string STAMINA_PLAYER_LENGTH "STAMINA_PLAYER_LENGTH";
const 
string STAMINA_PLAYER_BREATH_SLOW "STAMINA_PLAYER_BREATH_SLOW";
const 
string STAMINA_PLAYER_BREATH_SNT "react_breath_slow.snt";
const 
string STAMINA_PLAYER_HEAD_BOB "STAMINA_PLAYER_HEAD_BOB";

const 
float STAMINA_TIMER_SPEED_TIME 0.5f;
const 
float STAMINA_PLAYER_HEAD_BOB_SPEED 0.7f;

enum StaminaStages
    
{
        
Full,
        
Low,
        
Exhausted
    
}

class 
StaminaSystem
    
{
        private 
int state;
        private 
uint length;
        private 
bool head_bobbing;
        private 
bool is_running;

        
StaminaSystem()
            {
                
PreloadSound(STAMINA_PLAYER_BREATH_SNT);
                
this.state StaminaStages::Full;
                
this.length 15;
                
this.head_bobbing false;
                
this.is_running false;
            }

        ~
StaminaSystem()
            {
                
this.Stop();
            }

        
void AddDebugMessage(string &in messagebool checkbool to_file)
            {
                ::
AddDebugMessage("Stamina system: " messagecheck);
                if (
to_file) Print("Stamina system: " message);
            }

        
bool IsPlayerRunning() const
            {
                return 
this.is_running;
            }

        
void PlayBreathSound()
            {
                
PlaySoundAtEntity(STAMINA_PLAYER_BREATH_SLOWSTAMINA_PLAYER_BREATH_SNT"Player"0false);
                
FadeImageTrailTo(5,1);
            }

        
void Start()
            {
                
SetPlayerRunSpeedMul(1);
                
SetPlayerMoveSpeedMul(1);
                
AddTimer(STAMINA_PLAYER_SPEEDSTAMINA_TIMER_SPEED_TIMESTAMINA_TIMER_CALLBACK_NAME);
            }

        
void StartPlayerHeadBob()
            {
                if (
this.head_bobbing)
                    
MovePlayerHeadPos(0, -0.350STAMINA_PLAYER_HEAD_BOB_SPEED0.6);
                else
                    
MovePlayerHeadPos(000STAMINA_PLAYER_HEAD_BOB_SPEED0.6);

                
this.head_bobbing = !this.head_bobbing;
                
AddTimer(STAMINA_PLAYER_HEAD_BOB0.75fSTAMINA_TIMER_CALLBACK_NAME);
            }

        
void StartPlayerTiredEffect()
            {
                
this.PlayBreathSound();
                
AddTimer(STAMINA_PLAYER_BREATH_SLOW1.5fSTAMINA_TIMER_CALLBACK_NAME);
                
FadeImageTrailTo(5,1);
            }

        
void Stop()
            {
                
this.StopPlayerTiredEffect();
                
RemoveTimer(STAMINA_PLAYER_SPEED);
                
RemoveTimer(STAMINA_PLAYER_LENGTH);
                
SetPlayerRunSpeedMul(1);
                
SetPlayerMoveSpeedMul(1);
                
SetPlayerJumpDisabled(false);
                 
FadeImageTrailTo(0,1);
            }

        
void StopPlayerTiredEffect()
            {
                
this.head_bobbing false;
                
RemoveTimer(STAMINA_PLAYER_BREATH_SLOW);
                
RemoveTimer(STAMINA_PLAYER_HEAD_BOB);
                
MovePlayerHeadPos(0,0,011);
                 
FadeImageTrailTo(0,1);
                
// StopSound(STAMINA_PLAYER_BREATH_SLOW, 1); // Crashes the game upon exit.
            
}

        
void SetStaminaLength(uint length)
            {
                if (
length != 0)
                    
this.length length;
                else
                    
this.AddDebugMessage("Length cannot be 0!"falsetrue);
            }

        
void Update(string &in timer_name)
            {
                if (
timer_name == STAMINA_PLAYER_SPEED)
                {
                    
this.is_running = (GetPlayerSpeed() > 3) ? true false;

                    if (
this.is_running && GetTimerTimeLeft(STAMINA_PLAYER_LENGTH) == 0)
                        
AddTimer(STAMINA_PLAYER_LENGTHthis.lengthSTAMINA_TIMER_CALLBACK_NAME);

                    else if(!
this.is_running)
                    {
                        if (
GetTimerTimeLeft(STAMINA_PLAYER_LENGTH) > && this.state == StaminaStages::Full)
                            
RemoveTimer(STAMINA_PLAYER_LENGTH);

                        else if(
this.state == StaminaStages::Low)
                            
AddTimer(STAMINA_PLAYER_LENGTHthis.length/4STAMINA_TIMER_CALLBACK_NAME);

                        else if(
this.state == StaminaStages::Exhausted)
                            
AddTimer(STAMINA_PLAYER_LENGTHthis.length/7STAMINA_TIMER_CALLBACK_NAME);
                    }

                    
AddTimer(timer_nameSTAMINA_TIMER_SPEED_TIMESTAMINA_TIMER_CALLBACK_NAME);
                }

                else if (
timer_name == STAMINA_PLAYER_BREATH_SLOW)
                    
this.StartPlayerTiredEffect();

                else if (
timer_name == STAMINA_PLAYER_HEAD_BOB)
                    
this.StartPlayerHeadBob();

                else if (
timer_name == STAMINA_PLAYER_LENGTH)
                {
                    if (
this.is_running)
                    {
                        if (
this.state == StaminaStages::Full)
                        {
                            
this.state++;
                            
SetPlayerRunSpeedMul(0.3);
                        }

                        else if (
this.state == StaminaStages::Low)
                        {
                            
this.state++;
                            
SetPlayerRunSpeedMul(0);
                            
SetPlayerMoveSpeedMul(0);
                            
SetPlayerJumpDisabled(true);
                            
this.StartPlayerTiredEffect();
                            
this.StartPlayerHeadBob();
                            
FadeImageTrailTo(5,1);
                        }
                    }

                    else
                    {
                        
this.StopPlayerTiredEffect();

                        
SetPlayerRunSpeedMul(1);
                        
SetPlayerMoveSpeedMul(1);
                        
SetPlayerJumpDisabled(false);
                         
FadeImageTrailTo(0,1);

                        if (
this.state == StaminaStages::Low)
                            
this.state StaminaStages::Full;

                        else if (
this.state == StaminaStages::Exhausted)
                            
this.state StaminaStages::Full;
}
}
}
}

StaminaSystem stamina_obj;

void STAMINA_TIMER_CALLBACK(string &in timer_name)
    {
    
stamina_obj.Update(timer_name);
    } 

//////////////////////////// Running breath End /////////////////////////// 
---
Credits goes to : Your Computer
Here is the tread ; http://www.frictionalgames.com/forum/thread-16949.html
(This post was last modified: 05-05-2014, 10:22 AM by DnALANGE.)
05-05-2014, 10:19 AM
Find


Messages In This Thread
Sprint limit or none? - by Froge - 05-05-2014, 03:52 AM
RE: Sprint limit or none? - by 7heDubz - 05-05-2014, 04:15 AM
RE: Sprint limit or none? - by FlawlessHappiness - 05-05-2014, 07:20 AM
RE: Sprint limit or none? - by Streetboat - 05-05-2014, 07:27 AM
RE: Sprint limit or none? - by 7heDubz - 05-05-2014, 07:40 AM
RE: Sprint limit or none? - by Kurton - 05-05-2014, 08:00 AM
RE: Sprint limit or none? - by DnALANGE - 05-05-2014, 10:19 AM
RE: Sprint limit or none? - by Romulator - 05-05-2014, 11:47 AM



Users browsing this thread: 1 Guest(s)