Raised This Month: $32 Target: $400
 8% 

Run time error 4: index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-03-2016 , 10:38   Re: Run time error 4: index out of bounds
Reply With Quote #11

I wrote that using 1.8.3 with no warnings. I've seen that the 1.8.2 compiler complains more. I will adjust this so it compiles clean in 1.8.2.

An easy fix us to prefix your enums with _:

enum _:Something
{
__________________

Last edited by Bugsy; 11-03-2016 at 10:40.
Bugsy is online now
BeNq!
Senior Member
Join Date: Mar 2009
Old 11-03-2016 , 11:54   Re: Run time error 4: index out of bounds
Reply With Quote #12

Ok. I have ncod_class_cybersuit_p ( cod mod class ):

Code:
public ncod_classChangeState( id, iClass, NCodState:iState )
{
	switch( iState )
	{
		case NCODSTATE_DISABLE: {
			gbHasClass[ id ] = false;
			ncod_setUserStatist(id, NCODSTATIST_HEALTH, 0)
		}
		
		case NCODSTATE_ENABLE: {
			gbHasClass[ id ] = true;
			ncod_setUserStatist(id, NCODSTATIST_HEALTH, 20)
		}
        }
}
and

Code:
L 11/03/2016 - 16:49:42: [NCodMod_engine.amxx] [ unknown < ncod_class_cybersuit_p.amxx > ]: Bad param values33333!
Code:
// ncod_setUserStats( id, NCodStatist: iStatist, iValue )
public nativeSetUserStatist( iPlugin, iParams )
{
    new iParam1 = get_param( 1 );
    new iParam2 = get_param( 2 );
    new szPlugin[ 2 ][ 64 ];
    
    if( iParams != 3 )
    {
        get_plugin( iPlugin, szPlugin[ 0 ], 63, szPlugin[ 1 ], 63 );
        log_amx( "[ %s < %s > ]: Blad przy pobieraniu wartosci statystyki!", szPlugin[ 1 ], szPlugin[ 0 ] );
        return -1;
    }
    else if ( ( iParam1 >= sizeof( gPlayerInfo ) )) 
    {
        get_plugin( iPlugin, szPlugin[ 0 ], 63, szPlugin[ 1 ], 63 );
        log_amx( "[ %s < %s > ]: Bad param values1111!", szPlugin[ 1 ], szPlugin[ 0 ] );
        return -1;    
    }
    else if ( iParam2 >= sizeof( giStatistics ) ) 
    {
        get_plugin( iPlugin, szPlugin[ 0 ], 63, szPlugin[ 1 ], 63 );
        log_amx( "[ %s < %s > ]: Bad param values22222!", szPlugin[ 1 ], szPlugin[ 0 ] );
        return -1;    
    }
    else if ( _:giStatistics[ iParam2 ] >= sizeof( gPlayerInfo ) )
    {
        get_plugin( iPlugin, szPlugin[ 0 ], 63, szPlugin[ 1 ], 63 );
        log_amx( "[ %s < %s > ]: Bad param values33333!", szPlugin[ 1 ], szPlugin[ 0 ] );
        return -1;    
    }
    
    

    if( any: get_param( 2 ) != NCODSTATIST_LEVEL )
    {
        gPlayerInfo[ iParam1 ][ playerInfo: giStatistics[ _:NCodStatist: iParam2 ] ] = get_param( 3 );
    }
    else
    {
        gPlayerInfo[ iParam1 ][ playerInfo: giStatistics[ NCODSTATIST_EXPERIENCE ] ] = power( get_param( 3 ), 2 ) * gPluginInfo[ plExperienceMultiplier ];
        gPlayerInfo[ iParam1 ][ playerInfo: giStatistics[ NCODSTATIST_LEVEL ] ] = get_param( 3 );
    }
    
    return 0;
}
Code:
/**
 * Pobiera wartosc statystyki
 *
 * @type					native
 *
 * @param id				Index gracza
 * @param iStatist			Index statystyki ( patrz: struktura NCodStatist )
 *
 * @return					Zwraca wartosc statystyki
 */
native ncod_getUserStatist( id, NCodStatist: iStatist );

/**
 * Ustawia wartosc statystyki
 *
 * @type 					native
 *
 * @param id				Index gracza
 * @param iStatist			Index statystyki ( patrz: struktura NCodStatist )
 * @param iValue			Wartosc do ustawienia
 *
 * @return					Zwraca 0 jezeli sie powiedzie, badz -1 jezeli sie nie powiedzie
 */
native ncod_setUserStatist( id, NCodStatist: iStatist, iValue );

/**
 * Dodaje wartosc do statystyki
 *
 * @type 					define
 *
 * @param id				Index gracza
 * @param iStatist			Index statystyki ( patrz: struktura NCodStatist )
 * @param iValue			Wartosc do ustawienia
 *
 * @return					Zwraca 0 jezeli sie powiedzie, badz -1 jezeli sie nie powiedzie
 */
#define ncod_addToUserStatist(%1,%2,%3) ncod_setUserStatist(%1,%2,ncod_getUserStatist(%1,%2)+%3)
How to fix?

Last edited by BeNq!; 11-03-2016 at 11:54.
BeNq! is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-03-2016 , 20:14   Re: Run time error 4: index out of bounds
Reply With Quote #13

You will need to locate the enums and then add the _:. I am not familiar with that mod nor do I know where to get it so I cannot help. If you link me I can help.
__________________
Bugsy is online now
BeNq!
Senior Member
Join Date: Mar 2009
Old 11-03-2016 , 23:41   Re: Run time error 4: index out of bounds
Reply With Quote #14

I put in the first post files .sma and .inc. Have you steam?
BeNq! is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-05-2016 , 11:28   Re: Run time error 4: index out of bounds
Reply With Quote #15

Quote:
Originally Posted by BeNq! View Post
I put in the first post files .sma and .inc. Have you steam?
Try this: https://forums.alliedmods.net/showpo...94&postcount=7
__________________
Bugsy is online now
BeNq!
Senior Member
Join Date: Mar 2009
Old 11-05-2016 , 15:15   Re: Run time error 4: index out of bounds
Reply With Quote #16

Nope. Didn't work:

Code:
#include <amxmodx>
#include <engine>
#include < fakemeta_util >
#include <hamsandwich>

#include < ncodmod.inc >

new const MODEL_ROCKET[] = "models/rpgrocket.mdl"

new giSprite;

new skoki[33];
new bool:gbHasClass[ 33 ] = false;

new ilosc_rakiet_gracza[ 33 ] = { 0 };
new Float:gfNextAttack[ 33 ];

public plugin_init(){	
	ncod_registerClass( 
		"Cybersuit",
		"[PREMIUM] Ma 3 rakiety, zmniejszona widocznosc i grawitacja oraz poczworny skok",
		0, 0, 0, 0,
		(1<<CSW_HEGRENADE)|(1<<CSW_SMOKEGRENADE)|(1<<CSW_M4A1)|(1<<CSW_FLASHBANG), 
		NCODTEAM_ALL
	);
	
	register_forward( FM_Touch, "fwTouch" );
	register_forward(FM_CmdStart, "fwCmdStart_MultiJump");
}

public plugin_precache(){
	giSprite = precache_model( "sprites/blast.spr" ) ;
	precache_model(MODEL_ROCKET);
}

public ncod_classChangeState( id, iClass, NCodState:iState )
{
	switch( iState )
	{
		case NCODSTATE_DISABLE: {
			gbHasClass[ id ] = false;
			ncod_setUserStatist(id, NCODSTATIST_HEALTH, 0)
			
			ilosc_rakiet_gracza[id] = 0;
			fm_set_user_rendering(id,kRenderFxNone, 0, 0, 0, kRenderTransAlpha, 255);
			entity_set_float(id, EV_FL_gravity, 1.0);
		}
		
		case NCODSTATE_ENABLE: {
			gbHasClass[ id ] = true;
			ncod_setUserStatist(id, NCODSTATIST_HEALTH, 20)
			
			fm_set_user_rendering(id,kRenderFxNone, 0, 0, 0, kRenderTransAlpha, 100);
			entity_set_float(id, EV_FL_gravity, 600.0/800.0);
			
			ilosc_rakiet_gracza[id] = 3;
		}
		
		case NCODSTATE_SPAWN: {
			fm_set_user_rendering(id,kRenderFxNone, 0, 0, 0, kRenderTransAlpha, 100);
			ilosc_rakiet_gracza[id] = 3;
			entity_set_float(id, EV_FL_gravity, 600.0/800.0);
		}
		
		case NCODSTATE_USE: 
		{
			if( !is_user_alive( id ) )
				return ;
			
			if( !ilosc_rakiet_gracza[ id ] )
			{
				ncod_printInformation( id, NCODINFOTYPE_CHAT, NCODINFOCOLOR_NORMAL, "Rakiet sie skonczyly!" );
				return;
				
			}
			if( gfNextAttack[ id ] >= get_gametime() )
			{
				ncod_printInformation( id, NCODINFOTYPE_CHAT, NCODINFOCOLOR_NORMAL, "Rakiet mozesz uzywac co 2 sekundy!" );
			}
			else
			{
				gfNextAttack[ id ] = get_gametime() + 2.0;
				ilosc_rakiet_gracza[ id ] --;
				
				new Float: fTemp[ 3 ];
				
				new iRocket = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "info_target" ) );
				set_pev( iRocket, pev_classname, "ncod_rocket" );
				engfunc( EngFunc_SetModel, iRocket, "models/rpgrocket.mdl" );
				
				pev( id, pev_v_angle, fTemp );
				fTemp[ 0 ] *= -1.0;
				set_pev( iRocket, pev_angles, fTemp );
				
				pev( id, pev_origin, fTemp );
				set_pev( iRocket, pev_origin, fTemp );
				
				set_pev( iRocket, pev_effects, 2 );
				set_pev( iRocket, pev_solid, SOLID_BBOX );
				set_pev( iRocket, pev_movetype, MOVETYPE_FLY )
				set_pev( iRocket, pev_owner, id )
				
				velocity_by_aim( id, 1000, fTemp );
				set_pev( iRocket, pev_velocity, fTemp );
			}
		}
		
