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

Solved [L4D2] Setting Damage dealt to witch


Post New Thread Reply   
 
Thread Tools Display Modes
lightphoenix2
Member
Join Date: Feb 2016
Old 01-29-2021 , 08:22   Re: [L4D2] Setting Damage dealt to witch
Reply With Quote #11

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 > MaxClients)
	{
		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 (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) also works for any special infected, I don't know why.
I need another if statement on top to make the plugin work, I also don't know why.

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

Is because you can't compare strings like that:

This is the return of GetEntityClassname:

PHP Code:
Return Value
True on success
false if there is no classname set
https://sm.alliedmods.net/new-api/en...ntityClassname

In other worlds, since you are always passing a classname it will always returns true.

The correct what to check is doing like this.

PHP Code:
char classname[6]; //witch has a len of 5 + 1 for the terminator
GetEntityClassname(victimclassnamesizeof(classname)); 
Then you change your logic to:

PHP Code:
if (victim MaxClients && classname[0] == 'w' && StrEqual(classname"witch") && attacker && attacker <= MaxClients && IsClientInGame(attacker) && GetClientTeam(attacker) == && g_iLevel[attacker] > 0
I didn't test but may work.
__________________

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

Quote:
Originally Posted by Marttt View Post
Is because you can't compare strings like that:

This is the return of GetEntityClassname:

PHP Code:
Return Value
True on success
false if there is no classname set
https://sm.alliedmods.net/new-api/en...ntityClassname

In other worlds, since you are always passing a classname it will always returns true.

The correct what to check is doing like this.

PHP Code:
char classname[6]; //witch has a len of 5 + 1 for the terminator
GetEntityClassname(victimclassnamesizeof(classname)); 
Then you change your logic to:

PHP Code:
if (victim MaxClients && classname[0] == 'w' && StrEqual(classname"witch") && attacker && attacker <= MaxClients && IsClientInGame(attacker) && GetClientTeam(attacker) == && g_iLevel[attacker] > 0
I didn't test but may work.
Ah, from your explanation, it makes sense. I will try it out and let you know if it works.
lightphoenix2 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 01-29-2021 , 19:17   Re: [L4D2] Setting Damage dealt to witch
Reply With Quote #14

You don't need to quote every post before yours. It makes understanding harder, at least for me.

Later give the feedback if it worked now.
__________________

Last edited by Marttt; 01-29-2021 at 19:33.
Marttt is offline
lightphoenix2
Member
Join Date: Feb 2016
Old 01-30-2021 , 02:13   Re: [L4D2] Setting Damage dealt to witch
Reply With Quote #15

Code:
public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
	char classname[6];
	if(GetEntityClassname(victim, classname, sizeof(classname)) && StrEqual(classname, "witch") && attacker > 0 && GetClientTeam(attacker) == 2 && g_iLevel[attacker] > 0 && attacker <= MaxClients)
	{
		damage = GetRandomFloat(criMulMin, criMulMAX) * damage + 1;
		Knockback(attacker, victim, CritForce, 1.5, 2.0);
		if (CritPrint)
		{
			PrintToChat(attacker, "1\x01Critical!\x03 %.2f\x01 damage", damage);
		}
		return Plugin_Changed;
	}
	if (attacker > 0 && attacker <= MaxClients && GetClientTeam(attacker) == 2 && g_iLevel[attacker] > 0 && GetClientTeam(victim) != 2)
	{
		damage = GetRandomFloat(criMulMin, criMulMAX) * damage + 1;
		Knockback(attacker, victim, CritForce, 1.5, 2.0);
		if (CritPrint)
		{
			PrintToChat(attacker, "2\x01Critical!\x03 %.2f\x01 damage", damage);
		}
		return Plugin_Changed;
	}
	return Plugin_Continue;
}
This is the final version, from what API says, there is this String Buffer, I just need to save it and compare it as you did. GetEntityClassname function itself returns a boolean, but it can also store the classname in the second parameter, I didn't notice it until you mention it to me about the return function.

I have a theory why it can't detect witch without detecting its class, since Marttt mention witch is not SI and more like common infected. It will automatically skip or stop the Plugin. I tested beforehand, and when witch takes damage it will trigger OnTakeDamage, but it just stop, it never even reach
Quote:
return Plugin_Continue;
lightphoenix2 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 02-02-2021 , 19:11   Re: [L4D2] Setting Damage dealt to witch
Reply With Quote #16

you can break the OnTakeDamage in two if having it in the same is confusing you

OnTakeDamageClient

and

OnTakeDamageWitch

*only renamed.

Didn't get if it worked or not,

As I said the examples above were working.

You should debug with PrintToChatAll("TEST") in every single line to detect if the code is running or not, and what are the parameters values.
__________________

Last edited by Marttt; 02-02-2021 at 19:11.
Marttt 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 13:20.


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