Raised This Month: $12 Target: $400
 3% 

[STOCK][L4D2] Get entire survivors health (including temp health)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
honorcode23
BANNED
Join Date: Mar 2010
Location: Chile
Old 12-07-2010 , 21:05   [STOCK][L4D2] Get entire survivors health (including temp health)
Reply With Quote #1

I was playing around with the values and found out a method to get the exact amount of health a survivor has, including the temporal health too. Here's the stock, but i also added explanation in case anybody wanted to know.

Note: I dunno if this has been done yet, but i just want to share it with you.

PHP Code:
/**
* @brief Will return a survivors health, including also the temporal health.
*
* @client            Client index to retrieve the health from.
*
* @return            Returns the client's health as an integer.
* @error             Will return -1 if there was any problem.
*/
stock GetClientRealHealth(client)
{
    
//First filter -> Must be a valid client, successfully in-game and not an spectator (The dont have health).
    
if(!client
    
|| !IsValidEntity(client)
    || !
IsClientInGame(client)
    || !
IsPlayerAlive(client)
    || 
IsClientObserver(client))
    {
        return -
1;
    }
    
    
//If the client is not on the survivors team, then just return the normal client health.
    
if(GetClientTeam(client) != 2)
    {
        return 
GetClientHealth(client);
    }
    
    
//First, we get the amount of temporal health the client has
    
new Float:buffer GetEntPropFloat(clientProp_Send"m_healthBuffer");
    
    
//We declare the permanent and temporal health variables
    
new Float:TempHealth;
    new 
PermHealth GetClientHealth(client);
    
    
//In case the buffer is 0 or less, we set the temporal health as 0, because the client has not used any pills or adrenaline yet
    
if(buffer <= 0.0)
    {
        
TempHealth 0.0;
    }
    
    
//In case it is higher than 0, we proceed to calculate the temporl health
    
else
    {
        
//This is the difference between the time we used the temporal item, and the current time
        
new Float:difference GetGameTime() - GetEntPropFloat(clientProp_Send"m_healthBufferTime");
        
        
//We get the decay rate from this convar (Note: Adrenaline uses this value)
        
new Float:decay GetConVarFloat(FindConVar("pain_pills_decay_rate"));
        
        
//This is a constant we create to determine the amount of health. This is the amount of time it has to pass
        //before 1 Temporal HP is consumed.
        
new Float:constant 1.0/decay;
        
        
//Then we do the calcs
        
TempHealth buffer - (difference constant);
    }
    
    
//If the temporal health resulted less than 0, then it is just 0.
    
if(TempHealth 0.0)
    {
        
TempHealth 0.0;
    }
    
    
//Return the value
    
return RoundToFloor(PermHealth TempHealth);


Last edited by honorcode23; 12-07-2010 at 21:10.
honorcode23 is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 12-08-2010 , 03:48   Re: [STOCK][L4D2] Get entire survivors health (including temp health)
Reply With Quote #2

It's temporary, not temporal.
__________________
FaTony is offline
dirka_dirka
Veteran Member
Join Date: Nov 2009
Old 12-11-2010 , 14:54   Re: [STOCK][L4D2] Get entire survivors health (including temp health)
Reply With Quote #3

or temporl

its been done in some plugins, but never posted as a stock as far as i know.
dirka_dirka is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:11.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode