Raised This Month: $32 Target: $400
 8% 

Solved [L4D2] Setting Damage dealt to witch


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lightphoenix2
Member
Join Date: Feb 2016
Old 01-26-2021 , 11:48   [L4D2] Setting Damage dealt to witch
Reply With Quote #1

Hi, I'm wondering how do you set damage dealt to a witch
Code:
public void OnPluginStart()
{
	HookEvent("witch_spawn", eEvent);
}
public void eEvent (Event event, const char[] name, bool dontbroadcast)
{	
	int iWitch = GetEventInt(event, "witchid");
	SDKHook(iWitch, SDKHook_OnTakeDamagePost, OnTakeDamage);
}
I have tried hooking witch_spawn as well as SDKHook_OnTakeDamage before changing to SDKHook_OnTakeDamagePost.

Code:
public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
	if (attacker > 0 && attacker <= MaxClients && GetClientTeam(attacker) == 2 && g_iLevel[attacker] > 0)
	{
		if (GetClientTeam(victim) == 2)
		{
			return Plugin_Continue;
		}
		damage = GetRandomFloat(criMulMin, criMulMAX) * damage + 1;
		if(damage > 1024.0)
		{
			damage = 1023.0;
		}
		return Plugin_Changed;
	}
	
	return Plugin_Continue;
}
Any damage above 1024 seems to not be able to be detected by another plugin that detect damage done to special infected. It will display 0 instead. But it can still deal the damage.
Any Help would be appreciated!

Last edited by lightphoenix2; 01-30-2021 at 05:08.
lightphoenix2 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 01-26-2021 , 13:20   Re: [L4D2] Setting Damage dealt to witch
Reply With Quote #2

The order of events are "random"

You can have a plugin messing with OnTakeDamage
But if the plugin that outputs fires first then it may ignore the damage changed.
The plugin that outputs to the chat should use OnTakeDamagePost.

Can you share the other plugin? (if public)

EDIT:

So after trying your code I see that you GetClientTeam(victim) == 2 on the witch
Victim is the witch
Witch is not a client. (So GetClientTeam fails)
Team 2 means survivor

Try testing with this:

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

