A while back I wrote a small plugin to tell me everyone's HP.
This post had the formula; changing it around a bit comes up with:
(I noticed that a lot of this was unnecessary, particularly because I completely missed that I was doing hp + (time / decay) - (time / decay). Time and decay aren't needed when setting that value.)
PHP Code:
SetTempHealth(client, hp)
{
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", GetGameTime());
/*
new Float:decay = GetConVarFloat(FindConVar("pain_pills_decay_rate"));
new Float:time =
(GetEntPropFloat(client, Prop_Send, "m_healthBufferTime") -
GetGameTime()) * -1;
new Float:newBuf = hp + (time / decay);
new Float:newOverheal = newBuf - (time / decay);
*/
new Float:newOverheal = hp * 1.0;
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", newOverheal);
}
To test:
PHP Code:
RegConsoleCmd("sm_tmp", Command_SetTemp, "sm_tmp [new hp] - Sets your temp health. Get rid of me before trying this in a real game");
//...
public Action:Command_SetTemp(client, args)
{
decl String:arg[8];
GetCmdArg(1, arg, sizeof(arg));
new hp = StringToInt(arg);
SetTempHealth(client, hp);
return Plugin_Handled;
}