stats command error...
#3

Quote:
Originally Posted by Calisthenics
View Post
The errors and warning are given because you have `else` twice. Take a look at the example below:
pawn Code:
new some_value;

if (some_value == 1)
{
    // code..
}
else
{
    // code..
}
else return 1; // <-- this line causes the errors and warning
More about the command now. You use:
pawn Code:
if(id == INVALID_PLAYER_ID) {
    // code..
}
You should check if `id` is NOT equal to INVALID_PLAYER_ID. You use `playerid` in some arrays instead of `id`.

I tried to re-write the command
pawn Code:
CMD:stats(playerid, params[])
{
    if (PlayerInfo[playerid][LoggedIn] == false) return SendClientMessage(playerid, COLOR_RED, "ERROR: Account must be registered in order to use commands.");
    if (sscanf(params, "u", id)) return SendClientMessage(playerid, COLOR_RED, "Syntax: /stats <playerid>");

    new id;
    if (id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected");

    new string[266], tname[MAX_PLAYER_NAME], registered[4], admrank[57], // increase 266 if text is cut
        admin = PlayerInfo[id][AdminLevel],
        kills = PlayerInfo[id][Kills],
        deaths = PlayerInfo[id][Deaths],
        score = PlayerInfo[id][Score],
        money = GetPlayerMoney(id);

    GetPlayerName(id, tname, sizeof(tname));
    registered = (PlayerInfo[id][LoggedIn] == false) ? ("No") : ("Yes");

    static const ranks_with_color[][] = {"", "{FFFF00}(Moderator)", "{008000}(Administrator)", "{3366FF}(Manager)"};
 
    if (IsPlayerAdmin(id))
    {
        admrank = "{00FF00}Admin Level:{FF0000} RCON Admin\n";
    }
    else if (1 <= PlayerInfo[id][AdminLevel] <= 3)
    {
        format(admrank, sizeof(admrank), "{00FF00}Admin Level:{FFFFFF} %d %s\n", PlayerInfo[id][AdminLevel], ranks_with_color[PlayerInfo[id][AdminLevel]]);
    }

    format(string, sizeof(string), "{00FF00}Name:{FFFFFF} %s\n{00FF00}Registered:{FFFFFF} %s\n%s{00FF00}Kills:{FFFFFF} %d\n{00FF00}Deaths:{FFFFFF} %d\n{00FF00}Score:{FFFFFF} %d\n{00FF00}Money:{FFFFFF} %d", tname, registered, admrank, kills, deaths, score, money);
    ShowPlayerDialog(playerid, DIALOG_STATS, DIALOG_STYLE_MSGBOX, "{FFFFFF}Player's Statistics:", string, "Okay", "");
    return 1;
}
alright so the command worked as expected to do, but it's just a little bit hard for a scripter like me to understand what you coded, for example static const ranks thing, those (no) (yes), it's the first time i've seen those but it works, if you could simplify the code like it's on mine, it would be appreciated (if you want to)

p.s: there's a warning which i consider as an error since most warnings i've experienced turned out to be errors in my coding so here it is:

Code:
C:\Users\Heheboii\Desktop\samp037_svr_R2-1-1_win32 (1)\gamemodes\fps.pwn(971) : warning 204: symbol is assigned a value that is never used: "admin"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
Reply


Messages In This Thread
stats command error... - by mems - 19.12.2019, 16:56
Re: stats command error... - by Calisthenics - 19.12.2019, 17:34
Re: stats command error... - by mems - 19.12.2019, 17:56
Re: stats command error... - by Joe Staff - 19.12.2019, 18:33
Re: stats command error... - by Calisthenics - 19.12.2019, 18:37
Re: stats command error... - by mems - 19.12.2019, 19:36

Forum Jump:


Users browsing this thread: 1 Guest(s)