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

Hello I need help on TF2 Health


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
joel177
Junior Member
Join Date: Aug 2017
Old 06-18-2019 , 15:59   Hello I need help on TF2 Health
Reply With Quote #1

How i get and set the health in sourcepawn Click image for larger version

Name:	A-1.png
Views:	176
Size:	50.0 KB
ID:	176002
but not like that

SetEntityHealth()?

Last edited by joel177; 06-18-2019 at 16:02.
joel177 is offline
CrazyHackGUT
AlliedModders Donor
Join Date: Feb 2016
Location: Izhevsk, Russia
Old 06-18-2019 , 16:09   Re: Hello I need help on TF2 Health
Reply With Quote #2

TF2 Attributes, for example, can give you ability increase max health.
Attribute with name "max health additive bonus", or index 26.
__________________
My english is very bad. I am live in Russia. Learning english language - very hard task for me...
CrazyHackGUT is offline
Send a message via ICQ to CrazyHackGUT Send a message via Skype™ to CrazyHackGUT
joel177
Junior Member
Join Date: Aug 2017
Old 06-19-2019 , 08:43   Re: Hello I need help on TF2 Health
Reply With Quote #3

Quote:
Originally Posted by CrazyHackGUT View Post
TF2 Attributes, for example, can give you ability increase max health.
Attribute with name "max health additive bonus", or index 26.
yes but i dont want to bonus to health i want to change max health
if scout have 125 max health i want to change max health to 300
joel177 is offline
CrazyHackGUT
AlliedModders Donor
Join Date: Feb 2016
Location: Izhevsk, Russia
Old 06-19-2019 , 09:14   Re: Hello I need help on TF2 Health
Reply With Quote #4

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.
__________________
My english is very bad. I am live in Russia. Learning english language - very hard task for me...
CrazyHackGUT is offline
Send a message via ICQ to CrazyHackGUT Send a message via Skype™ to CrazyHackGUT
joel177
Junior Member
Join Date: Aug 2017
Old 06-19-2019 , 11:01   Re: Hello I need help on TF2 Health
Reply With Quote #5

Quote:
Originally Posted by CrazyHackGUT View Post
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 View Post
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!
joel177 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-19-2019 , 16:59   Re: Hello I need help on TF2 Health
Reply With Quote #6

Quote:
Originally Posted by CrazyHackGUT View Post
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.
...or you could just use SDKHooks's SDKHook_GetMaxHealth hook, which works on all epv2 games including TF2 and has its gamedata updated by the AlliedModders staff.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
CrazyHackGUT
AlliedModders Donor
Join Date: Feb 2016
Location: Izhevsk, Russia
Old 06-20-2019 , 04:48   Re: Hello I need help on TF2 Health
Reply With Quote #7

SDKHook_GetMaxHealth doesn't work on me. Windows, SM 1.9.
__________________
My english is very bad. I am live in Russia. Learning english language - very hard task for me...
CrazyHackGUT is offline
Send a message via ICQ to CrazyHackGUT Send a message via Skype™ to CrazyHackGUT
Whai
Senior Member
Join Date: Jul 2018
Old 07-08-2019 , 06:59   Re: Hello I need help on TF2 Health
Reply With Quote #8

If you're still looking for how to set max health in TF2, you can try my plugin
__________________
Whai is offline
Reply


Thread Tools
Display Modes

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 09:35.


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