sscanf "u" specifier makes problems
#1

Hello, I'm having a problem where only player id 0 uses any command for example /stats and its just not working. and printing error in the cmd.. here is the error and there is quick fix where i can just change the specifier "u" to "d" when using sscanf..

Code:
[00:10:10] [debug] Run time error 4: "Array index out of bounds"
[00:10:10] [debug]  Accessing element at index 12 past array upper bound 10
[00:10:10] [debug] AMX backtrace:
[00:10:10] [debug] #0 0032c5c8 in ?? (0) from LG-RP.amx
[00:10:10] [debug] #1 003175a4 in ?? (0, 0) from LG-RP.amx
[00:10:10] [debug] #2 0013df08 in public cmd_stats (0, 34493368) from LG-RP.amx
[00:10:10] [debug] #3 native CallLocalFunction () from samp-server.exe
[00:10:10] [debug] #4 00006634 in public OnPlayerCommandText (0, 34493340) from LG-RP.amx
/stats for example
Code:
CMD:stats(playerid, params[])
{
	if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
	ShowStats(playerid, playerid);
	return 1;
}
Whats the problem?
Reply
#2

Would you mind showing the ShowStats function?
Reply
#3

Quote:
Originally Posted by Jimmy0wns
View Post
Would you mind showing the ShowStats function?
here is the function:
Code:
stock ShowStats(playerid, playerb)
{
	new string[256], gender[8];
	// Gender
	if(PlayerInfo[playerb][pGender] == 1) format(gender, sizeof(gender), "Male");
	else if(PlayerInfo[playerb][pGender] == 2) format(gender, sizeof(gender), "Female");
	// Health and Armor
	new Float:HP,Float:Armor;
	GetPlayerHealth(playerb, HP);
	GetPlayerArmour(playerb, Armor);
	// Loyal
	new loyal[4];
	if(!PlayerInfo[playerb][pLoyal]) format(loyal, sizeof(loyal), "Yes");
	if(PlayerInfo[playerb][pLoyal]) format(loyal, sizeof(loyal), "No");
	// Oldskool
	new oldskool[4];
	if(PlayerInfo[playerb][pHours] >= 248) format(oldskool, sizeof(oldskool), "Yes");
	else if(PlayerInfo[playerb][pHours] < 248) format(oldskool, sizeof(oldskool), "No");
	//fac-fam rank
	new rank[128];
	if(PlayerInfo[playerb][pFac] >= 1) format(rank, sizeof(rank), "%s", RPFRN(playerb));
	else format(rank, sizeof(rank), "None");
	//fac-fam
	new org[128];
	if(PlayerInfo[playerb][pFac] >= 1) format(org, sizeof(org), "%s", RPFNEx(playerb));
	else format(org, sizeof(org), "None");
	//
	new rank2[128];
	if(PlayerInfo[playerb][pFam] >=1) format(rank2, sizeof(rank2), "%s", RPFaRN(playerb));
	else format(rank2, sizeof(rank2), "None");
	//fac-fam
	new org2[128];
	if(PlayerInfo[playerb][pFam] >=1) format(org2, sizeof(org2), "%s", RPFaN(playerb));
	else format(org2, sizeof(org2), "None");
	new exp = PlayerInfo[playerb][pExp];
	new nxtlevel = PlayerInfo[playerb][pLevel]+1;
	new expamount = nxtlevel*4;
	//new costlevel = nxtlevel*4000;//10k for testing purposes
	//respect
	new respectneed[4];
	if(PlayerInfo[playerb][pLevel] == 1) format(respectneed, sizeof(respectneed), "4");
 	else if(PlayerInfo[playerb][pLevel] == 2) format(respectneed, sizeof(respectneed), "8");
  	else if(PlayerInfo[playerb][pLevel] == 3) format(respectneed, sizeof(respectneed), "12");
   	else if(PlayerInfo[playerb][pLevel] == 4) format(respectneed, sizeof(respectneed), "16");
    else if(PlayerInfo[playerb][pLevel] == 5) format(respectneed, sizeof(respectneed), "20");
    else if(PlayerInfo[playerb][pLevel] == 6) format(respectneed, sizeof(respectneed), "24");
    else if(PlayerInfo[playerb][pLevel] == 7) format(respectneed, sizeof(respectneed), "28");
    else if(PlayerInfo[playerb][pLevel] == 8) format(respectneed, sizeof(respectneed), "32");
    else if(PlayerInfo[playerb][pLevel] == 9) format(respectneed, sizeof(respectneed), "36");
    else if(PlayerInfo[playerb][pLevel] == 10) format(respectneed, sizeof(respectneed), "40");
    else if(PlayerInfo[playerb][pLevel] == 11) format(respectneed, sizeof(respectneed), "44");
    else if(PlayerInfo[playerb][pLevel] == 12) format(respectneed, sizeof(respectneed), "48");
    else if(PlayerInfo[playerb][pLevel] == 13) format(respectneed, sizeof(respectneed), "52");
    else if(PlayerInfo[playerb][pLevel] == 14) format(respectneed, sizeof(respectneed), "56");
    else if(PlayerInfo[playerb][pLevel] == 15) format(respectneed, sizeof(respectneed), "60");
    else if(PlayerInfo[playerb][pLevel] == 16) format(respectneed, sizeof(respectneed), "64");
    else if(PlayerInfo[playerb][pLevel] == 17) format(respectneed, sizeof(respectneed), "68");
    else if(PlayerInfo[playerb][pLevel] == 18) format(respectneed, sizeof(respectneed), "72");
    else if(PlayerInfo[playerb][pLevel] == 19) format(respectneed, sizeof(respectneed), "76");
    else if(PlayerInfo[playerb][pLevel] == 20) format(respectneed, sizeof(respectneed), "80");
    else if(PlayerInfo[playerb][pLevel] == 21) format(respectneed, sizeof(respectneed), "84");
    else if(PlayerInfo[playerb][pLevel] == 22) format(respectneed, sizeof(respectneed), "88");
    else if(PlayerInfo[playerb][pLevel] == 23) format(respectneed, sizeof(respectneed), "92");
    else if(PlayerInfo[playerb][pLevel] == 24) format(respectneed, sizeof(respectneed), "96");
    else if(PlayerInfo[playerb][pLevel] == 25) format(respectneed, sizeof(respectneed), "100");
    else if(PlayerInfo[playerb][pLevel] == 26) format(respectneed, sizeof(respectneed), "104");
    else if(PlayerInfo[playerb][pLevel] == 27) format(respectneed, sizeof(respectneed), "108");
    else if(PlayerInfo[playerb][pLevel] == 28) format(respectneed, sizeof(respectneed), "112");
    else if(PlayerInfo[playerb][pLevel] == 29) format(respectneed, sizeof(respectneed), "116");
    else if(PlayerInfo[playerb][pLevel] == 30) format(respectneed, sizeof(respectneed), "120");
    else if(PlayerInfo[playerb][pLevel] == 31) format(respectneed, sizeof(respectneed), "124");
    else if(PlayerInfo[playerb][pLevel] == 32) format(respectneed, sizeof(respectneed), "128");
    else if(PlayerInfo[playerb][pLevel] == 33) format(respectneed, sizeof(respectneed), "132");
    else if(PlayerInfo[playerb][pLevel] == 34) format(respectneed, sizeof(respectneed), "136");
    else if(PlayerInfo[playerb][pLevel] == 35) format(respectneed, sizeof(respectneed), "140");
    else if(PlayerInfo[playerb][pLevel] == 36) format(respectneed, sizeof(respectneed), "144");
    else if(PlayerInfo[playerb][pLevel] == 37) format(respectneed, sizeof(respectneed), "148");
    else if(PlayerInfo[playerb][pLevel] == 38) format(respectneed, sizeof(respectneed), "152");
    else if(PlayerInfo[playerb][pLevel] == 39) format(respectneed, sizeof(respectneed), "156");
    else if(PlayerInfo[playerb][pLevel] == 40) format(respectneed, sizeof(respectneed), "160");
	//new average = (PlayerInfo[playerb][pTMinutes] / PlayerInfo[playerb][pDay]);
	// Stats
	if(PlayerInfo[playerid][CardOwner])
	{
		format(string, sizeof(string), " -- LG-RP Statistics of %s --", RPN(playerb));
		SendClientMessage(playerid, COLOR_ORANGE, string);
		format(string, sizeof(string), "Level: [%d] - Gender: [%s] - Age: [%d] - Money: [$%d] - Bank: [$%d] - Health: [%.0f] - Armor: [%.0f]", PlayerInfo[playerb][pLevel], gender, PlayerInfo[playerb][pAge], PlayerInfo[playerb][pMoney], BankInfo[playerb][Balance], HP, Armor);
		SendClientMessage(playerid, COLOR_LIGHTRED, string);
		format(string, sizeof(string), "Phone Number: [%d] - Playing Hours: [%d] Next Level: [%d/%d] - Respect Points: [%d]", PlayerInfo[playerb][pNumber], PlayerInfo[playerb][pHours], exp, expamount, PlayerInfo[playerb][pExp]);
		SendClientMessage(playerid, COLOR_LIGHTRED, string);
		format(string, sizeof(string), "Occupation: [%s] - Wanted Level: [%d] - Crimes Committed: [%d] - Arrested: [%dx] - Kill: [%d] - Death: [%d]", RPJN(playerb), PlayerInfo[playerb][pWanted], PlayerInfo[playerb][pCrimes], PlayerInfo[playerb][pArrested], PlayerInfo[playerb][pKill], PlayerInfo[playerb][pDeath]);
		SendClientMessage(playerid, COLOR_WHITE, string);
		format(string, sizeof(string), "Faction: [%s] - Faction Rank: [%s] - Family: [%s] - Family Rank: [%s]", org, rank, org2, rank2);
		SendClientMessage(playerid, COLOR_RADIO, string);
		format(string, sizeof(string), "Business: [%s] - House: [%s] - Garage: [%s] - Vehicles: 1[%s (ID:%d) - 2[%s (ID:%d)] - 3[%s (ID:%d)]", RBT(PlayerInfo[playerb][pBiz]), RPHK(playerb), RPGK(playerb), RVN(GetVehicleModel(PlayerInfo[playerb][pVeh])), PlayerInfo[playerb][pVeh], RVN(GetVehicleModel(PlayerInfo[playerb][pVVeh])), PlayerInfo[playerb][pVVeh], RVN(GetVehicleModel(PlayerInfo[playerb][pVVVeh])), PlayerInfo[playerb][pVVVeh]);
		SendClientMessage(playerid, COLOR_RADIO, string);
		SendClientMessage(playerid, COLOR_REPORT, "** For information about your inventory use the '/inv' command.");
	}
	else
	{
		format(string, sizeof(string), " Statistics of %s", RPN(playerb));
		SendClientMessage(playerid, COLOR_ORANGE, string);
		format(string, sizeof(string), "Level: [%d] - Gender: [%s] - Age: [%d] - Money: [$%d] - Bank: [You don't have Bank account] - Health: [%.0f] - Armor: [%.0f]", PlayerInfo[playerb][pLevel], gender, PlayerInfo[playerb][pAge], PlayerInfo[playerb][pMoney], HP, Armor);
		SendClientMessage(playerid, COLOR_LIGHTRED, string);
		format(string, sizeof(string), "Phone Number: [%d] - Playing Hours: [%d] Next Level: [%d/%d] - Respect Points: [%d]", PlayerInfo[playerb][pNumber], PlayerInfo[playerb][pHours], exp, expamount, PlayerInfo[playerb][pExp]);
		SendClientMessage(playerid, COLOR_LIGHTRED, string);
		format(string, sizeof(string), "Occupation: [%s] - Wanted Level: [%d] - Crimes Committed: [%d] - Arrested: [%dx] - Kill: [%d] - Death: [%d]", RPJN(playerb), PlayerInfo[playerb][pWanted], PlayerInfo[playerb][pCrimes], PlayerInfo[playerb][pArrested], PlayerInfo[playerb][pKill], PlayerInfo[playerb][pDeath]);
		SendClientMessage(playerid, COLOR_WHITE, string);
		format(string, sizeof(string), "Faction: [%s] - Faction Rank: [%s] - Family: [%s] - Family Rank: [%s]", org, rank, org2, rank2);
		SendClientMessage(playerid, COLOR_RADIO, string);
		format(string, sizeof(string), "Business: [%s] - House: [%s] - Garage: [%s] - Vehicles: 1[%s (ID:%d) - 2[%s (ID:%d)] - 3[%s (ID:%d)]", RBT(PlayerInfo[playerb][pBiz]), RPHK(playerb), RPGK(playerb), RVN(GetVehicleModel(PlayerInfo[playerb][pVeh])), PlayerInfo[playerb][pVeh], RVN(GetVehicleModel(PlayerInfo[playerb][pVVeh])), PlayerInfo[playerb][pVVeh], RVN(GetVehicleModel(PlayerInfo[playerb][pVVVeh])), PlayerInfo[playerb][pVVVeh]);
		SendClientMessage(playerid, COLOR_RADIO, string);
		SendClientMessage(playerid, COLOR_REPORT, "** For information about your inventory use the '/inv' command.");
	}
	return 1;
}
it works perfectly on any other ID then 0.
Reply
#4

  1. You're not even using sscanf in this command.
  2. Compile the script using -d3 and try again, this will provide a more detailed error log.
    • If you're using Pawno (IDE that is supplied with the Windows server), you can do so by doing the following:
      1. Create a text file called pawn.cfg inside your pawno folder.
      2. Open the file and insert -d3 in there. Save it.
      3. Recompile your script(s).
      After you do this show us your new error log after executing the command.