		default: return;
	}
}

public fwTouch( iSomething, iEnt )
{
	if( !pev_valid( iEnt ) )
		return FMRES_IGNORED;
	
	new szClassName[ 33 ];
	pev( iEnt, pev_classname, szClassName, 32 );
	
	if( !equali( szClassName, "ncod_rocket" ) )
		return FMRES_IGNORED;
	
	new iAttacker = pev( iEnt, pev_owner );
	
	if( !gbHasClass[ iAttacker ] )
		return FMRES_IGNORED;
	
	new Float:fOrigin[ 3 ];
	pev( iEnt, pev_origin, fOrigin );
		
	message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
	write_byte( TE_EXPLOSION );
	engfunc( EngFunc_WriteCoord, fOrigin[ 0 ] );
	engfunc( EngFunc_WriteCoord, fOrigin[ 1 ] );
	engfunc( EngFunc_WriteCoord, fOrigin[ 2 ] );
	write_short( giSprite );
	write_byte( 32 );
	write_byte( 20 );
	write_byte( 0 );
	message_end( );
	
	new iPlayer = -1;
	while( ( iPlayer = fm_find_ent_in_sphere( iPlayer, fOrigin, 300.0 ) ) != 0 )
	{
		if( !is_user_alive( iPlayer ) && iPlayer != iAttacker )
			continue;
		
		ExecuteHam( Ham_TakeDamage, iPlayer, iEnt, iAttacker, 25.0, (1<<24) );
	}
	engfunc( EngFunc_RemoveEntity, iEnt );
	
	return HAM_IGNORED;
}

