invalid function or declaration
#1

pawn Код:
new pInfo[MAX_PLAYERS][PlayerInfo];
enum PlayerInfo
{
    Pass[129], //User's password
    Adminlevel, //User's admin level
    VIPlevel, //User's vip level
    Money, //User's money
    Scores, //User's scores
    Kills, //User's kills
    Skin, //User's Skin
    Deaths //User's deaths
}

CMD:stats(playerid, params[]);

    new id;
    sscanf(params, "u", id);
    if (isnull(params))
    {
        ShowPlayerDialog(playerid,dstats,DIALOG_STYLE_MSGBOX, "%s", "Account: %s\nMoney: $%d\nKills: %d\nDeaths: %d",GetPlayerName(playerid),GetPlayerMoney(playerid),pInfo[playerid][Kills],pInfo[playerid][Deaths] "Close", "");
        else if(IsPlayerConnected(id))
        {
        ShowPlayerDialog(playerid,dstats,DIALOG_STYLE_MSGBOX, "%s", "Account: %s\nMoney: $%d\nKills: %d\nDeaths: %d",GetPlayerName(id),GetPlayerMoney(id),pInfo[id][Kills],pInfo[id][Deaths] "Close", "");
        }
        else return SendClientMessage(playerid,0xFF000080,"Player has not logged in the server!");
    }
I'm trying to make a /stats command, and I always get this error. What is the problem?
Reply
#2

You are using an else-if statement which is nested inside an IF statement.

pawn Код:
if (isnull(params))
    {
        ShowPlayerDialog(playerid,dstats,DIALOG_STYLE_MSGBOX, "%s", "Account: %s\nMoney: $%d\nKills: %d\nDeaths: %d",GetPlayerName(playerid),GetPlayerMoney(playerid),pInfo[playerid][Kills],pInfo[playerid][Deaths] "Close", "");
        if(IsPlayerConnected(id))
        {
            ShowPlayerDialog(playerid,dstats,DIALOG_STYLE_MSGBOX, "%s", "Account: %s\nMoney: $%d\nKills: %d\nDeaths: %d",GetPlayerName(id),GetPlayerMoney(id),pInfo[id][Kills],pInfo[id][Deaths] "Close", "");
        }
        else return SendClientMessage(playerid,0xFF000080,"Player has not logged in the server!");
    }
And what is this?
pawn Код:
sscanf(params, "u", id);
Reply
#3

pawn Код:
if (isnull(params))
    {
        ShowPlayerDialog(playerid,dstats,DIALOG_STYLE_MSGBOX, "%s", "Account: %s\nMoney: $%d\nKills: %d\nDeaths: %d",GetPlayerName(playerid),GetPlayerMoney(playerid),pInfo[playerid][Kills],pInfo[playerid][Deaths] "Close", "");
        if(IsPlayerConnected(id))
        {
            ShowPlayerDialog(playerid,dstats,DIALOG_STYLE_MSGBOX, "%s", "Account: %s\nMoney: $%d\nKills: %d\nDeaths: %d",GetPlayerName(id),GetPlayerMoney(id),pInfo[id][Kills],pInfo[id][Deaths] "Close", "");
        }
        else return SendClientMessage(playerid,0xFF000080,"Player has not logged in the server!");
    }
I corrected it, and still have these errors;

pawn Код:
error 010: invalid function or declaration
Reply
#4

Quote:
Originally Posted by Bible
Посмотреть сообщение
You are using an else-if statement which is nested inside an IF statement.

pawn Код:
if (isnull(params))
    {
        ShowPlayerDialog(playerid,dstats,DIALOG_STYLE_MSGBOX, "%s", "Account: %s\nMoney: $%d\nKills: %d\nDeaths: %d",GetPlayerName(playerid),GetPlayerMoney(playerid),pInfo[playerid][Kills],pInfo[playerid][Deaths] "Close", "");
        if(IsPlayerConnected(id))
        {
            ShowPlayerDialog(playerid,dstats,DIALOG_STYLE_MSGBOX, "%s", "Account: %s\nMoney: $%d\nKills: %d\nDeaths: %d",GetPlayerName(id),GetPlayerMoney(id),pInfo[id][Kills],pInfo[id][Deaths] "Close", "");
        }
        else return SendClientMessage(playerid,0xFF000080,"Player has not logged in the server!");
    }
