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

I need help with a plugin error "Exception reported: Client index 0 is invalid"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Camaro12345678
New Member
Join Date: Sep 2017
Old 03-04-2022 , 22:28   I need help with a plugin error "Exception reported: Client index 0 is invalid"
Reply With Quote #1

Hi, this is my first post here, I usually use plugins from others or patch code together so i have a very shallow understanding of programing.

My problem is that i have no idea what I'm doing wrong with this one.
The intended function is that when a grenade/molotov falls nearby a player the voice line is played as a warning.

It works fine at the first time, plays the sound "grenade!!!" but that's it.
It stops working for the remaining of the round despite having grenades landing in the foot all the time and error in the terminal over and over the following...

Code:
L 03/04/2022 - 18:01:50: [SM] Exception reported: Client index 0 is invalid             
L 03/04/2022 - 18:01:50: [SM] Blaming: grenade_yell.smx                                 
L 03/04/2022 - 18:01:50: [SM] Call stack trace:                                         
L 03/04/2022 - 18:01:50: [SM]   [0] GetClientTeam                                       
L 03/04/2022 - 18:01:50: [SM]   [1] Line 138, grenade_yell.sp::GrenadeScreamCheckTimer
This is the line 138 it reports.

Code:
if (client > 0 && IsPlayerAlive(client) && GetClientTeam(client) == 2 && GetClientTeam(owner) == 3)
This is the full code.

Code:
//#pragma dynamic 32768	// Increase heap size
#pragma semicolon 1

public Plugin myinfo = {
	name		= "[INS] Yells Grenade",
	author		= "",
	description	= "Yells at nearby Grenades and Molotov",
	version		= "2.0",
	url			= ""
};

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <insurgencydy>
#include <smlib>

#define INVALID_USERID 0

// Status
new

	g_plyrGrenScreamCoolDown[MAXPLAYERS+1];
	g_plyrFireScreamCoolDown[MAXPLAYERS+1];
	

public OnMapStart()
{	

	//Grenade Call Out
	PrecacheSound("player/voice/botsurvival/leader/incominggrenade9.ogg");
	PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade9.ogg");
	PrecacheSound("player/voice/botsurvival/leader/incominggrenade4.ogg");
	PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade4.ogg");
	PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade35.ogg");
	PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade34.ogg");
	PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade33.ogg");
	PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade23.ogg");
	PrecacheSound("player/voice/botsurvival/leader/incominggrenade2.ogg");
	PrecacheSound("player/voice/botsurvival/leader/incominggrenade13.ogg");
	PrecacheSound("player/voice/botsurvival/leader/incominggrenade12.ogg");
	PrecacheSound("player/voice/botsurvival/leader/incominggrenade11.ogg");
	PrecacheSound("player/voice/botsurvival/leader/incominggrenade10.ogg");
	PrecacheSound("player/voice/botsurvival/leader/incominggrenade18.ogg");
	
	//Molotov/Incen Callout
	PrecacheSound("player/voice/responses/security/subordinate/damage/molotov_incendiary_detonated7.ogg");
	PrecacheSound("player/voice/responses/security/leader/damage/molotov_incendiary_detonated6.ogg");
	PrecacheSound("player/voice/responses/security/subordinate/damage/molotov_incendiary_detonated6.ogg");
	PrecacheSound("player/voice/responses/security/leader/damage/molotov_incendiary_detonated5.ogg");
	PrecacheSound("player/voice/responses/security/leader/damage/molotov_incendiary_detonated4.ogg");

}