public fwCmdStart_MultiJump(id, uc_handle){
	if(!is_user_alive(id) || !gbHasClass[id])
		return FMRES_IGNORED;
	
	new flags = pev(id, pev_flags);
	
	if((get_uc(uc_handle, UC_Buttons) & IN_JUMP) && !(flags & FL_ONGROUND) && !(pev(id, pev_oldbuttons) & IN_JUMP) && skoki[id])
	{
		skoki[id]--;
		new Float:velocity[3];
		pev(id, pev_velocity,velocity);
		velocity[2] = random_float(265.0,285.0);
		set_pev(id, pev_velocity,velocity);
	}
	else if(flags & FL_ONGROUND)
		skoki[id] = 3;
	
	return FMRES_IGNORED;
}
Code:
L 11/05/2016 - 20:13:05: [AMXX] Displaying debug trace (plugin "NCodMod_engine.amxx")
L 11/05/2016 - 20:13:05: [AMXX] Run time error 4: index out of bounds 
L 11/05/2016 - 20:13:05: [AMXX]    [0] NCodMod_engine.sma::nativeSetUserStatist (line 1248)
L 11/05/2016 - 20:13:05: Unhandled dynamic native error
L 11/05/2016 - 20:13:05: [AMXX] Displaying debug trace (plugin "ncod_class_cybersuit_p.amxx")
L 11/05/2016 - 20:13:05: [AMXX] Run time error 10: native error (native "ncod_setUserStatist")
L 11/05/2016 - 20:13:05: [AMXX]    [0] ncod_class_cybersuit_p.sma::ncod_classChangeState (line 53)
Have you STEAM? I send you IP test-server.

