AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Hello I need help on TF2 Health (https://forums.alliedmods.net/showthread.php?t=316934)

joel177 06-18-2019 15:59

Hello I need help on TF2 Health
 
1 Attachment(s)
How i get and set the health in sourcepawn Attachment 176002
but not like that
https://i.ytimg.com/vi/wrtB2MCnT3A/hqdefault.jpg
SetEntityHealth()?

CrazyHackGUT 06-18-2019 16:09

Re: Hello I need help on TF2 Health
 
TF2 Attributes, for example, can give you ability increase max health.
Attribute with name "max health additive bonus", or index 26.

joel177 06-19-2019 08:43

Re: Hello I need help on TF2 Health
 
Quote:

Originally Posted by CrazyHackGUT (Post 2655902)
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

CrazyHackGUT 06-19-2019 09:14

Re: Hello I need help on TF2 Health
 
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.

joel177 06-19-2019 11:01

Re: Hello I need help on TF2 Health
 
Quote:

Originally Posted by CrazyHackGUT (Post 2655902)
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 (Post 2655966)
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!:)

Powerlord 06-19-2019 16:59

Re: Hello I need help on TF2 Health
 
Quote:

Originally Posted by CrazyHackGUT (Post 2655966)
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.

CrazyHackGUT 06-20-2019 04:48

Re: Hello I need help on TF2 Health
 
SDKHook_GetMaxHealth doesn't work on me. Windows, SM 1.9.

Whai 07-08-2019 06:59

Re: Hello I need help on TF2 Health
 
If you're still looking for how to set max health in TF2, you can try my plugin


All times are GMT -4. The time now is 10:56.

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