Reply
#5

Quote:
Originally Posted by Crayder
View Post
1. You're not even using sscanf in this command.
2. Compile the script using -d3 and try again, this will provide a more detailed error log.

If you're using Pawno (IDE that is supplied with the Windows server), you can do so by doing the following:
Create a text file called pawn.cfg inside your pawno folder.
Open the file and insert -d3 in there. Save it.
Recompile your script(s).
Yeah OK, it happens for any command, I just took this command because its the one i debugged, the same error happens with any other command, this problem 100% occurs with playerid, i cant point out where and why..
Reply
#6

EDIT: nvm, just do as I said in '2'.
Reply
#7

Okey, with the new debug there is more information. do you need anything else? just ask.
Code:
[00:48:35] [cmd] [Leonardo James]: /stats
[00:48:42] [debug] Run time error 4: "Array index out of bounds"
[00:48:42] [debug]  Accessing element at index 12 past array upper bound 10
[00:48:42] [debug] AMX backtrace:
[00:48:42] [debug] #0 003fb160 in RPFRN (playerid=1) at C:\Users\Max\Desktop\GTA United\gamemodes\LG-RP.pwn:54528
[00:48:42] [debug] #1 003e086c in ShowStats (playerid=1, playerb=1) at C:\Users\Max\Desktop\GTA United\gamemodes\LG-RP.pwn:52582
[00:48:42] [debug] #2 0018dedc in public cmd_stats (playerid=1, params[]=@014a22d8 "") at C:\Users\Max\Desktop\GTA United\gamemodes\LG-RP.pwn:23902
[00:48:42] [debug] #3 native CallLocalFunction () from samp-server.exe
[00:48:42] [debug] #4 00007478 in public OnPlayerCommandText (playerid=1, cmdtext[]=@014a22bc "/stats") at C:\Users\Max\Desktop\GTA United\pawno\include\I-ZCMD.inc:61
Reply
#8