Last edited by BeNq!; 11-05-2016 at 15:17.
BeNq! is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-05-2016 , 15:52   Re: Run time error 4: index out of bounds
Reply With Quote #17

:Shrug:

Did you add any '_:' to the include? If so, remove them.
Code:
Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2013 ITB CompuPhase, AMX Mod X Team

Header size:           3600 bytes
Code size:            55624 bytes
Data size:           193176 bytes
Stack/heap size:      16384 bytes; max. usage is unknown, due to recursion
Total requirements:  268784 bytes
Done.
__________________

Last edited by Bugsy; 11-05-2016 at 15:53.
Bugsy is online now
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 11-05-2016 , 23:17   Re: Run time error 4: index out of bounds
Reply With Quote #18

A small off-topic:

Bugsy, what change the '_:' make before the enum's name?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 11-05-2016 at 23:18.
EFFx is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-06-2016 , 09:05   Re: Run time error 4: index out of bounds
Reply With Quote #19

Quote:
Originally Posted by EFFx View Post
A small off-topic:

Bugsy, what change the '_:' make before the enum's name?
It basically allows you to tag the enum for array sizing purposes but the type/tag checking is not enforced in code.

PHP Code:
#include <amxmodx>

enum Test
{
    
Item1,
    
Item2,
    
Item355 ]
}

new 
tTestTest ];

public 
TestFunc() 
{
    
//Works fine with or without _: since the array was sized with Test and expects one of the enumerators (Item1,Item2,Item3)
    
tTestItem2 ] = 25;
    
    
//Will give a warning without _: because it expects only Item1, Item2, or Item3 passed in the array. The code will still work
    //perfectly since Item2 = 1.
    
tTest] = 25;
    
    
//You can 'type-cast' a value like this to eliminate a warning. These will give warnings if you use _: on the enum
    //because you are telling it to not enforce tag checking yet you are trying to use tagging.
    
tTestTest:] = 25;
    
    new 
iVal 1;
    
tTestTest:iVal ] = 25;

__________________
Bugsy is online now
BeNq!
Senior Member
Join Date: Mar 2009
Old 11-06-2016 , 10:16   Re: Run time error 4: index out of bounds
Reply With Quote #20

Code:
#include < amxmodx >
#include < amxmisc >
#include < nvault >
#include < hamsandwich >
#include < fakemeta_util >
#include < ColorChat2 >
#include < dhudmessage >

#include "ncodmod.inc"

#define inOtherTeam(%1,%2) bool:( get_user_team(%1) != get_user_team(%2) )

enum playerClassInfo 
{
	pciIdentificator,
	pciLevel,
	pciExperience,
	pciHealth,
	pciStrength,
	pciIntelligence,
	pciCondition,
	pciWeapons,
	pciInitialPoints
}

enum playerInfo 
{
	piName[ 33 ],
	piClass[ playerClassInfo ],
	Array: piClasses,
	piPerk,
	piPerkDurability,
	bool: piMenuFirstTime,
	bool: piMenuBlocked,
	piDistributePointsMode,
	Float: piNextEmitSound
}

enum classInfo 
{
	ciName[ 64 ],
	ciDescription[ 128 ],
	ciHealth,
	ciStrength,
	ciIntelligence,
	ciCondition,
	ciWeapons,
	ciTeam,
	ciAccessFlags,
	ciPlugin
}

enum itemInfo
{
	iiName[ 64 ],
	iiDescription[ 128 ],
	iiAccessFlags,
	iiPlugin
}

enum structBuffer
{
	cInfo[ classInfo ],
	iInfo[ itemInfo ],
	bLastC,
	bLastI,
	bHUDAddons[ 768 ]
}

enum structPluginInfo 
{
	plMaxLevel,
	plExperienceMultiplier,
	plMaxStatisticValue,
	plSaveDriver,
	plSaveMode,
	plReloadingSounds,
	plFriendlyFireSounds,
	plMySQLHost[ 128 ],
	plMySQLUser[ 128 ],
	plMySQLPassword[ 128 ],
	plMySQLDatabase[ 128 ],
	plMySQLPrefix[ 128 ]
}