public void OnPluginStart()
{
    
HookEvent("witch_spawn"eEvent);
}
public 
void eEvent (Event event, const char[] namebool dontbroadcast)
{
    
int iWitch GetEventInt(event"witchid");
    
SDKHook(iWitchSDKHook_OnTakeDamageOnTakeDamage);
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetype)
{
    
//if (attacker > 0 && attacker <= MaxClients && GetClientTeam(attacker) == 2 && g_iLevel[attacker] > 0)
    
if (<= attacker <= MaxClients && GetClientTeam(attacker) == 2)
    {
        
// if (GetClientTeam(victim) == 2) // Witchs don't have team, also victim = witch and 2 means survivor
        // {
            // return Plugin_Continue;
        // }
        //damage = GetRandomFloat(criMulMin, criMulMAX) * damage + 1;
        
damage GetRandomFloat(512.01536.0);
        if(
damage 1024.0)
        {
            
PrintToChatAll(">>> GREATER >>> damage > 1024. damage %f"damage);
            
//damage = 1023.0;
        
}
        else
        {
            
PrintToChatAll("<<< LESSER <<< damage < 1024. damage %f"damage);
        }
        return 
Plugin_Changed;
    }

    return 
Plugin_Continue;

__________________

Last edited by Marttt; 01-26-2021 at 18:29.
Marttt is offline
lightphoenix2
Member
Join Date: Feb 2016
Old 01-27-2021 , 08:29   Re: [L4D2] Setting Damage dealt to witch
Reply With Quote #3

Quote:
Originally Posted by Marttt View Post
The order of events are "random"

You can have a plugin messing with OnTakeDamage
But if the plugin that outputs fires first then it may ignore the damage changed.
The plugin that outputs to the chat should use OnTakeDamagePost.

Can you share the other plugin? (if public)

EDIT:

So after trying your code I see that you GetClientTeam(victim) == 2 on the witch
Victim is the witch
Witch is not a client. (So GetClientTeam fails)
Team 2 means survivor

Try testing with this:

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

public void OnPluginStart()
{
    
HookEvent("witch_spawn"eEvent);
}
public 
void eEvent (Event event, const char[] namebool dontbroadcast)
{
    
int iWitch GetEventInt(event"witchid");
    
SDKHook(iWitchSDKHook_OnTakeDamageOnTakeDamage);
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetype)
{
    
//if (attacker > 0 && attacker <= MaxClients && GetClientTeam(attacker) == 2 && g_iLevel[attacker] > 0)
    
if (<= attacker <= MaxClients && GetClientTeam(attacker) == 2)
    {
        
// if (GetClientTeam(victim) == 2) // Witchs don't have team, also victim = witch and 2 means survivor
        // {
            // return Plugin_Continue;
        // }
        //damage = GetRandomFloat(criMulMin, criMulMAX) * damage + 1;
        
damage GetRandomFloat(512.01536.0);
        if(
damage 1024.0)
        {
            
PrintToChatAll(">>> GREATER >>> damage > 1024. damage %f"damage);
            
//damage = 1023.0;
        
}
        else
        {
            
PrintToChatAll("<<< LESSER <<< damage < 1024. damage %f"damage);
        }
        return 
Plugin_Changed;
    }

    return 
Plugin_Continue;

The main one is over here that version uses hook event like player hurt to detect damage. I made a few changes to it since then and I included it in the attachment.

Code:
if (GetClientTeam(victim) == 2)
		{
			return Plugin_Continue;
		}
The Code GetClientTeam(victim) == 2 is to detect for the survivor and it will return Plugin_Continue. And no changes will be made.

I'm working on the plugin l4d2_critical_shot_m.sp which will deal extra damage by changing the damage in OnTakeDamage. But it doesn't work for witch. This plugin requires the main l4d2_skills_core_V2.2.sp or the main one linked above. Once you buy the skill from the menu the player will be able to have a chance to deal extra damage. GetClientTeam(victim) == 2 is to prevent changing damage done to Survivor team.
The original plugin can be found here, I'm making a module for Skills that allow you to buy skills from a menu.
Attached Files
File Type: sp Get Plugin or Get Source (l4d2_skills_core_V2.2.sp - 87 views - 40.0 KB)
File Type: sp Get Plugin or Get Source (l4d2_critical_shot_m.sp - 100 views - 6.8 KB)

Last edited by lightphoenix2; 01-27-2021 at 08:33.
lightphoenix2 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 01-27-2021 , 11:36   Re: [L4D2] Setting Damage dealt to witch
Reply With Quote #4

Well try to change OnTakeDamagePost to OnTakeDamage

The signature method is wrong (check here)

PHP Code:
// OnTakeDamage
function Action (int victimint &attackerint &inflictorfloat &damageint &damagetype); 
PHP Code:
// OnTakeDamagePost
function void (int victimint attackerint inflictorfloat damageint damagetype); 
If you wanna change the damage you have to use it on OnTakeDamage (return Plugin_Changed)
If you just wanna check the values check on OnTakeDamagePost (return)

Both plugins have too many dependencies (files and includes) so I can't properly test in my local server.
__________________
Marttt is offline
lightphoenix2
Member
Join Date: Feb 2016
Old 01-27-2021 , 12:42   Re: [L4D2] Setting Damage dealt to witch
Reply With Quote #5

Quote:
Originally Posted by Marttt View Post
Well try to change OnTakeDamagePost to OnTakeDamage

The signature method is wrong (check here)

PHP Code:
// OnTakeDamage
function Action (int victimint &attackerint &inflictorfloat &damageint &damagetype); 
PHP Code:
// OnTakeDamagePost
function void (int victimint attackerint inflictorfloat damageint damagetype); 
If you wanna change the damage you have to use it on OnTakeDamage (return Plugin_Changed)
If you just wanna check the values check on OnTakeDamagePost (return)

Both plugins have too many dependencies (files and includes) so I can't properly test in my local server.
Initially, I use OnTakeDamage, but it doesn't even detect for witch. Do you know how to capture damage done to witch? I think witch is slightly different than special infected.

I will try to implement OnTakeDamagePost to detect the damage instead of OnTakeDamage. Thanks~!
lightphoenix2 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 01-27-2021 , 13:49   Re: [L4D2] Setting Damage dealt to witch
Reply With Quote #6

My code snippet outputs damage to the witch

If it's not outputting maybe you have some plugin cancelling the damage triggering before.

Also witch is not considered as a SI (client), they are more similar to commons (infected) when we compare them as entities
__________________

Last edited by Marttt; 01-27-2021 at 13:56.
Marttt is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 01-28-2021 , 03:56   Re: [L4D2] Setting Damage dealt to witch
Reply With Quote #7

PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
{
    if (
entity || entity 2048)
    {
        return;
    }
    
    if (
strcmp(classname"witch") == 0)
    {
        
SDKHook(entitySDKHook_OnTakeDamageOnTakeDamage);
    }


Last edited by cravenge; 01-28-2021 at 03:57.
cravenge is offline
lightphoenix2
Member
Join Date: Feb 2016
Old 01-28-2021 , 11:08   Re: [L4D2] Setting Damage dealt to witch
Reply With Quote #8

Quote:
Originally Posted by cravenge View Post
PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
{
    if (
entity || entity 2048)
    {
        return;
    }
    
    if (
strcmp(classname"witch") == 0)
    {
        
SDKHook(entitySDKHook_OnTakeDamageOnTakeDamage);
    }

Thanks this help to hook the witch, but it still cant be detected for god knows what so I made this:
Code:
public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
	if(GetEntityClassname(victim, "witch", 10) && attacker > 0 && GetClientTeam(attacker) == 2 && g_iLevel[attacker] > 0 && attacker <= MaxClients && victim > 12)
	{
		damage = GetRandomFloat(criMulMin, criMulMAX) * damage + 1;
		Knockback(attacker, victim, CritForce, 1.5, 2.0);
		if (CritPrint)
		{
			PrintToChat(attacker, "\x01Critical!\x03 %.2f\x01 damage", damage);
		}
		return Plugin_Changed;
	}
	if (attacker > 0 && attacker <= MaxClients && GetClientTeam(attacker) == 2 && g_iLevel[attacker] > 0)
	{
		if (GetClientTeam(victim) == 2)
		{
			return Plugin_Continue;
		}
		damage = GetRandomFloat(criMulMin, criMulMAX) * damage + 1;
		if(damage > 1024.0)
		{
			damage = 1023.0;
		}
		if (CritPrint)
		{
			PrintToChat(attacker, "\x01Critical!\x03 %.2f\x01 damage", damage);
		}
		
		Knockback(attacker, victim, CritForce, 1.5, 2.0);
		return Plugin_Changed;
	}
	return Plugin_Continue;
}
GetEntityClassname(victim, "witch", 10) seems to work for all special infected so I limited them using victim > 12. Anyone got any better idea??
lightphoenix2 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 01-28-2021 , 11:21   Re: [L4D2] Setting Damage dealt to witch
Reply With Quote #9

You should remove all your plugins and test this one as a single alone.

As I said if another plugin does "return Plugin_Stop;" on OnTakeDamage first.
It will not fire your PrintToChat

Witchs are not clients, so you can safely check victim > MaxClients
If you check the classname before then you don't even need the victim check.

The only thing I don't have is that g_iLevel var, maybe this is the problem.

As always, to debug your code, start doing simple checks then add more.
Maybe one of your checks is failing.

From your replies seem that you didn't test my snippet either from cravenge, both are working for us.
__________________

Last edited by Marttt; 01-28-2021 at 11:23.
Marttt is offline
lightphoenix2
Member
Join Date: Feb 2016
Old 01-28-2021 , 13:05   Re: [L4D2] Setting Damage dealt to witch
Reply With Quote #10

Quote:
Originally Posted by Marttt View Post
You should remove all your plugins and test this one as a single alone.

As I said if another plugin does "return Plugin_Stop;" on OnTakeDamage first.
It will not fire your PrintToChat

Witchs are not clients, so you can safely check victim > MaxClients
If you check the classname before then you don't even need the victim check.

The only thing I don't have is that g_iLevel var, maybe this is the problem.

As always, to debug your code, start doing simple checks then add more.
Maybe one of your checks is failing.

From your replies seem that you didn't test my snippet either from cravenge, both are working for us.
I used cravenge OnEntityCreated in l4d2_critical_shot_m.sp and your OnDamage for l4d2_skills_core_V2.2.sp. You can check it out in the attachment. It seems to work, just that I can't test if its other plugins that are causing the problem.
Also, I change the victim > 10 to victim > MaxClients after you mentioned it, which makes more sense.
Attached Files
File Type: sp Get Plugin or Get Source (l4d2_critical_shot_m.sp - 82 views - 7.1 KB)
File Type: sp Get Plugin or Get Source (l4d2_skills_core_V2.2.sp - 81 views - 40.0 KB)

Last edited by lightphoenix2; 01-28-2021 at 13:06.
lightphoenix2 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 02:21.


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