PDA

View Full Version : /stats error


Filbert
02/07/2018, 02:12 PM
D:\SA-MP Servers\Test Server\gamemodes\Test.pwn(23346) : error 047: array sizes do not match, or destination array is too small
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


1 Error.

CMD:stats(playerid,params[]) {
new player1;
if(sscanf(params,"i",player1)) {
new string[500],Registered1[10],LoggedIn1[10],AdminLevel1[10],h,m,s,pDeaths;
new Hour, Minute, Second; gettime(Hour, Minute, Second);
TotalGameTime(playerid, h, m, s);
if(PlayerInfo[playerid][Registered] == 1){Registered1 = "Yes";} else {Registered1 = "No";}
if(PlayerInfo[playerid][LoggedIn] == 1){LoggedIn1 = "Yes";} else {LoggedIn1 = "No";}
if(PlayerInfo[playerid][Hide] == 1){AdminLevel1 = "0";} else {AdminLevel1 = PlayerInfo[playerid][Level];} // <<< Line 23346
if(PlayerInfo[playerid][Deaths] == 0) pDeaths = 1; else pDeaths = PlayerInfo[playerid][Deaths];
format(string,sizeof string,"{ff4d4d}Stats of %s\n\n{FFFFFF}Registered: %s\nLoggedIn: %s\nAdmin Level: %d\nScore: %d\nTime: %d hrs %d mins %d secs\nPing: %d\nCountry: %s\
\n\n{33AA33}Cash: $%d\nBank: $%d\n\n{FFFFFF}Skin: %d\nWanted level: %d\n\n{FFFF00}Kills and Deaths\n{FFFFFF}Kills: %d\nDeaths: %d\nRatio: %f",
pName(playerid),Registered1,LoggedIn1,AdminLevel1, GetPlayerScore(playerid),h,m,s,GetPlayerPing(playe rid),GetPlayerCountryName(playerid),
GetPlayerMoney(playerid),PlayerInfo[playerid][Bank],GetPlayerSkin(playerid),GetPlayerWantedLevel(play erid),PlayerInfo[playerid][Kills],PlayerInfo[playerid][Deaths],
Float:PlayerInfo[playerid][Kills]/Float:pDeaths);
return ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Stats", string, "Ok","");
}
new string[500],Registered1[10],LoggedIn1[10],h,m,s,pDeaths;
new Hour, Minute, Second; gettime(Hour, Minute, Second);
TotalGameTime(player1, h, m, s);
if(PlayerInfo[player1][Registered] == 1){Registered1 = "Yes";} else {Registered1 = "No";}
if(PlayerInfo[player1][LoggedIn] == 1){LoggedIn1 = "Yes";} else {LoggedIn1 = "No";}
if(PlayerInfo[player1][Deaths] == 0) pDeaths = 1; else pDeaths = PlayerInfo[player1][Deaths];
format(string,sizeof string,"{ff4d4d}Stats of %s\n\n{FFFFFF}Registered: %s\nLoggedIn: %s\nAdmin Level: %d\nScore: %d\nTime: %d hrs %d mins %d secs\nPing: %d\nCountry: %s\
\n\n{33AA33}Cash: $%d\nBank: $%d\n\n{FFFFFF}Skin: %d\nWanted level: %d\n\n{FFFF00}Kills and Deaths\n{FFFFFF}Kills: %d\nDeaths: %d\nRatio: %0.2f",
pName(player1),Registered1,LoggedIn1,PlayerInfo[player1][Level],GetPlayerScore(player1),h,m,s,GetPlayerPing(playe r1),GetPlayerCountryName(player1),
GetPlayerMoney(player1),PlayerInfo[player1][Bank],GetPlayerSkin(player1),GetPlayerWantedLevel(playe r1),PlayerInfo[player1][Kills],PlayerInfo[player1][Deaths],
Float:PlayerInfo[player1][Kills]/Float:pDeaths);
return ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Stats", string, "Ok","");
}

Mike861
02/07/2018, 02:37 PM
Try to put those [10] numbers inside a tag in message formatting, like instead of LoggedIn1 try LoggedIn1[10]

Calisthenics
02/07/2018, 02:41 PM
AdminLevel1 should be an integer.

When you have repeated code, make it a function.
You can use ternary operator for "Yes"/"No".
Based on its name, when "Hide" is 1 shouldn't have been admin level 0? If not, change it in the code.


CMD:stats(playerid, params[])
{
new player1;

if (sscanf(params, "i", player1)) player1 = playerid;

ShowStatsForPlayer(playerid, player1);
return 1;
}

ShowStatsForPlayer(viewer, target)
{
new string[500], h, m, s;

TotalGameTime(target, h, m, s);

format(string, sizeof string,
"{ff4d4d}Stats of %s\n\n{FFFFFF}Registered: %s\nLoggedIn: %s\nAdmin Level: %d\nScore: %d\nTime: %d hrs %d mins %d secs\nPing: %d\nCountry: %s\
\n\n{33AA33}Cash: $%d\nBank: $%d\n\n{FFFFFF}Skin: %d\nWanted level: %d\n\n{FFFF00}Kills and Deaths\n{FFFFFF}Kills: %d\nDeaths: %d\nRatio: %f",
pName(target),
PlayerInfo[target][Registered] == 1 ? ("Yes") : ("No"),
PlayerInfo[target][LoggedIn] == 1 ? ("Yes") : ("No"),
PlayerInfo[target][Hide] == 1 ? 0 : PlayerInfo[target][Level],
GetPlayerScore(target),
h, m, s,
GetPlayerPing(target),
GetPlayerCountryName(target),
GetPlayerMoney(target),
PlayerInfo[target][Bank],
GetPlayerSkin(target),
GetPlayerWantedLevel(target),
PlayerInfo[target][Kills],
PlayerInfo[target][Deaths],
PlayerInfo[target][Deaths] == 0 ? (Float: PlayerInfo[target][Kills] / Float: 1) : (Float: PlayerInfo[target][Kills] / Float: PlayerInfo[target][Deaths]));

return ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Stats", string, "Ok", "");
}