View Single Post
Author Message
Vespa
New Member
Join Date: Dec 2020
Old 04-07-2021 , 12:07   Exception Array index out-of-bounds
Reply With Quote #1

Hi, I'm totally new in SourcePawn language, so I'm trying to learn and understand the language and scripting.
In my server I have a plugin that arise the following errors in log file:
Code:
SourceMod error session started
L 04/06/2021 - 20:03:18: Info (map "embassy_coop") (file "/home/insserver/serverfiles/insurgency/addons/sourcemod/logs/errors_20210406.log")
L 04/06/2021 - 20:03:18: [SM] Exception reported: Array index out-of-bounds (index -1, limit 13)
L 04/06/2021 - 20:03:18: [SM] Blaming: c_dy_respawn_naong_ai_director_S3.smx
L 04/06/2021 - 20:03:18: [SM] Call stack trace:
L 04/06/2021 - 20:03:18: [SM]   [1] Line 2200, c_dy_respawn_naong_ai_director_S3.sp::Timer_CheckEnemyAway
So I check the director plugin to find the issue...
The Timer_CheckEnemyAway is defined here:
Code:
CreateTimer(1.0, Timer_CheckEnemyAway,_ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
after that, it's called in the following function:
Code:
// Check enemy is stuck
public Action:Timer_CheckEnemyAway(Handle:Timer)
{
	//Remove bot weapons when static killed to reduce server performance on dropped items.
	new primaryRemove = 1, secondaryRemove = 1, grenadesRemove = 1;
	// Check round state
	if (g_iRoundStatus == 0) return Plugin_Continue;
	
	if (Ins_InCounterAttack())
	{
		g_checkStaticAmtCntrAway = g_checkStaticAmtCntrAway - 1;
		if (g_checkStaticAmtCntrAway <= 0)
		{
			for (new enemyBot = 1; enemyBot <= MaxClients; enemyBot++)
			{	
				if (IsClientInGame(enemyBot) && IsFakeClient(enemyBot))
				{
					new m_iTeam = GetClientTeam(enemyBot);
					if (IsPlayerAlive(enemyBot) && m_iTeam == TEAM_2_INS)
					{
						// Get current position
						decl Float:enemyPos[3];
						GetClientAbsOrigin(enemyBot, Float:enemyPos);
						
						// Get distance
						new Float:tDistance;
						new Float:capDistance;
						tDistance = GetVectorDistance(enemyPos, g_enemyTimerAwayPos[enemyBot]);
						if (g_isCheckpoint == 1)
						{
							new m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
							Ins_ObjectiveResource_GetPropVector("m_vCPPositions",m_vCPPositions[m_nActivePushPointIndex],m_nActivePushPointIndex);
							capDistance = GetVectorDistance(enemyPos,m_vCPPositions[m_nActivePushPointIndex]);
						}
						else 
							capDistance = 801;
						// If enemy position is static, kill him
						if (tDistance <= 150 && capDistance > 2500) 
						{
							//PrintToServer("ENEMY STATIC - KILLING");
							RemoveWeapons(enemyBot, primaryRemove, secondaryRemove, grenadesRemove);
							ForcePlayerSuicide(enemyBot);
							AddLifeForStaticKilling(enemyBot);
						}
						// Update current position
						else
						{
							g_enemyTimerAwayPos[enemyBot] = enemyPos;
						}
					}
				}
			}
			g_checkStaticAmtCntrAway = 12;
		}
	}
	else
	{
		g_checkStaticAmtAway = g_checkStaticAmtAway - 1;
		if (g_checkStaticAmtAway <= 0)
		{
			for (new enemyBot = 1; enemyBot <= MaxClients; enemyBot++)
			{	
				if (IsClientInGame(enemyBot) && IsFakeClient(enemyBot))
				{
					new m_iTeam = GetClientTeam(enemyBot);
					if (IsPlayerAlive(enemyBot) && m_iTeam == TEAM_2_INS)
					{
						// Get current position
						decl Float:enemyPos[3];
						GetClientAbsOrigin(enemyBot, Float:enemyPos);
						
						// Get distance
						new Float:tDistance;
						new Float:capDistance;
						tDistance = GetVectorDistance(enemyPos, g_enemyTimerAwayPos[enemyBot]);
						//Check point distance
						if (g_isCheckpoint == 1)
						{
							new m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
							Ins_ObjectiveResource_GetPropVector("m_vCPPositions",m_vCPPositions[m_nActivePushPointIndex],m_nActivePushPointIndex);
							capDistance = GetVectorDistance(enemyPos,m_vCPPositions[m_nActivePushPointIndex]);
						}
						// If enemy position is static, kill him
						if (tDistance <= 150 && capDistance > 1200) 
						{
							//PrintToServer("ENEMY STATIC - KILLING");
							RemoveWeapons(enemyBot, primaryRemove, secondaryRemove, grenadesRemove);
							ForcePlayerSuicide(enemyBot);
							AddLifeForStaticKilling(enemyBot);
						}
						// Update current position
						else
						{ 
							g_enemyTimerAwayPos[enemyBot] = enemyPos;
						}
					}
				}
			}
			g_checkStaticAmtAway = 30; 
		}
	}
	
	return Plugin_Continue;
}
I don't understand what's the array causing the error...any hint to fix the issue? Thanks a lot for any help

Last edited by Vespa; 04-07-2021 at 12:12.
Vespa is offline