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

Solved [TF2] OnTakeDamage : Is it possible to hook an entity ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Whai
Senior Member
Join Date: Jul 2018
Old 11-03-2018 , 11:16   [TF2] OnTakeDamage : Is it possible to hook an entity ?
Reply With Quote #1

Is it possible to hook an entity like a tank ?

I tested this code but not working :
PHP Code:
public void OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetype)
{
    if(!
IsValidClient(attacker)) return Plugin_Continue;

    if(
attacker == victim) return Plugin_Continue;

    
int iEnt = -1;
    
iEnt FindEntityByClassname(iEnt"tank_boss");

    if(
iEnt == victim)
    {
        
PrintToChatAll("%N attacked a tank !"attacker);
    }

    return 
Plugin_Changed;
}

stock bool IsValidClient(int client)
{
    return (
<= client <= MaxClients) && IsClientInGame(client);

__________________

Last edited by Whai; 11-03-2018 at 18:13.
Whai is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 11-03-2018 , 11:55   Re: [TF2] OnTakeDamage : Is it possible to hook an entity ?
Reply With Quote #2

Quote:
Originally Posted by Whai View Post
Is it possible to hook an entity like a tank ?

I tested this code but not working :
PHP Code:
public void OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetype)
{
    if(!
IsValidClient(attacker)) return Plugin_Continue;

    if(
attacker == victim) return Plugin_Continue;

    
int iEnt = -1;
    
iEnt FindEntityByClassname(iEnt"tank_boss");

    if(
iEnt == victim)
    {
        
PrintToChatAll("%N attacked a tank !"attacker);
    }

    return 
Plugin_Changed;
}

stock bool IsValidClient(int client)
{
    return (
<= client <= MaxClients) && IsClientInGame(client);

b/c you are hooking client so the client will never be tank_boss

try
PHP Code:
    new ent = -1;    
    while ((
ent FindEntityByClassname(ent"tank_boss")) != -1)
    {
        
SDKHook(entSDKHook_OnTakeDamageOnPropTakeDamage);
    } 
__________________

Last edited by 8guawong; 11-03-2018 at 11:56.
8guawong is offline
Whai
Senior Member
Join Date: Jul 2018
Old 11-03-2018 , 12:50   Re: [TF2] OnTakeDamage : Is it possible to hook an entity ?
Reply With Quote #3

Quote:
Originally Posted by 8guawong View Post
b/c you are hooking client so the client will never be tank_boss

try
PHP Code:
    new ent = -1;    
    while ((
ent FindEntityByClassname(ent"tank_boss")) != -1)
    {
        
SDKHook(entSDKHook_OnTakeDamageOnPropTakeDamage);
    } 

Thanks ! it worked, but is there another method to hook this thing without using OnEntityCreated ?

Here is what I did :


And here is what happens with this code (look the dmg I've done)



I noticed something about that :


with this code, for some reason it print 10 times the "Square attacked the tank" so maybe it has something with the damage I did

Oh and if you do that :

You lose you ears
__________________

Last edited by Whai; 11-03-2018 at 16:26.
Whai is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 11-03-2018 , 15:33   Re: [TF2] OnTakeDamage : Is it possible to hook an entity ?
Reply With Quote #4

Code:
public void OnEntityCreated(int entity, const char[] classname) 
{ 
    // check if the classname param is the tank
    { 
        SDKHook(entity, SDKHook_OnTakeDamage, OnPropTakeDamage); 
    } 
}
__________________
Neuro Toxin is offline
Whai
Senior Member
Join Date: Jul 2018
Old 11-03-2018 , 16:26   Re: [TF2] OnTakeDamage : Is it possible to hook an entity ?
Reply With Quote #5

Quote:
Originally Posted by Neuro Toxin View Post
Code:
public void OnEntityCreated(int entity, const char[] classname) 
{ 
    // check if the classname param is the tank
    { 
        SDKHook(entity, SDKHook_OnTakeDamage, OnPropTakeDamage); 
    } 
}
Thanks for this, I'll try later

Edit : Thanks ! That worked, there is no spam message and I don’t lag anymore
__________________

Last edited by Whai; 11-03-2018 at 16:48.
Whai is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 11-03-2018 , 17:45   Re: [TF2] OnTakeDamage : Is it possible to hook an entity ?
Reply With Quote #6

Did u put in a string equals check for tank classname?
__________________
Neuro Toxin is offline
Whai
Senior Member
Join Date: Jul 2018
Old 11-03-2018 , 18:05   Re: [TF2] OnTakeDamage : Is it possible to hook an entity ?
Reply With Quote #7

Quote:
Originally Posted by Neuro Toxin View Post
Did u put in a string equals check for tank classname?
Yes, I wrote this but I don't know if this forward need "return Plugin_Handled"

PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
{
    if(
StrEqual(classname"tank_boss"))
    {
        
SDKHook(entitySDKHook_OnTakeDamageOnPropTakeDamage);
    }

__________________
Whai is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 11-03-2018 , 19:29   Re: [TF2] OnTakeDamage : Is it possible to hook an entity ?
Reply With Quote #8

OnEntityCreated type is void. So no return value is required.
__________________

Last edited by Neuro Toxin; 11-03-2018 at 19:32.
Neuro Toxin 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 08:32.


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