public OnEntityCreated(entity, const String:classname[])
{

	if (StrEqual(classname, "grenade_m67") || StrEqual(classname, "grenade_f1"))
		{
		CreateTimer(0.2, GrenadeScreamCheckTimer, entity, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
		}
	else if (StrEqual(classname, "grenade_molotov") || StrEqual(classname, "grenade_anm14"))
		{
		CreateTimer(0.2, FireScreamCheckTimer, entity, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
		}

}
public Action:FireScreamCheckTimer(Handle:timer, any:entity)
{
	new Float:fGrenOrigin[3];
	new Float:fPlayerOrigin[3];
	new Float:fPlayerEyeOrigin[3];
	new owner;
	if (IsValidEntity(entity) && entity > 0)
	{
		GetEntPropVector(entity, Prop_Send, "m_vecOrigin", fGrenOrigin);
		owner = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
	}
	else
		KillTimer(timer);


	
 
	for (new client = 1;client <= MaxClients;client++)
	{
		if (client <= 0 || !IsClientInGame(client) || !IsClientConnected(client))
			continue;
		if (owner <= 0 || !IsClientInGame(owner) || !IsClientConnected(owner))
			continue;
		if (IsFakeClient(client))
			continue;

		if (IsPlayerAlive(client) && GetClientTeam(client) == 2 && GetClientTeam(owner) == 3)
		{

			GetClientEyePosition(client, fPlayerEyeOrigin);
			GetClientAbsOrigin(client,fPlayerOrigin);
			//new Handle:trace = TR_TraceRayFilterEx(fPlayerEyeOrigin, fGrenOrigin, MASK_SOLID_BRUSHONLY, RayType_EndPoint, Base_TraceFilter); 

			if (GetVectorDistance(fPlayerOrigin, fGrenOrigin) <= 320 &&  g_plyrFireScreamCoolDown[client] <= 0)// && TR_DidHit(trace) && fGrenOrigin[2] > 0)
			{
				//PrintToServer("SCREAM FIRE");
				PlayerFireScreamRand(client);
				new fRandomInt = GetRandomInt(2, 5);
				g_plyrFireScreamCoolDown[client] = fRandomInt;
				//CloseHandle(trace);  
			}
		}
	}

	if (!IsValidEntity(entity) || !(entity > 0))
		KillTimer(timer);
}
public Action:GrenadeScreamCheckTimer(Handle:timer, any:entity)
{
	new Float:fGrenOrigin[3];
	new Float:fPlayerOrigin[3];
	new Float:fPlayerEyeOrigin[3];
	new owner;
	if (IsValidEntity(entity) && entity > 0)
	{
		GetEntPropVector(entity, Prop_Send, "m_vecOrigin", fGrenOrigin);
		owner = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
	}
	else
		KillTimer(timer);

	for (new client = 1;client <= MaxClients;client++)
	{
		if (client <= 0 || !IsClientInGame(client) || !IsClientConnected(client))
			continue;

		if (IsFakeClient(client))
			continue;

		//if (IsPlayerAlive(client) && GetClientTeam(client) == 2 && GetClientTeam(owner) == 3)
		if (client > 0 && IsPlayerAlive(client) && GetClientTeam(client) == 2 && GetClientTeam(owner) == 3)		
		{

			GetClientEyePosition(client, fPlayerEyeOrigin);
			GetClientAbsOrigin(client,fPlayerOrigin);			
			//new Handle:trace = TR_TraceRayFilterEx(fPlayerEyeOrigin, fGrenOrigin, MASK_VISIBLE, RayType_EndPoint, Base_TraceFilter); 

			if (GetVectorDistance(fPlayerOrigin, fGrenOrigin) <= 450 &&  g_plyrGrenScreamCoolDown[client] <= 0)// && TR_DidHit(trace) && fGrenOrigin[2] > 0)
			{
				PlayerGrenadeScreamRand(client);
				new fRandomInt = GetRandomInt(1, 3);
				g_plyrGrenScreamCoolDown[client] = fRandomInt;
				//CloseHandle(trace); 
			} 
		}
	}

	if (!IsValidEntity(entity) || !(entity > 0))
		KillTimer(timer);
}
I suspect the timer is not being killed, or it's not getting the player correctly, but I'm dumb, no seriously if you can draw it for me i will be very grateful.
Thanks in advance.
Camaro12345678 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 03-05-2022 , 04:24   Re: I need help with a plugin error "Exception reported: Client index 0 is invalid"
Reply With Quote #2

The issue probably is here:

if (client > 0 && IsPlayerAlive(client) && GetClientTeam(client) == 2 && GetClientTeam(owner) == 3)

in this case most likely the entity has no "owner" and the plugin is trying to get the team from "owner" variable without doing safe checks before
(valid client index [1...MaxClients] and IsClientInGame check)

Try changing it to:

PHP Code:
if (IsPlayerAlive(client) && GetClientTeam(client) == && <= owner <= MaxClients && IsClientInGame(owner) && GetClientTeam(owner) == 3
Btw the code has other flaws like here

PHP Code:
    for (new client 1;client <= MaxClients;client++)
    {
        if (
client <= || !IsClientInGame(client) || !IsClientConnected(client))
            continue; 
You don't need to check
Code:
client <= 0
Since the client is defined and initialized in the loop as "1"

Also IsClientInGame already checks for IsClientConnected
__________________

Last edited by Marttt; 03-05-2022 at 04:25.
Marttt is offline
NoroHime
Veteran Member
Join Date: Aug 2016
Location: bed
Old 03-05-2022 , 21:47   Re: I need help with a plugin error "Exception reported: Client index 0 is invalid"
Reply With Quote #3

i didnt recommended use Owner property, it wasnt change when you transfer weapon to other players
when you storing entity ids, you need turn it to Entity References

and you try operate a timer you need check it using IsValidHandle(timer)

many problem you can learn from [TUT] SourcePawn Scripting - Tips, Basics to Advanced
you worth to try it
---
and this snippets i usually uses
PHP Code:
stock bool isAliveSurvivor(int client) {
    return 
isSurvivor(client) && IsPlayerAlive(client);
}

stock bool isSurvivor(int client) {
    return 
isClient(client) && GetClientTeam(client) == 2;
}

stock bool isClient(int client) {
    return 
isClientIndex(client) && IsValidEntity(client) && IsClientInGame(client);
}

stock bool isClientIndex(int client) {
    return (
<= client <= MaxClients);

__________________

Last edited by NoroHime; 03-05-2022 at 21:49.
NoroHime is offline
Camaro12345678
New Member
Join Date: Sep 2017
Old 03-06-2022 , 01:48   Re: I need help with a plugin error "Exception reported: Client index 0 is invalid"
Reply With Quote #4

Quote:
Originally Posted by Marttt View Post
The issue probably is here:

if (client > 0 && IsPlayerAlive(client) && GetClientTeam(client) == 2 && GetClientTeam(owner) == 3)

in this case most likely the entity has no "owner" and the plugin is trying to get the team from "owner" variable without doing safe checks before
(valid client index [1...MaxClients] and IsClientInGame check)

Try changing it to:

PHP Code:
if (IsPlayerAlive(client) && GetClientTeam(client) == && <= owner <= MaxClients && IsClientInGame(owner) && GetClientTeam(owner) == 3
Btw the code has other flaws like here

PHP Code:
    for (new client 1;client <= MaxClients;client++)
    {
        if (
client <= || !IsClientInGame(client) || !IsClientConnected(client))
            continue; 
You don't need to check
Code:
client <= 0
Since the client is defined and initialized in the loop as "1"

Also IsClientInGame already checks for IsClientConnected
Thank you very much, i made the changes you pointed out and seems like the error message at least was gone from the terminal, but still the command is called once and then is dead.

I suspect that there's another flaw here.

Code:
			if (GetVectorDistance(fPlayerOrigin, fGrenOrigin) <= 350 &&  g_plyrGrenScreamCoolDown[client] <= 0)
			{
				PlayerGrenadeScreamRand(client);
				new fRandomInt = GetRandomInt(1, 3);
				g_plyrGrenScreamCoolDown[client] = fRandomInt;
It's supposed to get a random number 1,3 in this case and use it as a countdown to the next time it is allowed to play the sound.
If i remove it, it works but, there's no cool down, the sound plays over and over itself. Even though very funny, it's not intended.
If you could shine a light for me, it would be great.
Camaro12345678 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 03-06-2022 , 06:48   Re: I need help with a plugin error "Exception reported: Client index 0 is invalid"
Reply With Quote #5

you second problem is code logic here:

g_plyrGrenScreamCoolDown[client]
g_plyrFireScreamCoolDown[client]

once the variable is set, you code won't run for that client again because you always check if g_plyrFireScreamCoolDown[client] <= 0 / g_plyrFireScreamCoolDown[client] <= 0, and once set the check will always fail cause you don't reset

try this code:

PHP Code:
//#pragma dynamic 32768    // Increase heap size
#pragma semicolon 1

public Plugin myinfo = {
    
name        "[INS] Yells Grenade",
    
author        "",
    
description    "Yells at nearby Grenades and Molotov",
    
version        "2.0",
    
url            ""
};

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <insurgencydy>
#include <smlib>

#define INVALID_USERID 0

// Status
new

    
g_plyrGrenScreamCoolDown[MAXPLAYERS+1];
    
g_plyrFireScreamCoolDown[MAXPLAYERS+1];


public 
OnMapStart()
{

    
//Grenade Call Out
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade9.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade9.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade4.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade4.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade35.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade34.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade33.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade23.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade2.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade13.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade12.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade11.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade10.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade18.ogg");

    
//Molotov/Incen Callout
    
PrecacheSound("player/voice/responses/security/subordinate/damage/molotov_incendiary_detonated7.ogg");
    
PrecacheSound("player/voice/responses/security/leader/damage/molotov_incendiary_detonated6.ogg");
    
PrecacheSound("player/voice/responses/security/subordinate/damage/molotov_incendiary_detonated6.ogg");
    
PrecacheSound("player/voice/responses/security/leader/damage/molotov_incendiary_detonated5.ogg");
    
PrecacheSound("player/voice/responses/security/leader/damage/molotov_incendiary_detonated4.ogg");

}

public 
void OnClientDisconnect(int client)
{
    
g_plyrFireScreamCoolDown[client] = 0.0;
    
g_plyrGrenScreamCoolDown[client] = 0.0;
}

public 
OnEntityCreated(entity, const String:classname[])
{

    if (
StrEqual(classname"grenade_m67") || StrEqual(classname"grenade_f1"))
        {
        
CreateTimer(0.2GrenadeScreamCheckTimerentityTIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
        }
    else if (
StrEqual(classname"grenade_molotov") || StrEqual(classname"grenade_anm14"))
        {
        
CreateTimer(0.2FireScreamCheckTimerentityTIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
        }

}
public 
Action:FireScreamCheckTimer(Handle:timerany:entity)
{
    new 
Float:fGrenOrigin[3];
    new 
Float:fPlayerOrigin[3];
    new 
Float:fPlayerEyeOrigin[3];
    new 
owner;
    if (
IsValidEntity(entity) && entity 0)
    {
        
GetEntPropVector(entityProp_Send"m_vecOrigin"fGrenOrigin);
        
owner GetEntPropEnt(entityProp_Send"m_hOwnerEntity");
    }
    else
        
KillTimer(timer);




    for (new 
client 1;client <= MaxClients;client++)
    {
        if (
client <= || !IsClientInGame(client) || !IsClientConnected(client))
            continue;
        if (
owner <= || !IsClientInGame(owner) || !IsClientConnected(owner))
            continue;
        if (
IsFakeClient(client))
            continue;

        if (
IsPlayerAlive(client) && GetClientTeam(client) == && GetClientTeam(owner) == 3)
        {

            
GetClientEyePosition(clientfPlayerEyeOrigin);
            
GetClientAbsOrigin(client,fPlayerOrigin);
            
//new Handle:trace = TR_TraceRayFilterEx(fPlayerEyeOrigin, fGrenOrigin, MASK_SOLID_BRUSHONLY, RayType_EndPoint, Base_TraceFilter);
            
            
if (g_plyrFireScreamCoolDown[client] != 0.0 && GetGameTime() - g_plyrFireScreamCoolDown[client] < 5.0// 5 seconds cooldown
                
continue;

            
//if (GetVectorDistance(fPlayerOrigin, fGrenOrigin) <= 320 &&  g_plyrFireScreamCoolDown[client] <= 0)// && TR_DidHit(trace) && fGrenOrigin[2] > 0)
            
if (GetVectorDistance(fPlayerOriginfGrenOrigin) <= 320)// && TR_DidHit(trace) && fGrenOrigin[2] > 0)
            
{
                
//PrintToServer("SCREAM FIRE");
                
PlayerFireScreamRand(client);
                new 
fRandomInt GetRandomInt(25);
                
//g_plyrFireScreamCoolDown[client] = fRandomInt;
                
g_plyrFireScreamCoolDown[client] = GetGameTime();
                
//CloseHandle(trace);
            
}
        }
    }

    if (!
IsValidEntity(entity) || !(entity 0))
        
KillTimer(timer);
}
public 
Action:GrenadeScreamCheckTimer(Handle:timerany:entity)
{
    new 
Float:fGrenOrigin[3];
    new 
Float:fPlayerOrigin[3];
    new 
Float:fPlayerEyeOrigin[3];
    new 
owner;
    if (
IsValidEntity(entity) && entity 0)
    {
        
GetEntPropVector(entityProp_Send"m_vecOrigin"fGrenOrigin);
        
owner GetEntPropEnt(entityProp_Send"m_hOwnerEntity");
    }
    else
        
KillTimer(timer);

    for (new 
client 1;client <= MaxClients;client++)
    {
        if (
client <= || !IsClientInGame(client) || !IsClientConnected(client))
            continue;

        if (
IsFakeClient(client))
            continue;

        
//if (IsPlayerAlive(client) && GetClientTeam(client) == 2 && GetClientTeam(owner) == 3)
        
if (client && IsPlayerAlive(client) && GetClientTeam(client) == && GetClientTeam(owner) == 3)
        {

            
GetClientEyePosition(clientfPlayerEyeOrigin);
            
GetClientAbsOrigin(client,fPlayerOrigin);
            
//new Handle:trace = TR_TraceRayFilterEx(fPlayerEyeOrigin, fGrenOrigin, MASK_VISIBLE, RayType_EndPoint, Base_TraceFilter);

            
if (g_plyrGrenScreamCoolDown[client] != 0.0 && GetGameTime() - g_plyrGrenScreamCoolDown[client] < 5.0// 5 seconds cooldown
                
continue;

            
//if (GetVectorDistance(fPlayerOrigin, fGrenOrigin) <= 450 &&  g_plyrGrenScreamCoolDown[client] <= 0)// && TR_DidHit(trace) && fGrenOrigin[2] > 0)
            
if (GetVectorDistance(fPlayerOriginfGrenOrigin) <= 450)// && TR_DidHit(trace) && fGrenOrigin[2] > 0)
            
{
                
PlayerGrenadeScreamRand(client);
                new 
fRandomInt GetRandomInt(13);
                
//g_plyrGrenScreamCoolDown[client] = fRandomInt;
                
g_plyrGrenScreamCoolDown[client] = GetGameTime();
                
//CloseHandle(trace);
            
}
        }
    }

    if (!
IsValidEntity(entity) || !(entity 0))
        
KillTimer(timer);

Attached Files
File Type: sp Get Plugin or Get Source (ins_yells_grenade.sp - 41 views - 6.0 KB)
__________________

Last edited by Marttt; 03-06-2022 at 06:50.
Marttt is offline
Camaro12345678
New Member
Join Date: Sep 2017
Old 03-06-2022 , 15:47   Re: I need help with a plugin error "Exception reported: Client index 0 is invalid"
Reply With Quote #6

Quote:
Originally Posted by Marttt View Post
you second problem is code logic here:

g_plyrGrenScreamCoolDown[client]
g_plyrFireScreamCoolDown[client]

once the variable is set, you code won't run for that client again because you always check if g_plyrFireScreamCoolDown[client] <= 0 / g_plyrFireScreamCoolDown[client] <= 0, and once set the check will always fail cause you don't reset

try this code:

PHP Code:
//#pragma dynamic 32768    // Increase heap size
#pragma semicolon 1

public Plugin myinfo = {
    
name        "[INS] Yells Grenade",
    
author        "",
    
description    "Yells at nearby Grenades and Molotov",
    
version        "2.0",
    
url            ""
};

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <insurgencydy>
#include <smlib>

#define INVALID_USERID 0

// Status
new

    
g_plyrGrenScreamCoolDown[MAXPLAYERS+1];
    
g_plyrFireScreamCoolDown[MAXPLAYERS+1];


public 
OnMapStart()
{

    
//Grenade Call Out
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade9.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade9.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade4.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade4.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade35.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade34.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade33.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade23.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade2.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade13.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade12.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade11.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade10.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade18.ogg");

    
//Molotov/Incen Callout
    
PrecacheSound("player/voice/responses/security/subordinate/damage/molotov_incendiary_detonated7.ogg");
    
PrecacheSound("player/voice/responses/security/leader/damage/molotov_incendiary_detonated6.ogg");
    
PrecacheSound("player/voice/responses/security/subordinate/damage/molotov_incendiary_detonated6.ogg");
    
PrecacheSound("player/voice/responses/security/leader/damage/molotov_incendiary_detonated5.ogg");
    
PrecacheSound("player/voice/responses/security/leader/damage/molotov_incendiary_detonated4.ogg");

}

public 
void OnClientDisconnect(int client)
{
    
g_plyrFireScreamCoolDown[client] = 0.0;
    
g_plyrGrenScreamCoolDown[client] = 0.0;
}

public 
OnEntityCreated(entity, const String:classname[])
{

    if (
StrEqual(classname"grenade_m67") || StrEqual(classname"grenade_f1"))
        {
        
CreateTimer(0.2GrenadeScreamCheckTimerentityTIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
        }
    else if (
StrEqual(classname"grenade_molotov") || StrEqual(classname"grenade_anm14"))
        {
        
CreateTimer(0.2FireScreamCheckTimerentityTIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
        }

}
public 
Action:FireScreamCheckTimer(Handle:timerany:entity)
{
    new 
Float:fGrenOrigin[3];
    new 
Float:fPlayerOrigin[3];
    new 
Float:fPlayerEyeOrigin[3];
    new 
owner;
    if (
IsValidEntity(entity) && entity 0)
    {
        
GetEntPropVector(entityProp_Send"m_vecOrigin"fGrenOrigin);
        
owner GetEntPropEnt(entityProp_Send"m_hOwnerEntity");
    }
    else
        
KillTimer(timer);




    for (new 
client 1;client <= MaxClients;client++)
    {
        if (
client <= || !IsClientInGame(client) || !IsClientConnected(client))
            continue;
        if (
owner <= || !IsClientInGame(owner) || !IsClientConnected(owner))
            continue;
        if (
IsFakeClient(client))
            continue;

        if (
IsPlayerAlive(client) && GetClientTeam(client) == && GetClientTeam(owner) == 3)
        {

            
GetClientEyePosition(clientfPlayerEyeOrigin);
            
GetClientAbsOrigin(client,fPlayerOrigin);
            
//new Handle:trace = TR_TraceRayFilterEx(fPlayerEyeOrigin, fGrenOrigin, MASK_SOLID_BRUSHONLY, RayType_EndPoint, Base_TraceFilter);
            
            
if (g_plyrFireScreamCoolDown[client] != 0.0 && GetGameTime() - g_plyrFireScreamCoolDown[client] < 5.0// 5 seconds cooldown
                
continue;

            
//if (GetVectorDistance(fPlayerOrigin, fGrenOrigin) <= 320 &&  g_plyrFireScreamCoolDown[client] <= 0)// && TR_DidHit(trace) && fGrenOrigin[2] > 0)
            
if (GetVectorDistance(fPlayerOriginfGrenOrigin) <= 320)// && TR_DidHit(trace) && fGrenOrigin[2] > 0)
            
{
                
//PrintToServer("SCREAM FIRE");
                
PlayerFireScreamRand(client);
                new 
fRandomInt GetRandomInt(25);
                
//g_plyrFireScreamCoolDown[client] = fRandomInt;
                
g_plyrFireScreamCoolDown[client] = GetGameTime();
                
//CloseHandle(trace);
            
}
        }
    }

    if (!
IsValidEntity(entity) || !(entity 0))
        
KillTimer(timer);
}
public 
Action:GrenadeScreamCheckTimer(Handle:timerany:entity)
{
    new 
Float:fGrenOrigin[3];
    new 
Float:fPlayerOrigin[3];
    new 
Float:fPlayerEyeOrigin[3];
    new 
owner;
    if (
IsValidEntity(entity) && entity 0)
    {
        
GetEntPropVector(entityProp_Send"m_vecOrigin"fGrenOrigin);
        
owner GetEntPropEnt(entityProp_Send"m_hOwnerEntity");
    }
    else
        
KillTimer(timer);

    for (new 
client 1;client <= MaxClients;client++)
    {
        if (
client <= || !IsClientInGame(client) || !IsClientConnected(client))
            continue;

        if (
IsFakeClient(client))
            continue;

        
//if (IsPlayerAlive(client) && GetClientTeam(client) == 2 && GetClientTeam(owner) == 3)
        
if (client && IsPlayerAlive(client) && GetClientTeam(client) == && GetClientTeam(owner) == 3)
        {

            
GetClientEyePosition(clientfPlayerEyeOrigin);
            
GetClientAbsOrigin(client,fPlayerOrigin);
            
//new Handle:trace = TR_TraceRayFilterEx(fPlayerEyeOrigin, fGrenOrigin, MASK_VISIBLE, RayType_EndPoint, Base_TraceFilter);

            
if (g_plyrGrenScreamCoolDown[client] != 0.0 && GetGameTime() - g_plyrGrenScreamCoolDown[client] < 5.0// 5 seconds cooldown
                
continue;

            
//if (GetVectorDistance(fPlayerOrigin, fGrenOrigin) <= 450 &&  g_plyrGrenScreamCoolDown[client] <= 0)// && TR_DidHit(trace) && fGrenOrigin[2] > 0)
            
if (GetVectorDistance(fPlayerOriginfGrenOrigin) <= 450)// && TR_DidHit(trace) && fGrenOrigin[2] > 0)
            
{
                
PlayerGrenadeScreamRand(client);
                new 
fRandomInt GetRandomInt(13);
                
//g_plyrGrenScreamCoolDown[client] = fRandomInt;
                
g_plyrGrenScreamCoolDown[client] = GetGameTime();
                
//CloseHandle(trace);
            
}
        }
    }

    if (!
IsValidEntity(entity) || !(entity 0))
        
KillTimer(timer);

I got errors back in the terminal and tag mismatch errors at compile with this code, lines 57,58,115,159 basically all the ones that contains the screamcooldowns.

I managed to clean the terminal errors with your previous post but, still a dead end loop and mismatch errors.

PHP Code:
//#pragma dynamic 32768    // Increase heap size
#pragma semicolon 1

public Plugin myinfo = {
    
name        "[INS] Yells Grenade",
    
author        "",
    
description    "Yells at nearby Grenades and Molotov",
    
version        "2.0",
    
url            ""
};

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <insurgencydy>
#include <smlib>

#define INVALID_USERID 0

// Status
new

    
g_plyrGrenScreamCoolDown[MAXPLAYERS+1];
    
g_plyrFireScreamCoolDown[MAXPLAYERS+1];


public 
OnMapStart()
{

    
//Grenade Call Out
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade9.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade9.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade4.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade4.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade35.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade34.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade33.ogg");
    
PrecacheSound("player/voice/botsurvival/subordinate/incominggrenade23.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade2.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade13.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade12.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade11.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade10.ogg");
    
PrecacheSound("player/voice/botsurvival/leader/incominggrenade18.ogg");

    
//Molotov/Incen Callout
    
PrecacheSound("player/voice/responses/security/subordinate/damage/molotov_incendiary_detonated7.ogg");
    
PrecacheSound("player/voice/responses/security/leader/damage/molotov_incendiary_detonated6.ogg");
    
PrecacheSound("player/voice/responses/security/subordinate/damage/molotov_incendiary_detonated6.ogg");
    
PrecacheSound("player/voice/responses/security/leader/damage/molotov_incendiary_detonated5.ogg");
    
PrecacheSound("player/voice/responses/security/leader/damage/molotov_incendiary_detonated4.ogg");

}

public 
void OnClientDisconnect(int client)
{
    
g_plyrFireScreamCoolDown[client] = 0.0;
    
g_plyrGrenScreamCoolDown[client] = 0.0;
}

public 
OnEntityCreated(entity, const String:classname[])
{

    if (
StrEqual(classname"grenade_m67") || StrEqual(classname"grenade_f1"))
        {
        
CreateTimer(0.2GrenadeScreamCheckTimerentityTIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
        }
    else if (
StrEqual(classname"grenade_molotov") || StrEqual(classname"grenade_anm14"))
        {
        
CreateTimer(0.2FireScreamCheckTimerentityTIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
        }

}
public 
Action:FireScreamCheckTimer(Handle:timerany:entity)
{
    new 
Float:fGrenOrigin[3];
    new 
Float:fPlayerOrigin[3];
    new 
Float:fPlayerEyeOrigin[3];
    new 
owner;
    if (
IsValidEntity(entity) && entity 0)
    {
        
GetEntPropVector(entityProp_Send"m_vecOrigin"fGrenOrigin);
        
owner GetEntPropEnt(entityProp_Send"m_hOwnerEntity");
    }
    else
        
KillTimer(timer);




    for (new 
client 1;client <= MaxClients;client++)
    {
        if (
client <= || !IsClientInGame(client) || !IsClientConnected(client))
            continue;
        if (
owner <= || !IsClientInGame(owner) || !IsClientConnected(owner))
            continue;
        if (
IsFakeClient(client))
            continue;

        if (
IsPlayerAlive(client) && GetClientTeam(client) == && <= owner <= MaxClients && IsClientInGame(owner) && GetClientTeam(owner) == 3)
        {

            
GetClientEyePosition(clientfPlayerEyeOrigin);
            
GetClientAbsOrigin(client,fPlayerOrigin);

            
            if (
g_plyrFireScreamCoolDown[client] != 0.0 && GetGameTime() - g_plyrFireScreamCoolDown[client] < 5.0// 5 seconds cooldown
                
continue;


            if (
GetVectorDistance(fPlayerOriginfGrenOrigin) <= 320)
            {
                
//PrintToServer("SCREAM FIRE");
                
PlayerFireScreamRand(client);
                
g_plyrFireScreamCoolDown[client] = GetGameTime();
                
//CloseHandle(trace);
            
}
        }
    }

    if (!
IsValidEntity(entity) || !(entity 0))
        
KillTimer(timer);
}
public 
Action:GrenadeScreamCheckTimer(Handle:timerany:entity)
{
    new 
Float:fGrenOrigin[3];
    new 
Float:fPlayerOrigin[3];
    new 
Float:fPlayerEyeOrigin[3];
    new 
owner;
    if (
IsValidEntity(entity) && entity 0)
    {
        
GetEntPropVector(entityProp_Send"m_vecOrigin"fGrenOrigin);
        
owner GetEntPropEnt(entityProp_Send"m_hOwnerEntity");
    }
    else
        
KillTimer(timer);

    for (new 
client 1;client <= MaxClients;client++)
    {
        if (
client <= || !IsClientInGame(client) || !IsClientConnected(client))
            continue;

        if (
IsFakeClient(client))
            continue;

        if (
IsPlayerAlive(client) && GetClientTeam(client) == && <= owner <= MaxClients && IsClientInGame(owner) && GetClientTeam(owner) == 3)
        {

            
GetClientEyePosition(clientfPlayerEyeOrigin);
            
GetClientAbsOrigin(client,fPlayerOrigin);
            

            if (
g_plyrGrenScreamCoolDown[client] != 0.0 && GetGameTime() - g_plyrGrenScreamCoolDown[client] < 5.0// 5 seconds cooldown
                
continue;

            if (
GetVectorDistance(fPlayerOriginfGrenOrigin) <= 450)
            {
                
PlayerGrenadeScreamRand(client);
                
g_plyrGrenScreamCoolDown[client] = GetGameTime();

            }
        }
    }

    if (!
IsValidEntity(entity) || !(entity 0))
        
KillTimer(timer);

Camaro12345678 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 03-06-2022 , 16:54   Re: I need help with a plugin error "Exception reported: Client index 0 is invalid"
Reply With Quote #7

tag mismatch, just change "new" declaration to "float"

new
g_plyrGrenScreamCoolDown[MAXPLAYERS+1];
g_plyrFireScreamCoolDown[MAXPLAYERS+1];

float g_plyrGrenScreamCoolDown[MAXPLAYERS+1];
float g_plyrFireScreamCoolDown[MAXPLAYERS+1];

anyway I can't test cause I don't have insurgency installed
better way to find why something is not working is outputting some debug info to the chat
__________________
Marttt is offline
Camaro12345678
New Member
Join Date: Sep 2017
Old 03-06-2022 , 19:16   Re: I need help with a plugin error "Exception reported: Client index 0 is invalid"
Reply With Quote #8

Quote:
Originally Posted by Marttt View Post
tag mismatch, just change "new" declaration to "float"

new
g_plyrGrenScreamCoolDown[MAXPLAYERS+1];
g_plyrFireScreamCoolDown[MAXPLAYERS+1];

float g_plyrGrenScreamCoolDown[MAXPLAYERS+1];
float g_plyrFireScreamCoolDown[MAXPLAYERS+1];

anyway I can't test cause I don't have insurgency installed
better way to find why something is not working is outputting some debug info to the chat
Sir. You are a gentleman and a scholar, it works perfectly fine now. I had tried using float but i forgot to remove "new"

Thank you so much for the help Marttt, also @NoroHime for the pointer, i should dive in soucepawn at sometime and stop embarrassing myself.

Anyway, thank you and have a nice day.
Camaro12345678 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 22:01.


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