And what is this?
pawn Код:
sscanf(params, "u", id);
Oh, I got that from another script to check if the player typed the correct usage. I removed it anyway and still got the same error
Reply
#5

pawn Код:
CMD:stats(playerid, params[]);
Remove the semicolon.

EDIT:

Quote:
Originally Posted by Axey187
Посмотреть сообщение
Oh, I got that from another script to check if the player typed the correct usage. I removed it anyway and still got the same error
That is possible with the sscanf function.
Read this: https://github.com/Y-Less/sscanf/wik...nners-Tutorial
Reply
#6

Could you please try this code:

pawn Код:
CMD:stats(playerid, params[])
{
    new id, pName[MAX_PLAYER_NAME], Dialog[500];
   
    if(sscanf(params, "u", id))
    {
    GetPlayerName(playerid, pName, sizeof(pName));
    format(Dialog, sizeof(Dialog), "Account: %s\nMoney: $%d\nKills: %d\nDeaths: %d", pName, GetPlayerMoney(playerid),pInfo[playerid][Kills],pInfo[playerid][Deaths]);    
    ShowPlayerDialog(playerid,dstats,DIALOG_STYLE_MSGBOX, pName, Dialog, "Close", "");
    return 1;
    }    
    if(!IsPlayerConnected(id)) return GameTextForPlayer(playerid, "~g~Player disconnected", 3000, 3);
   
    GetPlayerName(id, pName, sizeof(pName));  
    format(Dialog, sizeof(Dialog), "Account: %s\nMoney: $%d\nKills: %d\nDeaths: %d", pName, GetPlayerMoney(id), pInfo[id][Kills], pInfo[id][Deaths]);
    ShowPlayerDialog(playerid,dstats,DIALOG_STYLE_MSGBOX, pName, Dialog, "Close", "");
    return 1;
}
Reply
#7

I've removed the semicolon, here's what I got:

pawn Код:
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : error 029: invalid expression, assumed zero
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : warning 215: expression has no effect
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : warning 215: expression has no effect
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : warning 215: expression has no effect
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : warning 202: number of arguments does not match definition
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : warning 202: number of arguments does not match definition
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : warning 215: expression has no effect
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : warning 215: expression has no effect
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : error 001: expected token: ";", but found "-string-"
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : warning 215: expression has no effect
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : warning 215: expression has no effect
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : error 001: expected token: ";", but found ")"
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : fatal error 107: too many error messages on one line

@Boot, Your code gave me these:
pawn Код:
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(182) : error 055: start of function body without function header
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : error 010: invalid function or declaration
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(190) : error 010: invalid function or declaration
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(192) : error 010: invalid function or declaration
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(194) : error 021: symbol already defined: "GetPlayerName"
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(197) : error 010: invalid function or declaration
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(199) : warning 203: symbol is never used: "Dialog"
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(199) : warning 203: symbol is never used: "id"
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(199) : warning 203: symbol is never used: "pName"
Reply
#8

Quote:
Originally Posted by Axey187
Посмотреть сообщение
@Boot, Your code gave me these:
pawn Код:
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(182) : error 055: start of function body without function header
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(185) : error 010: invalid function or declaration
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(190) : error 010: invalid function or declaration
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(192) : error 010: invalid function or declaration
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(194) : error 021: symbol already defined: "GetPlayerName"
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(197) : error 010: invalid function or declaration
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(199) : warning 203: symbol is never used: "Dialog"
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(199) : warning 203: symbol is never used: "id"
C:\Users\Ziad\Desktop\SA-MP\pawno\SAMP.pwn(199) : warning 203: symbol is never used: "pName"
Try now, I have forgot to remove ";" at the first line.
Reply
#9

pawn Код:
ShowPlayerDialog(playerid,dstats,DIALOG_STYLE_MSGBOX, "%s", "Account: %s\nMoney: $%d\nKills: %d\nDeaths: %d",GetPlayerName(playerid),GetPlayerMoney(playerid),pInfo[playerid][Kills],pInfo[playerid][Deaths] "Close", "");
That is simply not possible! In order for you to use specifiers such as: %s and %d you have to format the string.
I highly recommend you to read the wiki about these functions:
https://sampwiki.blast.hk/wiki/Format
https://sampwiki.blast.hk/wiki/ShowPlayerDialog
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)