/stats error
#1

Code:
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 © 1997-2006, ITB CompuPhase


1 Error.
PHP Code:
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 
HourMinuteSecondgettime(HourMinuteSecond);
       
TotalGameTime(playeridhms);
       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] == 0pDeaths 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(playerid),GetPlayerCountryName(playerid),
       
GetPlayerMoney(playerid),PlayerInfo[playerid][Bank],GetPlayerSkin(playerid),GetPlayerWantedLevel(playerid),PlayerInfo[playerid][Kills],PlayerInfo[playerid][Deaths],
       
Float:PlayerInfo[playerid][Kills]/Float:pDeaths);
       return 
ShowPlayerDialog(playerid0DIALOG_STYLE_MSGBOX"Stats"string"Ok","");
    }
    new 
string[500],Registered1[10],LoggedIn1[10],h,m,s,pDeaths;
    new 
HourMinuteSecondgettime(HourMinuteSecond);
    
TotalGameTime(player1hms);
    if(
PlayerInfo[player1][Registered] == 1){Registered1 "Yes";} else {Registered1 "No";}
    if(
PlayerInfo[player1][LoggedIn] == 1){LoggedIn1 "Yes";} else {LoggedIn1 "No";}
    if(
PlayerInfo[player1][Deaths] == 0pDeaths 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(player1),GetPlayerCountryName(player1),
    
GetPlayerMoney(player1),PlayerInfo[player1][Bank],GetPlayerSkin(player1),GetPlayerWantedLevel(player1),PlayerInfo[player1][Kills],PlayerInfo[player1][Deaths],
    
Float:PlayerInfo[player1][Kills]/Float:pDeaths);
    return 
ShowPlayerDialog(playerid0DIALOG_STYLE_MSGBOX"Stats"string"Ok","");

Reply
#2

Try to put those [10] numbers inside a tag in message formatting, like instead of LoggedIn1 try LoggedIn1[10]
Reply
#3

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.

PHP Code:
CMD:stats(playeridparams[]) 
{
    new 
player1;
    if (
sscanf(params"i"player1)) player1 playerid;
    
ShowStatsForPlayer(playeridplayer1);
    return 
1;
}
ShowStatsForPlayer(viewertarget)
{
    new 
string[500], hms;
    
TotalGameTime(targethms);
    
format(stringsizeof 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] == ? ("Yes") : ("No"),
        
PlayerInfo[target][LoggedIn] == ? ("Yes") : ("No"),
        
PlayerInfo[target][Hide] == PlayerInfo[target][Level],
        
GetPlayerScore(target),
        
hms,
        
GetPlayerPing(target),
        
GetPlayerCountryName(target),
        
GetPlayerMoney(target),
        
PlayerInfo[target][Bank],
        
GetPlayerSkin(target),
        
GetPlayerWantedLevel(target),
        
PlayerInfo[target][Kills],
        
PlayerInfo[target][Deaths],
        
PlayerInfo[target][Deaths] == ? (FloatPlayerInfo[target][Kills] / Float1) : (FloatPlayerInfo[target][Kills] / FloatPlayerInfo[target][Deaths]));
    return 
ShowPlayerDialog(playerid0DIALOG_STYLE_MSGBOX"Stats"string"Ok""");

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)