View Single Post
Mr. Zero
Veteran Member
Join Date: Jun 2009
Location: Denmark
Old 08-21-2014 , 10:54   Re: [L4D2]Get/set player health?
Reply With Quote #5

PHP Code:
/**
 * Returns player temporarily health.
 *
 * Note: This will not work with mutations or campaigns that alters the decay
 * rate through vscript'ing. If you want to be sure that it works no matter
 * the mutation, you will have to detour the OnGetScriptValueFloat function.
 * Doing so you are able to capture the altered decay rate and calulate the
 * temp health the same way as this function does.
 *
 * @param client        Client index.
 * @return              Player's temporarily health, -1 if unable to get.
 * @error               Invalid client index or unable to find
 *                      pain_pills_decay_rate cvar.
 */
stock L4D_GetPlayerTempHealth(client)
{
    static 
Handle:painPillsDecayCvar INVALID_HANDLE;
    if (
painPillsDecayCvar == INVALID_HANDLE)
    {
        
painPillsDecayCvar FindConVar("pain_pills_decay_rate");
        if (
painPillsDecayCvar == INVALID_HANDLE)
        {
            return -
1;
        }
    }

    new 
tempHealth RoundToCeil(GetEntPropFloat(clientProp_Send"m_healthBuffer") - ((GetGameTime() - GetEntPropFloat(clientProp_Send"m_healthBufferTime")) * GetConVarFloat(painPillsDecayCvar))) - 1;
    return 
tempHealth tempHealth;

PHP Code:
/**
 * Returns whether player is incapacitated.
 *
 * Note: A tank player will return true when in dying animation.
 *
 * @param client        Player index.
 * @return              True if incapacitated, false otherwise.
 * @error               Invalid client index.
 */
stock bool:L4D_IsPlayerIncapacitated(client)
{
    return 
bool:GetEntProp(clientProp_Send"m_isIncapacitated"1);

More various L4D stock functions can be found here.
Mr. Zero is offline