Little help here ?
#1

Hello, I have a little problem here with the division names. Here's the whole code.

Код:
CMD:adjustdivisionname(playerid, params[])
{
	new division, name[8], string[128];
	if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
	if(!IsACop(playerid) || !PlayerInfo[playerid][pFacLeader]) return SendClientMessage(playerid, COLOR_GREY, "You are not an LSPD faction leader.");
	if(sscanf(params, "is[32]", division, name)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /adjustdivisionname [division] [name]");
	switch(division)
	{
	    case 1:
	    {
	        FacInfo[1][fDiv1] = name;
	        format(string, sizeof(string), "You have set division 1's name to %s", name);
	        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
	    }
	    case 2:
	    {
	        FacInfo[1][fDiv2] = name;
	        format(string, sizeof(string), "You have set division 2's name to %s", name);
	        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
	    }
	    case 3:
	    {
	        FacInfo[1][fDiv3] = name;
	        format(string, sizeof(string), "You have set division 3's name to %s", name);
	        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
	    }
	    case 4:
	    {
	        FacInfo[1][fDiv4] = name;
	        format(string, sizeof(string), "You have set division 4's name to %s", name);
	        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
	    }
	}
	return 1;
}
I want to make the division names lenght longer than 8 characters, but everytime I try to make the "name" longer, or shorter (ex: new division, name[32], string[128]; ), I get this error:

Код:
 error 047: array sizes do not match, or destination array is too small
error 047: array sizes do not match, or destination array is too small
error 047: array sizes do not match, or destination array is too small
error 047: array sizes do not match, or destination array is too small
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.

Error lines: FacInfo[1][fDiv1] = name; , FacInfo[1][fDiv2] = name; FacInfo[1][fDiv3] = name; FacInfo[1][fDiv4] = name;
So, the question is - how to make the divisions " name " longer? Everyone who atleast tries to help will be +Repped, thanks in advance.
Reply
#2

I can see you have already changed
pawn Код:
if(sscanf(params, "is[32]"
to 32.

But you'll have to change
pawn Код:
new division, name[8],
this to 32 as well.

And if you have done that, there is only one more array that could be wrong, and that is;

pawn Код:
FacInfo[1][fDiv3]
Search for that, and i bet you It's sized 8 like so;
pawn Код:
enum factiondata // factiondata might be called something else in your script
{
 .... other arrays and integers
    fDiv3[8],
And maybe you don't even use enums, but the array fDiv3 size is defined somewhere.
Reply
#3

Cleary forgot about that, thank you pal! +Repped

One more question, how to do it like that:

When a player exceeds the characters limit of division name to return ClientMessage like "The max name lenght is 32 characters" for example...

I tried something like if(name => 33) return scm(playerid, -1, " blah blah"); ... but it didnt worked.
Reply
#4

Use strlen
pawn Код:
if(strlen(name)) > 32) return scm(playerid,-1,"blah blah");
You should also check so that the string isn't empty...

pawn Код:
if(isnull(name)) return scm(playerid,-1,"blah blah");
If you get an error using isnull, you probably don't have the function (it most likely comes with alot of includes, so chances are it will work). But if it doesn't work, put this at the top:

pawn Код:
#if !defined isnull
    #define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
Reply
#5

Thanks!
Reply
#6

No problem
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)