Raised This Month: $535 Target: $400
 133% 

Solved [L4D2]Exception reported: Client index 0 is invalid


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ddd123
Senior Member
Join Date: May 2021
Old 07-29-2021 , 21:53   [L4D2]Exception reported: Client index 0 is invalid
Reply With Quote #1

Sorry if i'm doing wrong. This is my first time to post scripting room.
So basically i'm editing and combining Everyone vomit, Showdamage as fortnite and [L4D1/2]Critical Shot
To make sure i can also hear custom sound effect from common infected from shot + random chance to vomit

But when i test i keep getting this annoying spam error and i don't know how to fix it
HTML Code:
L 07/30/2021 - 09:19:15: [SM] Exception reported: Client index 0 is invalid
L 07/30/2021 - 09:19:15: [SM] Blaming: l4d_crit.smx
L 07/30/2021 - 09:19:15: [SM] Call stack trace:
L 07/30/2021 - 09:19:15: [SM]   [0] EmitSound
L 07/30/2021 - 09:19:15: [SM]   [1] Line 433, include/sdktools_sound.inc::EmitSoundToClient
L 07/30/2021 - 09:19:15: [SM]   [2] Line 116, plugin.sp::IHurtDamage
I don't see Line 433 since my script total lines are 298
Here's around line 116
HTML Code:
public Action:IHurtDamage(Handle:event, const String:name[], bool:dontBroadcast)
{	
	new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
	new TempChance = GetRandomInt(0, 100);
	int iHitgroup = GetEventInt(event, "hitgroup");
	EmitSoundToClient(attacker, SOUNDER); // emit sound
	if(iHitgroup == 1) // headshot
		EmitSoundToClient(attacker, SOUNDERS); // emit sound LINE 116

	if (TempChance < GetConVarInt(cvarCritChance))
	{
			if (GetClientTeam(attacker) == 2)
			{
				new infected = GetEventInt(event, "entityid");
				decl String:class[20];
				GetEntityNetClass(infected, class, 20);
				new compare;
				compare = strcmp(class, "Witch");
				if(compare == 0)
				{
					return Plugin_Continue;
				}
				else
				{
//					IgniteEntity(infected, 100.0, false);
					damage = GetEventInt(event, "dmg_health");
					damagebonus = damage * damagechance;
					
					VomitEntity(infected);
					EmitSoundToAll (SOUNDS, true);
					
					new Float:x[3];
					new Float:z[3];
					new Float:j[3];
					new String:tName[32];
					new particle = CreateEntityByName("info_particle_system");
					DispatchKeyValue(particle, "effect_name", "boomer_explode_d");
					DispatchSpawn(particle);
					ActivateEntity(particle);
					AcceptEntityInput(particle, "Start");
					Format(tName, sizeof(tName), "part%d", infected);
					DispatchKeyValue(infected, "targetname", tName);
					SetVariantString(tName);
					AcceptEntityInput(particle, "SetParent", particle, particle, 0);
					SetVariantString("eyes");
					AcceptEntityInput(particle, "SetParentAttachment");
					TeleportEntity(particle, x, j, NULL_VECTOR);
					z[2]=z[2]-2;
					CreateTimer(0.1, DeleteParticles, EntIndexToEntRef(particle));
				}
			}
		}
	return Plugin_Continue;
}
Should i also post full sp script file here?
I would greatly happy and appreciate if someone can improve all my noob script and fix it

Last edited by ddd123; 07-30-2021 at 02:25.
ddd123 is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 07-29-2021 , 22:01   Re: [L4D2]Exception reported: Client index 0 is invalid
Reply With Quote #2

Line 433 lies within sdktools_sound.inc, which is where the function “EmitSoundToClient” is defined. you will have to validate the client index you are passing to the function in your plugin.

In other words, you must make sure “attacker” is valid.
__________________
Psyk0tik is offline
ddd123
Senior Member
Join Date: May 2021
Old 07-29-2021 , 22:06   Re: [L4D2]Exception reported: Client index 0 is invalid
Reply With Quote #3

Please forgive me for me being have no knowledge about coding and scripting (since most of script i did was copy and pasting)
But how do i do that? I really don't know how to make it sure the attacker is valid or something

Edit: Okay, i might be very wrong but MAYBE this error spam happened on versus mode (maybe bots cause this?) or something but i still don't know why and how to fix it

Last edited by ddd123; 07-30-2021 at 02:22.
ddd123 is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 07-30-2021 , 01:09   Re: [L4D2]Exception reported: Client index 0 is invalid
Reply With Quote #4

Below this line:
PHP Code:
new attacker GetClientOfUserId(GetEventInt(event"attacker")); 
You can add:
PHP Code:
if (!(attacker <= MaxClients && IsClientInGame(attacker))) // check that attacker index is between 1 and 32 and is in-game
    
return Plugin_Continue
__________________
Psyk0tik is offline
ddd123
Senior Member
Join Date: May 2021
Old 07-30-2021 , 02:24   Re: [L4D2]Exception reported: Client index 0 is invalid
Reply With Quote #5

Quote:
Originally Posted by Crasher_3637 View Post
Below this line:
PHP Code:
new attacker GetClientOfUserId(GetEventInt(event"attacker")); 
You can add:
PHP Code:
if (!(attacker <= MaxClients && IsClientInGame(attacker))) // check that attacker index is between 1 and 32 and is in-game
    
return Plugin_Continue
Thank you so much Crasher_3637!
Already test with full play 1 custom campaign map and no more spam error shown on both console and error log!
You're lifesaver!
ddd123 is offline
dustinandband
Senior Member
Join Date: May 2015
Old 07-30-2021 , 11:06   Re: [L4D2]Exception reported: Client index 0 is invalid
Reply With Quote #6

Quote:
Originally Posted by Crasher_3637 View Post
Below this line:
PHP Code:
new attacker GetClientOfUserId(GetEventInt(event"attacker")); 
You can add:
PHP Code:
if (!(attacker <= MaxClients && IsClientInGame(attacker))) // check that attacker index is between 1 and 32 and is in-game
    
return Plugin_Continue
Had anyone seen a client index above the MacClients value? Just asking here cause I never check if a client index is below 32 and havenít had any errors about that over the years, but wondering why itís a common practice to check.
dustinandband is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 07-30-2021 , 11:18   Re: [L4D2]Exception reported: Client index 0 is invalid
Reply With Quote #7

Quote:
Originally Posted by dustinandband View Post
Had anyone seen a client index above the MacClients value? Just asking here cause I never check if a client index is below 32 and havenít had any errors about that over the years, but wondering why itís a common practice to check.
I've seen client indexes having negative values and very high values (up to 5 digits) before. You can usually get those kinds of values when passing/using entity indexes without validating that they are actually client indexes. For example, in OnTakeDamage, sometimes the inflictor (entity index) can also be the attacker, so when you only check "attacker > 0" it will return true for the inflictor's index, thus resulting in an "Invalid client index" error.
__________________
Psyk0tik 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 18:47.


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