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

TF2 regenerate health done by damage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Newbie1992
Senior Member
Join Date: Jan 2013
Location: Germany
Old 12-19-2013 , 09:07   TF2 regenerate health done by damage
Reply With Quote #1

Hello guys,

I got a private plugin made by a good friend, this plugin will refill the player health by done damage.
So but i got 2x little problems with that plugin. First about the server its a saxton hale server.

So here are my problems.
* The plugin will not refill the damage by a backstab!
* The plugin will not add more health when the enemy is burning and or bleeding. (ONLY THE FIRST HIT WILL COUNT example: flamethrower or flying guillotine!)


Can anyone give me a little tip how i can add/change/fix that?


Here the plugin file (sp)
Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdkhooks>

#define PLUGIN_VERSION "1.0.0"

new Handle:g_hCVHealthPercentage;

new bool:g_bIsDonor[MAXPLAYERS+1] = {false, ...};

public Plugin:myinfo = 
{
    name = "HealthRegen",
    author = "fluxX",
    description = "Regenerate health done by damage",
    version = PLUGIN_VERSION,
    url = "http://wcfan.de"
}

public OnPluginStart()
{
    new Handle:hVersion = CreateConVar("sm_healthregen_version", PLUGIN_VERSION, "HealthRegen Version", FCVAR_PLUGIN|FCVAR_NOTIFY|FCVAR_REPLICATED|FCVAR_DONTRECORD);
    if(hVersion != INVALID_HANDLE)
    {
        SetConVarString(hVersion, PLUGIN_VERSION);
        HookConVarChange(hVersion, OnConVarVersionChange);
    }
    
    g_hCVHealthPercentage = CreateConVar("sm_healthregen_percentage", "0.20", "Percentage of health done by damage.", FCVAR_PLUGIN);
}

public OnConVarVersionChange(Handle:convar, const String:oldValue[], const String:newValue[])
{
    SetConVarString(convar, PLUGIN_VERSION);
}

public OnClientPutInServer(client)
{
    SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
}

public OnClientPostAdminCheck(client)
{
    if(CheckCommandAccess(client, "", ADMFLAG_RESERVATION, true))
        g_bIsDonor[client] = true;
    else
        g_bIsDonor[client] = false;
}

public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
    if(IsValidClient(attacker) && GetClientTeam(attacker) == 2 && attacker != victim && g_bIsDonor[attacker])
    {
        new iMaxHealth = GetEntData(attacker, FindDataMapOffs(attacker, "m_iMaxHealth"), 4);
        new iAddHealth = RoundToFloor(damage * GetConVarFloat(g_hCVHealthPercentage));
        new iClientHealth = GetClientHealth(attacker);
        
        iClientHealth += iAddHealth;
        
        if(iClientHealth > iMaxHealth)
            iClientHealth = iMaxHealth;
        
        SetEntData(attacker, FindDataMapOffs(attacker, "m_iHealth"), iClientHealth, 4, true);
    }
}

stock bool:IsValidClient(client)
{
    if(client < 1 || client > MaxClients)
        return false;
    if(!IsClientConnected(client))
        return false;
    return IsClientInGame(client);
}
Thanks!

best regards,
Newbie' the Noob
__________________

Last edited by Newbie1992; 12-19-2013 at 09:07.
Newbie1992 is offline
NIGathan
Senior Member
Join Date: Aug 2011
Location: /dev/null
Old 12-20-2013 , 04:30   Re: TF2 regenerate health done by damage
Reply With Quote #2

I've used this before to prevent damage:
PHP Code:
SetEntProp(victimIdProp_Data"m_iHealth"GetEventInt(event"damageamount") + iHealth); 
This works with backstabs and bleed/burn. However, I used it on one of these hooks:
PHP Code:
HookEvent("player_hurt"Event_PlayerHurtEventHookMode_Pre); 
Not with sdkhooks.
NIGathan is offline
Newbie1992
Senior Member
Join Date: Jan 2013
Location: Germany
Old 12-20-2013 , 08:14   Re: TF2 regenerate health done by damage
Reply With Quote #3

