array index out of bounds Error.
#1

Hello,
i have this error:

Код:
: error 032: array index out of bounds (variable "gangname")
This is my code:

Код:
dcmd_makegang(playerid, params[])
{
    new gangname[MAX_GANG_NAME+1];
    if(sscanf(params, "z", gangname))
    return SendClientMessage(playerid, COLOR_GREY, "USAGE: /makegang [gangname]");

	if(PlayerInfo[playerid][pLevel] >= 10)
	{
		new string[92];
		format(string, 92, "%s Has created the gang: %s And is Recruiting!", Playername[playerid], params);
		SendClientMessageToAll(COLOR_RED, string);
		CreateGang(gangname[MAX_GANG_NAME+1], Playername[playerid]);
	}
	else
	{
	    SendClientMessage(playerid, COLOR_RED, "You need Minimum of Level 10 to create a Gang");
	}
	return 1;
}
iam using this gang system:

https://sampforum.blast.hk/showthread.php?tid=72784

Please somebody help me..
Reply
#2

try
Код:
CreateGang(strval(gangname), Playername[playerid]);
But i doubt it that it will work
Reply
#3

Nope, it doesn't Work, now i get this error on your line:

Код:
: error 035: argument type mismatch (argument 1)
Reply
#4

pawn Код:
CreateGang(gangname, Playername[playerid]);
Reply
#5

Код:
 error 047: array sizes do not match, or destination array is too small
:S
Reply
#6

Can you show CreateGang function?
Reply
#7

Код:
stock CreateGang(name[MAX_GANG_NAME],owner[MAX_PLAYER_NAME])
{
    new string[256],File:hFile;
	for(new i = 0; i < MAX_GANGS; i++)
	{
	    format(string, sizeof(string), "/gangs/%d.gang", i);
	    if(!fexist(string))
	    {
	        hFile = fopen(string, io_write);
	        format(string, sizeof(string), "%s|%s", name,owner);
	        fwrite(hFile, string);
	        fclose(hFile);
	        Gangs[i][gName] = name;
	        Gangs[i][gOwner] = owner;
	        hFile = fopen("ganglog.log", io_append);
			format(string, sizeof(string), "Gang %d added: %s|%s", i, name,owner);
			fwrite(hFile, string);
			fclose(hFile);
			return i;
	    }
	}
	return -1;
}
Here you go.
Reply
#8

You will have to replace
pawn Код:
new gangname[MAX_GANG_NAME+1];
with
pawn Код:
new gangname[MAX_GANG_NAME];
(The size of the requested array is MAX_GANG_NAME, not MAX_GANG_NAME+1)
Reply
#9

Or just change it to

stock CreateGang(name[],owner[])
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)