|
Junior Member
|
06-19-2019
, 11:01
Re: Hello I need help on TF2 Health
|
#5
|
Quote:
Originally Posted by CrazyHackGUT
TF2 Attributes, for example, can give you ability increase max health.
Attribute with name "max health additive bonus", or index 26.
|
Quote:
Originally Posted by CrazyHackGUT
You can get current max health, and with this information, add required "bonus health points".
From one my plugin.
Gamedata:
Code:
"Games"
{
"tf"
{
"Offsets"
{
"CTFPlayer::GetMaxHealth"
{
"windows" "117"
"linux" "118"
}
"CTFPlayer::GetAmmoCount"
{
"windows" "258"
"linux" "259"
}
}
}
}
Sourcecode:
Code:
#include <sourcemod>
#include <tf2_stocks>
#pragma semicolon 1
#pragma newdecls required
Handle g_fnGetMaxHealth;
public APLRes AskPluginLoad2(Handle hMySelf, bool bLate, char[] szError, int iErrMax) {
if(GetEngineVersion() != Engine_TF2) {
Format(szError, iErrMax, "This plugin only works for Team Fortress 2");
return APLRes_Failure;
}
return APLRes_Success;
}
public void OnPluginStart() {
// Load SDK configuration.
Handle hConf = LoadGameConfigFile("TF2_UTILs");
if (!hConf) {
__FuckMe(0);
}
// Initialize SDK function (GetMaxHealth).
StartPrepSDKCall(SDKCall_Player);
if (!PrepSDKCall_SetFromConf(hConf, SDKConf_Virtual, "CTFPlayer::GetMaxHealth") || !PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain)) {
CloseHandle(hConf);
__FuckMe(1);
}
// Get function pointer.
g_fnGetMaxHealth = EndPrepSDKCall();
if (!g_fnGetMaxHealth) {
CloseHandle(hConf);
__FuckMe(1);
}
}
void __FuckMe(int iReason) {
char szReason[128];
switch (iReason) {
case 0: strcopy(szReason, sizeof(szReason), "Can't load gamedata file TF2_UTILs.");
case 1: strcopy(szReason, sizeof(szReason), "Can't create SDKCall function for CTFPlayer::GetMaxHealth. Gamedata is incorrect.");
}
SetFailState("Can't finish initializing: %s", szReason);
}
/**
* UTILs
*/
int UTIL_GetMaxHealth(int iClient) {
return SDKCall(g_fnGetMaxHealth, iClient);
}
Just call UTIL_GetMaxHealth() with passing client index returns max player health with respecting all attributes.
I can't guarantee in "freshness" gamedata. I wrote this code (and retrieved gamedata too) in december 2018. Maybe something changed. You can check "freshness" manually here.
|
Thank You!
|
|
|
|