enum structPluginSounds 
{
	psStart,
	psStart2,
	psLevelUp,
	psLevelDegraded,
	psReloading1,
	psReloading2,
	psReloading3,
	psCheckFire1,
	psCheckFire2,
	psCheckFire3,
	psSelectMenuItem,
	psPanicMessage
}

stock const gszStateInfo[ ][ ] =
{
	"Maksymalny poziom Zycia osiagniety!",
	"Maksymalny poziom Wytrzymalosci osiagniety!",
	"Maksymalny poziom Inteligencji osiagniety!",
	"Maksymalny poziom Kondycji osiagniety!"
}

stock const _:giStatistics[ NCodStatist ] = 
{
	ciHealth,
	ciStrength,
	ciIntelligence,
	ciCondition
}
Code:
// ncod_setUserStats( id, NCodStatist: iStatist, iValue )
public nativeSetUserStatist( iPlugin, iParams )
{
    new iParam1 = get_param( 1 );
    new iParam2 = get_param( 2 );
    new szPlugin[ 2 ][ 64 ];
    
    if( iParams != 3 )
    {
        get_plugin( iPlugin, szPlugin[ 0 ], 63, szPlugin[ 1 ], 63 );
        log_amx( "[ %s < %s > ]: Bad params!", szPlugin[ 1 ], szPlugin[ 0 ] );
        return -1;
    }

    if( any: get_param( 2 ) != NCODSTATIST_LEVEL )
    {
        gPlayerInfo[ iParam1 ][ playerInfo: giStatistics[ iParam2 ] ] = get_param( 3 );
    }
    else
    {
        gPlayerInfo[ iParam1 ][ playerInfo: giStatistics[ NCODSTATIST_EXPERIENCE ] ] = power( get_param( 3 ), 2 ) * gPluginInfo[ plExperienceMultiplier ];
        gPlayerInfo[ iParam1 ][ playerInfo: giStatistics[ NCODSTATIST_LEVEL ] ] = get_param( 3 );
    }
    
    return 0;
}
+ .inc:

Code:
#if defined _ncodmod_included
  #endinput
#endif
#define _ncodmod_included

enum NCodState {
	NCODSTATE_DISABLE,
	NCODSTATE_ENABLE,
	NCODSTATE_USE,
	NCODSTATE_SPAWN
}

enum _:NCodStatist
{
	NCODSTATIST_HEALTH,
	NCODSTATIST_STRENGTH,
	NCODSTATIST_INTELLIGENCE,
	NCODSTATIST_CONDITION,
	NCODSTATIST_LEVEL,
	NCODSTATIST_EXPERIENCE
}

enum NCodTeams {
	NCODTEAM_ALL,
	NCODTEAM_TERRORIST,
	NCODTEAM_AMERICA
}

enum NCodInfoType {
	NCODINFOTYPE_CHAT,
	NCODINFOTYPE_HUD,
	NCODINFOTYPE_BOTH
}

enum NCodInfoColor {
	NCODINFOCOLOR_NORMAL,
	NCODINFOCOLOR_INFORMATION,
	NCODINFOCOLOR_WARNING,
	NCODINFOCOLOR_PANIC
}
Error...

Code:
L 11/06/2016 - 16:14:47: Start of error session.
L 11/06/2016 - 16:14:47: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20161106.log")
L 11/06/2016 - 16:14:47: [AMXX] Displaying debug trace (plugin "NCodMod_engine.amxx")
L 11/06/2016 - 16:14:47: [AMXX] Run time error 4: index out of bounds 
L 11/06/2016 - 16:14:47: [AMXX]    [0] NCodMod_engine.sma::nativeSetUserStatist (line 1248)
L 11/06/2016 - 16:14:47: Unhandled dynamic native error
L 11/06/2016 - 16:14:47: [AMXX] Displaying debug trace (plugin "ncod_class_cybersuit_p.amxx")
L 11/06/2016 - 16:14:47: [AMXX] Run time error 10: native error (native "ncod_setUserStatist")
L 11/06/2016 - 16:14:47: [AMXX]    [0] ncod_class_cybersuit_p.sma::ncod_classChangeState (line 53)
I did what you wrote. Still any error.
What is wrong?
BeNq! 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 12:11.


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