SA-MP Forums Archive
[zCMD] Array index out of bonus - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [zCMD] Array index out of bonus (/showthread.php?tid=646741)



[zCMD] Array index out of bonus - None1337 - 22.12.2017

Hello, i get this error

Код:
[21:33:41] [debug] Run time error 4: "Array index out of bounds"
[21:33:41] [debug] AMX backtrace:
[21:33:41] [debug] #0 0003c0b0 in public OnPlayerCommandText (playerid=1, cmdtext[]=@0296f218 "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2") at D:\gamemode\pawno\include\zcmd.inc:94
How can I fix?


Re: [zCMD] Array index out of bonus - Argument - 22.12.2017

where is the code?


Re: [zCMD] Array index out of bonus - rfr - 22.12.2017

did you edit zcmd inc?


Re: [zCMD] Array index out of bonus - None1337 - 22.12.2017

No, I didn't edit.

This is the line:
funcname[pos-1] = tolower(cmdtext[pos]);

code:
Код:
/**********************************
 *                                *
 *   @Author:      ZeeX           *
 *   @Version:     0.3.1          *
 *   @Released:    31/10/2009     *
 *                                *
 **********************************/

#if defined _zcmd_included
	#endinput
#endif	
#define _zcmd_included

#define MAX_FUNC_NAME (32)

#define COMMAND:%1(%2)          \
			forward cmd_%1(%2); \
			public cmd_%1(%2)		
			
#define CMD:%1(%2) \
			COMMAND:%1(%2)

#define command(%1,%2,%3) \
			COMMAND:%1(%2, %3)      
      
#define cmd(%1,%2,%3) \
			COMMAND:%1(%2, %3)

#if !defined isnull
	#define isnull(%1) \
				((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif


forward OnPlayerCommandReceived(playerid, cmdtext[]); 
forward OnPlayerCommandPerformed(playerid, cmdtext[], success); 


static
	bool:zcmd_g_HasOPCS = false,
	bool:zcmd_g_HasOPCE = false;

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
	zcmd_g_HasOPCS = funcidx("OnPlayerCommandReceived") != -1;
	zcmd_g_HasOPCE = funcidx("OnPlayerCommandPerformed") != -1;
    return CallLocalFunction("zcmd_OnFilterScriptInit", "");
}

#if defined _ALS_OnFilterScriptInit
    #undef OnFilterScriptInit
#else
    #define _ALS_OnFilterScriptInit
#endif
#define OnFilterScriptInit zcmd_OnFilterScriptInit
forward zcmd_OnFilterScriptInit();

#else /*not a filterscript*/

public OnGameModeInit()
{
	zcmd_g_HasOPCS = funcidx("OnPlayerCommandReceived") != -1;
	zcmd_g_HasOPCE = funcidx("OnPlayerCommandPerformed") != -1;
	if (funcidx("zcmd_OnGameModeInit") != -1)
	{
		return CallLocalFunction("zcmd_OnGameModeInit", "");
	}	
	return 1;
}

#if defined _ALS_OnGameModeInit
    #undef OnGameModeInit
#else
    #define _ALS_OnGameModeInit
#endif
#define OnGameModeInit zcmd_OnGameModeInit
forward zcmd_OnGameModeInit();

#endif /*if defined FILTERSCRIPT*/

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (zcmd_g_HasOPCS && !CallLocalFunction("OnPlayerCommandReceived", "is", playerid, cmdtext))
    {
        return 1;
    }
    new
        pos,
        funcname[MAX_FUNC_NAME];
    while (cmdtext[++pos] > ' ') 
	{
		funcname[pos-1] = tolower(cmdtext[pos]); 
	}
	format(funcname, sizeof(funcname), "cmd_%s", funcname);
    while (cmdtext[pos] == ' ') pos++;
	if (!cmdtext[pos])
	{
		if (zcmd_g_HasOPCE)
		{
			return CallLocalFunction("OnPlayerCommandPerformed", "isi", playerid, cmdtext, CallLocalFunction(funcname, "is", playerid, "\1"));
		}
		return CallLocalFunction(funcname, "is", playerid, "\1");	
	}
	if (zcmd_g_HasOPCE)
	{
		return CallLocalFunction("OnPlayerCommandPerformed", "isi", playerid, cmdtext, CallLocalFunction(funcname, "is", playerid, cmdtext[pos]));
	}
	return CallLocalFunction(funcname, "is", playerid, cmdtext[pos]);
}

#if defined _ALS_OnPlayerCommandText
    #undef OnPlayerCommandText
#else
    #define _ALS_OnPlayerCommandText
#endif
#define OnPlayerCommandText zcmd_OnPlayerCommandText
forward zcmd_OnPlayerCommandText(playerid, cmdtext[]);



Re: [zCMD] Array index out of bonus - Kwarde - 22.12.2017

When precisely does this error occur? If it only occurs at a certain command we would like to see that command.
Since this bug doesn't appear on compiling it might have been triggered by something else rather than the zcmd include itself


Re: [zCMD] Array index out of bonus - Dayrion - 23.12.2017

CMD's lengh name doesn't should go over 27 characters.
Your example:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2 is 36 letters long


Re: [zCMD] Array index out of bonus - Konstantinos - 23.12.2017

http://forum.sa-mp.com/showpost.php?...&postcount=480
http://forum.sa-mp.com/showpost.php?...&postcount=482


Re: [zCMD] Array index out of bonus - None1337 - 23.12.2017

Thanks for help!
Fixed.