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

Solved [TF2] OnTakeDamage damage value help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ravrob
Junior Member
Join Date: Oct 2019
Location: The Ice
Old 07-15-2020 , 20:32   [TF2] OnTakeDamage damage value help
Reply With Quote #1

I'm trying to create a script that will allow players to leech health under certain conditions and what I wrote does that just fine, only if you call the damage parameter it'll return some huge insane number that creates unstoppable juggernauts, not exactly my intentions. Is there any way to convert this into a normal usable number or am I missing something? Any help would be appreciated.

PHP Code:
public void OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetypeint &weaponfloat damageForce[3], float damagePosition[3], int damagecustom)
{
    if (
attacker <= || attacker MaxClients)
    { 
        return 
Plugin_Continue;
    }
    
int vHealth GetClientHealth(attacker);
    
int color[4];
    
GetEntityRenderColor(attackercolor[0], color[1], color[2], color[3]);
    
PrintToChatAll("%N dealt %i damage."attackerdamage);
    if(
attacker && color[0] == 210 && vitim != attacker)
    {
        if(
TF2_GetPlayerClass(attacker) == TFClass_Heavy && vHealth 300)
        {
            
SetEntProp(attackerProp_Send"m_iHealth"vHealth damage1);
        }
        if(
TF2_GetPlayerClass(attacker) == TFClass_Scout && vHealth 150)
        {
            
SetEntProp(attackerProp_Send"m_iHealth"vHealth damage1);
        }
    }
    return 
Plugin_Continue;


Last edited by Ravrob; 07-16-2020 at 06:25.
Ravrob is offline
Scag
AlliedModders Donor
Join Date: May 2017
Location: Crashing Hale
Old 07-15-2020 , 22:43   Re: [TF2] OnTakeDamage damage value help
Reply With Quote #2

"damage" is a float. When you're printing it out, you're printing it out as an integer, so you'll get an incredibly incorrect number.

To get it as its actual value, you would have to use %f or %.0f to shave off the decimals. Or you can convert the float value to an integer with RoundFloat or something of the sort. e.g. int iDamage = RoundFloat(damage);

Your other logic looks correct at a glance.

Edit: You must be getting a tag mismatch warning. When you do math with a float value, the resultant value turns into a float. since m_iMaxHealth and succinctly SetEntProp require integers, you would want to use RoundFloat. vHealth + damage turns the resulting value into a float.
__________________
Over-engineering is underrated.

GitHub
BTC
ETH

Retired

Last edited by Scag; 07-16-2020 at 00:36.
Scag is offline
Ravrob
Junior Member
Join Date: Oct 2019
Location: The Ice
Old 07-16-2020 , 06:24   Re: [TF2] OnTakeDamage damage value help
Reply With Quote #3

Oh, duh. You were absolutely correct I feel silly having missed that, thank you! Although oddly enough I wasn't getting a tag mismatch.. not sure why that is.
Ravrob is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 07-16-2020 , 08:39   Re: [TF2] OnTakeDamage damage value help
Reply With Quote #4

Quote:
Originally Posted by Ravrob View Post
Although oddly enough I wasn't getting a tag mismatch.. not sure why that is.
SetEntProp takes any, so it won't throw any tag mismatch warnings.

As an aside you may want to use SDKHook_OnTakeDamageAlive(Post) if you need to take damage modifiers into account.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop 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 03:10.


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