Thread: [Request] health of player

Results 1 to 9 of 9
  1. #1
    warrior spy-warrior's Avatar  
    Contributor
    Join Date
    Nov 2006
    Location
    Europe, France, Paris
    Posts
    2,960

    [Request] health of player

    hello,

    search script, health of player:
    Informed the player on his health.
    The player can not runing with -49 HP
    The player to the HUD flashing(red) with -24 HP

    thanks
    Patience is a virtue greatly needed by those who attempt great things.
    La patience est une vertu fort nécessaire à ceux qui tentent de réaliser de grandes choses.

    Server SvenCoop
    I love the mods svencoop
    World time zone & Look clocks

  2. #2
    Giegue
    Join Date
    Oct 2013
    Location
    Argentina
    Posts
    92

    Re: [Request] health of player

    (Broken english confuses me, sorry!)

    Here, let me know if it works:

    Code:
    // HUD Parameters
    HUDTextParams h_Parameters;
    
    // Player should be unable to run when it's health is below THIS percentage
    const float PERCENT_HP_DANGER = 50.0;
    
    // Player's HUD should be flashing when it's health is below THIS percentage
    const float PERCENT_HP_CRITICAL = 25.0;
    
    // How much should we slow down the player when it's HP is on danger? (Again, percentage)
    const float PERCENT_SLOWDOWN = 50.0;
    
    void PluginInit()
    {
       // Register script information
       g_Module.ScriptInfo.SetAuthor( "Julian \"Giegue\" Rodriguez" );
       g_Module.ScriptInfo.SetContactInfo( "www.steamcommunity.com/id/ngiegue" );
       
       // Set up parameters for HUD
       
       // These may look bad depending on player's screen resolution
       // Fell free to change the parameters
       h_Parameters.x = 0.02; // X
       h_Parameters.y = 0.90; // Y
       
       h_Parameters.a1 = 0; // Opaque HUD?
       
       h_Parameters.r2 = 250; // White color for flashing
       h_Parameters.g2 = 250;
       h_Parameters.b2 = 250;
       h_Parameters.a2 = 1; // White flash should be opaque ?
       
       h_Parameters.fadeinTime = 0.0;
       h_Parameters.fadeoutTime = 0.0;
       h_Parameters.holdTime = 60.0;
       h_Parameters.fxTime = 0.0;
       
       // HACKHACK - Prevent HUD message from being overlapped by using mapper's game_text channels (Channels 5-8)
       h_Parameters.channel = 8;
       
       // Check player's health every 0.75 seconds
       g_Scheduler.SetInterval( "CheckHealth", 0.75, g_Scheduler.REPEAT_INFINITE_TIMES );
    }
    
    // Health handler
    void CheckHealth()
    {
       // Loop through all indexes
       for ( int i = 1; i <= g_Engine.maxClients; i++ )
       {
          // Get player
          CBasePlayer@ pPlayer = g_PlayerFuncs.FindPlayerByIndex( i );
          
          // Check if player is valid (and connected)
          if ( pPlayer !is null && pPlayer.IsConnected() )
          {
             // Get necessary data
             float flHealth = pPlayer.pev.health;
             float flMaxHealth = pPlayer.pev.max_health;
             float flDanger = flMaxHealth * PERCENT_HP_DANGER / 100.0;
             float flCritical = flMaxHealth * PERCENT_HP_CRITICAL / 100.0;
             float flMaxSpeed = g_EngineFuncs.CVarGetFloat( "sv_maxspeed" );
             float flSlowSpeed = flMaxSpeed * PERCENT_SLOWDOWN / 100.0;
             
             // Player's health is at critical level?
             if ( flHealth < flCritical )
             {
                // At danger level, slow down the player
                pPlayer.pev.maxspeed = flSlowSpeed;
                
                // Red color for HUD
                h_Parameters.r1 = 250;
                h_Parameters.g1 = 10;
                h_Parameters.b1 = 10;
                h_Parameters.effect = 1; // Flash HUD
                
                // Print player health
                g_PlayerFuncs.HudMessage( pPlayer, h_Parameters, "Health: " + flHealth );
             }
             else if ( flHealth < flDanger ) // At danger level?
             {
                // At danger level, slow down the player
                pPlayer.pev.maxspeed = flSlowSpeed;
                
                // Yellow color for HUD
                h_Parameters.r1 = 250;
                h_Parameters.g1 = 250;
                h_Parameters.b1 = 10;
                h_Parameters.effect = 0; // No effect
                
                // Print player health
                g_PlayerFuncs.HudMessage( pPlayer, h_Parameters, "Health: " + flHealth );
             }
             else // Player is fine
             {
                // Restore player's speed
                pPlayer.pev.maxspeed = 0.0;
                
                // Green color for HUD
                h_Parameters.r1 = 10;
                h_Parameters.g1 = 250;
                h_Parameters.b1 = 10;
                h_Parameters.effect = 0; // No effect
                
                // Print player health
                g_PlayerFuncs.HudMessage( pPlayer, h_Parameters, "Health: " + flHealth );
             }
          }
       }
    }
    What's a signature?

  3. #3
    warrior spy-warrior's Avatar  
    Contributor
    Join Date
    Nov 2006
    Location
    Europe, France, Paris
    Posts
    2,960

    Re: [Request] health of player

    Quote Originally Posted by Julcoool View Post
    (Broken english confuses me, sorry!)

    Here, let me know if it works:
    Yes, cool

    all hud red/green 25% opaque, not colore text health.

    Thanks

    script tested server:
    [FR] Sven Co-op 5.0 Win, Half-Life
    Patience is a virtue greatly needed by those who attempt great things.
    La patience est une vertu fort nécessaire à ceux qui tentent de réaliser de grandes choses.

    Server SvenCoop
    I love the mods svencoop
    World time zone & Look clocks

  4. #4
    warrior spy-warrior's Avatar  
    Contributor
    Join Date
    Nov 2006
    Location
    Europe, France, Paris
    Posts
    2,960

    Re: [Request] health of player

    Please, Julcoool

    Can you add an updated?
    Pouvez-vous ajouter une mis à jour ?

    The red screen but that is not opaque and with his heart beating.
    L'écran rouge mais, qui ne soit pas opaque et avec un son de coeur qui bat.

    Remove the message when the player is in observer mode.
    Retirez le message lorsque le joueurs est en mode observateur.

    Thanks
    Patience is a virtue greatly needed by those who attempt great things.
    La patience est une vertu fort nécessaire à ceux qui tentent de réaliser de grandes choses.

    Server SvenCoop
    I love the mods svencoop
    World time zone & Look clocks

  5. #5
    QPU-aligned Silencer's Avatar  
    Contributor
    Join Date
    May 2006
    Posts
    6,078

    Re: [Request] health of player

    Quote Originally Posted by Julcoool View Post
    (Broken english confuses me, sorry!)

    Here, let me know if it works

    -code-
    I am honestly impressed at how much sense you were able to make from that.

  6. #6
    warrior spy-warrior's Avatar  
    Contributor
    Join Date
    Nov 2006
    Location
    Europe, France, Paris
    Posts
    2,960

    Re: [Request] health of player

    Is it possible to disable it when the player is dead (observer) ?
    C'est possible de le désactiver quand le joueur est mort (observateur) ?
    Patience is a virtue greatly needed by those who attempt great things.
    La patience est une vertu fort nécessaire à ceux qui tentent de réaliser de grandes choses.

    Server SvenCoop
    I love the mods svencoop
    World time zone & Look clocks

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    190

    Re: [Request] health of player

    Simplest way: add a separate check after all the if/else statements for when health <=0.0 and then reset everything.

    Code:
    if ( flHealth < 0.1 ) // dead
    {
        pPlayer.pev.maxspeed = 0.0; //restore
    }
    Neater way: add to the top of the if/else nest
    Code:
    if ( flHealth < 0.1 ) // dead
    {
        pPlayer.pev.maxspeed = 0.0; //restore
    }
    else if ( flHealth < flCritical )
    ...
    Best way: check for death usermsg and reset speed to normal for that user, as it's not guaranteed or known spectator will retain <=0 health and the check speed might be random/not fast enough to check if so.
    Or
    use the API some easier way as there is likely an easier way to check if they are spectating.
    Last edited by HL2 RULEZ; 01-12-2016 at 09:08 PM.
    BLEH. BLEHEG
    BLEHHEGLAH!!!!!!!!! O.o

  8. #8
    warrior spy-warrior's Avatar  
    Contributor
    Join Date
    Nov 2006
    Location
    Europe, France, Paris
    Posts
    2,960

    Re: [Request] health of player

    hello,
    I did not find or i have to add the code.
    Je n'ai pas trouvé ou je dois ajouter le code.

    This is to find a high speed when you are in observer mode.
    Il s'agit de trouver une vitesse élevée lorsque vous êtes en mode observateur.

    Thanks for help
    Patience is a virtue greatly needed by those who attempt great things.
    La patience est une vertu fort nécessaire à ceux qui tentent de réaliser de grandes choses.

    Server SvenCoop
    I love the mods svencoop
    World time zone & Look clocks

  9. #9
    Super moderator GeckonCZ's Avatar  
    Programmer
    Join Date
    May 2014
    Location
    Great Moravia
    Posts
    262

    Re: [Request] health of player

    You should use pPlayer.IsAlive() rather than just checking if pPlayer.pev.health is less than/equal to zero. That should solve the problems with observer as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •