New Member
|
03-06-2022
, 15:47
Re: I need help with a plugin error "Exception reported: Client index 0 is invalid"
|
#6
|
Quote:
Originally Posted by Marttt
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.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 (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(fPlayerOrigin, fGrenOrigin) <= 320)// && TR_DidHit(trace) && fGrenOrigin[2] > 0)
{
//PrintToServer("SCREAM FIRE");
PlayerFireScreamRand(client);
new fRandomInt = GetRandomInt(2, 5);
//g_plyrFireScreamCoolDown[client] = fRandomInt;
g_plyrFireScreamCoolDown[client] = GetGameTime();
//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 (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(fPlayerOrigin, fGrenOrigin) <= 450)// && TR_DidHit(trace) && fGrenOrigin[2] > 0)
{
PlayerGrenadeScreamRand(client);
new fRandomInt = GetRandomInt(1, 3);
//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.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 && 1 <= owner <= MaxClients && IsClientInGame(owner) && GetClientTeam(owner) == 3)
{
GetClientEyePosition(client, fPlayerEyeOrigin);
GetClientAbsOrigin(client,fPlayerOrigin);
if (g_plyrFireScreamCoolDown[client] != 0.0 && GetGameTime() - g_plyrFireScreamCoolDown[client] < 5.0) // 5 seconds cooldown
continue;
if (GetVectorDistance(fPlayerOrigin, fGrenOrigin) <= 320)
{
//PrintToServer("SCREAM FIRE");
PlayerFireScreamRand(client);
g_plyrFireScreamCoolDown[client] = GetGameTime();
//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 && 1 <= owner <= MaxClients && IsClientInGame(owner) && GetClientTeam(owner) == 3)
{
GetClientEyePosition(client, fPlayerEyeOrigin);
GetClientAbsOrigin(client,fPlayerOrigin);
if (g_plyrGrenScreamCoolDown[client] != 0.0 && GetGameTime() - g_plyrGrenScreamCoolDown[client] < 5.0) // 5 seconds cooldown
continue;
if (GetVectorDistance(fPlayerOrigin, fGrenOrigin) <= 450)
{
PlayerGrenadeScreamRand(client);
g_plyrGrenScreamCoolDown[client] = GetGameTime();
}
}
}
if (!IsValidEntity(entity) || !(entity > 0))
KillTimer(timer);
}
|
|