Hello,

Thanks for your answer but can you edit the sp so that all will works fine with all weapons and damage in tf2?

I have no idea what i need to change/edit.

Thanks!
__________________
Newbie1992 is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 12-20-2013 , 09:06   Re: TF2 regenerate health done by damage
Reply With Quote #4

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#define PLUGIN_VERSION "1.0.0"

new Handle:g_hCVHealthPercentage;
new 
bool:g_bIsDonor[MAXPLAYERS+1] = {false, ...};

public 
Plugin:myinfo 
{
    
name "HealthRegen",
    
author "fluxX",
    
description "Regenerate health done by damage",
    
version PLUGIN_VERSION,
    
url "http://wcfan.de"
}

public 
OnPluginStart()
{
    
g_hCVHealthPercentage CreateConVar("sm_healthregen_percentage""20""Percentage of health done by damage."FCVAR_PLUGIN);
    
HookEvent("player_hurt"Event_PlayerHurtEventHookMode_Pre); 
}

public 
OnClientPostAdminCheck(client)
{
    if(
CheckCommandAccess(client""ADMFLAG_RESERVATIONtrue))
        
g_bIsDonor[client] = true;
    else
        
g_bIsDonor[client] = false;
}

public 
Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if( 
IsValidClient(client) && g_bIsDonor[client] )
    {
        new 
damage GetEventInt(event"damageamount");        // errr.. i plan to explain this to you but getting my ass lazy.
        
new mult GetConVarIntg_hCVHealthPercentage );        // bla
        
new healthtoadd damage mult 100;                    //
        
new health GetEntPropclientProp_Data"m_iHealth" );
        
SetEntProp(clientProp_Data"m_iHealth"health healthtoadd ); 
    }
}

stock bool:IsValidClient(client)
{
    if(
client || client MaxClients)
        return 
false;
    if(!
IsClientConnected(client))
        return 
false;
    return 
IsClientInGame(client);

__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.
GsiX is offline
Newbie1992
Senior Member
Join Date: Jan 2013
Location: Germany
Old 12-20-2013 , 09:33   Re: TF2 regenerate health done by damage
Reply With Quote #5

Hello,

Thanks for your answer too, but the plugin does not work so.

Thanks!
__________________
Newbie1992 is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 12-20-2013 , 16:02   Re: TF2 regenerate health done by damage
Reply With Quote #6

PHP Code:
new healthtoadd damage mult 100
Assuming mult is a percentage between 0 and 99, healthtoadd will always be 0. Assuming this is the issue, change 100 to 100.0
__________________

Last edited by 11530; 12-20-2013 at 16:03.
11530 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-20-2013 , 16:11   Re: TF2 regenerate health done by damage
Reply With Quote #7

Quote:
Originally Posted by 11530 View Post
PHP Code:
new healthtoadd damage mult 100
Assuming mult is a percentage between 0 and 99, healthtoadd will always be 0. Assuming this is the issue, change 100 to 100.0
Yeah, that's not going to help any, since you're still storing it as a whole number and not a Float.

You'd need something like this instead...

PHP Code:
new healthtoadd RoundToNearest(damage mult 100.0); //or RoundToCeil to always round up 
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-20-2013 at 16:12.
Powerlord is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 12-20-2013 , 17:38   Re: TF2 regenerate health done by damage
Reply With Quote #8

Yea I just jumped the gun as soon as I saw the 100. I didn't look into it any further than that. It's Friday, so I'm allowed a little leeway
__________________
11530 is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 12-21-2013 , 01:56   Re: TF2 regenerate health done by damage
Reply With Quote #9

Quote:
Originally Posted by Powerlord View Post
Yeah, that's not going to help any, since you're still storing it as a whole number and not a Float.

You'd need something like this instead...

PHP Code:
new healthtoadd RoundToNearest(damage mult 100.0); //or RoundToCeil to always round up 
Woops.. my bad..

EDIT: This is something we like when Oh Ross is on watch.. thanks for the correction.
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 12-21-2013 at 01:59.
GsiX is offline
Reply



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 04:20.


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