Post RPFRN function and line 54528.

Just from a fast look, replace all those if/else if statements about PlayerInfo[playerb][pLevel] to a switch and the format can be replaced with an integer variable assignment and after the switch, calling valstr to convert it to string.
Reply
#9

Quote:
Originally Posted by Konstantinos
View Post
Just from a fast look, replace all those if/else if statements about PlayerInfo[playerb][pLevel] to a switch and the format can be replaced with an integer variable assignment and after the switch, calling valstr to convert it to string.
Actually, all of the following could be removed:
pawn Code:
//respect
    new respectneed[4];
    if(PlayerInfo[playerb][pLevel] == 1) format(respectneed, sizeof(respectneed), "4");
    else if(PlayerInfo[playerb][pLevel] == 2) format(respectneed, sizeof(respectneed), "8");
    else if(PlayerInfo[playerb][pLevel] == 3) format(respectneed, sizeof(respectneed), "12");
    else if(PlayerInfo[playerb][pLevel] == 4) format(respectneed, sizeof(respectneed), "16");
    else if(PlayerInfo[playerb][pLevel] == 5) format(respectneed, sizeof(respectneed), "20");
    else if(PlayerInfo[playerb][pLevel] == 6) format(respectneed, sizeof(respectneed), "24");
    else if(PlayerInfo[playerb][pLevel] == 7) format(respectneed, sizeof(respectneed), "28");
    else if(PlayerInfo[playerb][pLevel] == 8) format(respectneed, sizeof(respectneed), "32");
    else if(PlayerInfo[playerb][pLevel] == 9) format(respectneed, sizeof(respectneed), "36");
    else if(PlayerInfo[playerb][pLevel] == 10) format(respectneed, sizeof(respectneed), "40");
    else if(PlayerInfo[playerb][pLevel] == 11) format(respectneed, sizeof(respectneed), "44");
    else if(PlayerInfo[playerb][pLevel] == 12) format(respectneed, sizeof(respectneed), "48");
    else if(PlayerInfo[playerb][pLevel] == 13) format(respectneed, sizeof(respectneed), "52");
    else if(PlayerInfo[playerb][pLevel] == 14) format(respectneed, sizeof(respectneed), "56");
    else if(PlayerInfo[playerb][pLevel] == 15) format(respectneed, sizeof(respectneed), "60");
    else if(PlayerInfo[playerb][pLevel] == 16) format(respectneed, sizeof(respectneed), "64");
    else if(PlayerInfo[playerb][pLevel] == 17) format(respectneed, sizeof(respectneed), "68");
    else if(PlayerInfo[playerb][pLevel] == 18) format(respectneed, sizeof(respectneed), "72");
    else if(PlayerInfo[playerb][pLevel] == 19) format(respectneed, sizeof(respectneed), "76");
    else if(PlayerInfo[playerb][pLevel] == 20) format(respectneed, sizeof(respectneed), "80");
    else if(PlayerInfo[playerb][pLevel] == 21) format(respectneed, sizeof(respectneed), "84");
    else if(PlayerInfo[playerb][pLevel] == 22) format(respectneed, sizeof(respectneed), "88");
    else if(PlayerInfo[playerb][pLevel] == 23) format(respectneed, sizeof(respectneed), "92");
    else if(PlayerInfo[playerb][pLevel] == 24) format(respectneed, sizeof(respectneed), "96");
    else if(PlayerInfo[playerb][pLevel] == 25) format(respectneed, sizeof(respectneed), "100");
    else if(PlayerInfo[playerb][pLevel] == 26) format(respectneed, sizeof(respectneed), "104");
    else if(PlayerInfo[playerb][pLevel] == 27) format(respectneed, sizeof(respectneed), "108");
    else if(PlayerInfo[playerb][pLevel] == 28) format(respectneed, sizeof(respectneed), "112");
    else if(PlayerInfo[playerb][pLevel] == 29) format(respectneed, sizeof(respectneed), "116");
    else if(PlayerInfo[playerb][pLevel] == 30) format(respectneed, sizeof(respectneed), "120");
    else if(PlayerInfo[playerb][pLevel] == 31) format(respectneed, sizeof(respectneed), "124");
    else if(PlayerInfo[playerb][pLevel] == 32) format(respectneed, sizeof(respectneed), "128");
    else if(PlayerInfo[playerb][pLevel] == 33) format(respectneed, sizeof(respectneed), "132");
    else if(PlayerInfo[playerb][pLevel] == 34) format(respectneed, sizeof(respectneed), "136");
    else if(PlayerInfo[playerb][pLevel] == 35) format(respectneed, sizeof(respectneed), "140");
    else if(PlayerInfo[playerb][pLevel] == 36) format(respectneed, sizeof(respectneed), "144");
    else if(PlayerInfo[playerb][pLevel] == 37) format(respectneed, sizeof(respectneed), "148");
    else if(PlayerInfo[playerb][pLevel] == 38) format(respectneed, sizeof(respectneed), "152");
    else if(PlayerInfo[playerb][pLevel] == 39) format(respectneed, sizeof(respectneed), "156");
    else if(PlayerInfo[playerb][pLevel] == 40) format(respectneed, sizeof(respectneed), "160");
If you'd rather not remove it though, here is the correct way to do this:
pawn Code:
new respectneed[4];
    format(respectneed, sizeof(respectneed), "%i", PlayerInfo[playerb][pLevel] * 4);




We still need you to post the RPFRN function and line 54528.
Reply
#10

Thats the function RPFRN:
Code:
stock RPFRN(playerid)
{
	new rankname[32];
	if(PlayerInfo[playerid][pFacRank] == 0 && PlayerInfo[playerid][pFac] == 0) format(rankname, sizeof(rankname), "Civilian");
	else if(PlayerInfo[playerid][pFac])
	{
		//if(PlayerInfo[playerid][pFacRank] == 0) format(rankname, sizeof(rankname), "%s", FacInfo[PlayerInfo[playerid][pFac]][fRank0]);
		if(PlayerInfo[playerid][pFacRank] == 1) format(rankname, sizeof(rankname), "%s", FacInfo[PlayerInfo[playerid][pFac]][fRank1]);
		else if(PlayerInfo[playerid][pFacRank] == 2) format(rankname, sizeof(rankname), "%s", FacInfo[PlayerInfo[playerid][pFac]][fRank2]);
		else if(PlayerInfo[playerid][pFacRank] == 3) format(rankname, sizeof(rankname), "%s", FacInfo[PlayerInfo[playerid][pFac]][fRank3]);
		else if(PlayerInfo[playerid][pFacRank] == 4) format(rankname, sizeof(rankname), "%s", FacInfo[PlayerInfo[playerid][pFac]][fRank4]);
		else if(PlayerInfo[playerid][pFacRank] == 5) format(rankname, sizeof(rankname), "%s", FacInfo[PlayerInfo[playerid][pFac]][fRank5]);
		else if(PlayerInfo[playerid][pFacRank] == 6) format(rankname, sizeof(rankname), "%s", FacInfo[PlayerInfo[playerid][pFac]][fRank6]);
		else if(PlayerInfo[playerid][pFacRank] == 7) format(rankname, sizeof(rankname), "%s", FacInfo[PlayerInfo[playerid][pFac]][fRank7]);
		else if(PlayerInfo[playerid][pFacRank] == 8) format(rankname, sizeof(rankname), "%s", FacInfo[PlayerInfo[playerid][pFac]][fRank8]);
		else if(PlayerInfo[playerid][pFacRank] == 9) format(rankname, sizeof(rankname), "%s", FacInfo[PlayerInfo[playerid][pFac]][fRank9]);
		else if(PlayerInfo[playerid][pFacRank] == 10) format(rankname, sizeof(rankname), "%s", FacInfo[PlayerInfo[playerid][pFac]][fRank10]);
	}
	return rankname;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)