Cannot make a command
#1

Whenever I try to make a command, I get the error "invalid function or declaration"..

Here's my code:
pawn Код:
//======================== Includes ======================= //

#include <a_samp>
#include <YSI\y_ini>
#include <zcmd>
#include <sscanf2>
//============================= Defines ========================//

#define dregister 2011 //Defining register dialog so it won't mixed up with the other dialogs
#define dlogin 2012 //Defining login dialog so it won't mixed up with the other dialogs
#define UserPath "Users/%s.ini" //Will define user's account path. In this case, we will save it in Scriptfiles/Users. So create a file inside of your Scriptfiles folder called Users
#define dstats 2014
//=============== Colors =======================//
#define COLOR_RED 0xFF000080


native WP_Hash(buffer[],len,const str[]); // Whirlpool native, add it at the top of your script under includes
//================== Enumerators =========================//

//We will create an enum to store player's data.
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
}
//================================= Variables and Arrays (Varibales with space) ==================================//
new pInfo[MAX_PLAYERS][PlayerInfo]; //This will create a new variable so we can later use it to saving/loading user's info.
new id;

stock Path(playerid) //Will create a new stock so we can easily use it later to load/save user's data in user's path
{
    new str[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(str,sizeof(str),UserPath,name);
    return str;
}
//==================================== forwards ========================================//

forward loadaccount_user(playerid, name[], value[]); //forwarding a new function to load user's data


//Now we will use our own function that we have created above
public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
    ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length of a hashed user's password. Whirlpool will hash 128 characters + NULL*/

    INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
    INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
    INI_Int("Money",pInfo[playerid][Money]); //As explained above
    INI_Int("Scores",pInfo[playerid][Scores]);//As explained above
    INI_Int("Kills",pInfo[playerid][Kills]);//As explained above
    INI_Int("Deaths",pInfo[playerid][Deaths]);//As explained above
    INI_Int("Skin",pInfo[playerid][Skin]);//As explained above
    return 1;
}
//======================================== Player Joining ===================================//

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
    GetPlayerName(playerid,name,sizeof(name)); //Get player's name
    if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
    {// then
        INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
        ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_PASSWORD,"Login","{EE1289}Your account is registered on our server. Type in your password to login:","Login","Leave");/*A dialog with input style will appear so you can insert your password to login.*/
    }
    else //If the connected user is not registered,
    {//then we will 'force' him to register :)
        ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_PASSWORD,"Register","{EE1289}Your account is not registered on our server. Please type in your desired password to register:","Register","Leave");
        return 1;
    }
    return 1;
}
//==================== Dialog Response ========================//
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == dregister) //If dialog id is a register dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            if(!strlen(inputtext)) //If they didn't enter any password
            {// then we will tell to them to enter the password to register
                ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_PASSWORD,"Register","{EE1289}Your account is not registered on our server. Please type in your desired password to register:","Register","Quit");
                return 1;
            }
            //If they have entered a correct password for his/her account...
            new hashpass[129]; //Now we will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
            new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
            INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
            INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
            INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
            INI_WriteInt(file,"VIPLevel",0);//As explained above
            INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
            INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
            INI_WriteInt(file,"Kills",0);//As explained above
            INI_WriteInt(file,"Deaths",0);//As explained above
            INI_WriteInt(file,"Skin",23);//As explained above
            INI_Close(file);//Now after we've done saving their data, we now need to close the file
            SendClientMessage(playerid,0xEE128980,"You have successfully registered a new account on the server!");//Tell to them that they have successfully registered a new account
            SetPlayerPos(playerid,1127.4020,-2037.0612,69.8836);
            SetPlayerSkin(playerid, 23);
            return 1;
        }
    }
    if(dialogid == dlogin) //If dialog id is a login dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            new hashpass[129]; //Will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
            if(!strcmp(hashpass, pInfo[playerid][Pass], false)) //If they have insert their correct password
            {//then
                INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
                SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
                GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
                SendClientMessage(playerid,0xEE762180,"You have successfully logged in your account!");//Tell them that they've successfully logged in
            }
            else //If they've entered an incorrect password
            {//then
                ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","{EE1289}Your account is registered on our server. Type in your password to login:\n\n{FA1D2F}Failed attempt: Password is incorrect","Login","Quit");//We will tell to them that they've entered an incorrect password
                return 1;
            }
        }
    }
    return 1;
}
//=============================== Upon Player Leaving =============================//

public OnPlayerDisconnect(playerid, reason)
{
    //Same as OnDialogResponse, we will save their stats inside of their user's account
        new INI:file = INI_Open(Path(playerid)); //will open their file
        INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
        INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his money inside of his account
        INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
        INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
        INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
        INI_Close(file);//Now after we've done saving their data, we now need to close the file
        return 1;
}
//============================ Upon player Death ========================//
public OnPlayerDeath(playerid, killerid, reason)
{
    pInfo[killerid][Kills]++;//Will give 1 kill to killer and it will be saved inside of his/her account
    pInfo[playerid][Deaths]++;//Will give 1 death each time they die and it will be saved inside of his/her account
    return 1;
}
//================== Commands =======================//
CMD:stats(playerid,params[])

    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!");


Here's what I get after compiling:
pawn Код:
SAMP.pwn(171) : error 010: invalid function or declaration
SAMP.pwn(175) : error 010: invalid function or declaration
SAMP.pwn(179) : error 010: invalid function or declaration
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase

3 Errors.
Reply
#2

No one is going to guess what your line is..
Reply
#3

Can you show me the error lines?
Reply
#4

nvm.
Reply
#5

pawn Код:
Line 171:if(isnull(params))
Line 175: else if(IsPlayerConnected(id))
Line 179:else return SendClientMessage(playerid,0xFF000080,"Player has not logged in the server!");
Yes, /stats is my first command In script. I've learned scripting 3 weeks ago though.


@Facerafter, I got alot more errors by your lines:

pawn Код:
SAMP.pwn(173) : warning 202: number of arguments does not match definition
\SAMP.pwn(173) : warning 202: number of arguments does not match definition
SAMP.pwn(173) : error 035: argument type mismatch (argument 6)
SAMP.pwn(177) : warning 202: number of arguments does not match definition
SAMP.pwn(177) : warning 202: number of arguments does not match definition
SAMP.pwn(177) : error 035: argument type mismatch (argument 6)
SAMP.pwn(180) : warning 209: function "cmd_stats" should return a value
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


2 Errors.
Reply
#6

Lol.

First. You don't use sscanf correctly:

pawn Код:
if(sscanf(params, "u", id) return SendClientMessage(playerid, -1, "/Stats [ID]");
Then... ShowPlayerDialog. Lol lmfao. You can't do that. You need to format it.

pawn Код:
new string[128];
format(string, sizeof(string), "Account: %s\nMoney: $%d\nKills: %d\nDeaths: %d",GetPlayerName(playerid),GetPlayerMoney(playerid),pInfo[playerid][Kills],pInfo[playerid][Deaths]);
ShowPlayerDialog(playerid, dstats, DIALOG_STYLE_MSGBOX, "Account Stats", string, "Close", "");
Then. else & return? lol.

pawn Код:
else
{
    SendClientMessage(playerid,0xFF000080,"Player has not logged in the server!");
}
You don't check good if he's connected..

pawn Код:
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,0xFF000080,"Player has not logged in the server!");
Then continue with your code.
Reply
#7

nvm.
Reply
#8

@HY:

pawn Код:
CMD:stats(playerid,params[])

if(sscanf(params, "u", id) return SendClientMessage(playerid, -1, "/Stats [ID]");
{
    new string[128];
    format(string, sizeof(string), "Account: %s\nMoney: $%d\nKills: %d\nDeaths: %d",GetPlayerName(playerid),GetPlayerMoney(playerid),pInfo[playerid][Kills],pInfo[playerid][Deaths]);
    ShowPlayerDialog(playerid, dstats, DIALOG_STYLE_MSGBOX, "Account Stats", string, "Close", "");
}
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,0xFF000080,"Player has not logged in the server!");
< This is your code.

Errors:
pawn Код:
SA-MP\pawno\include\YSI\y_utils.inc(337) : warning 219: local variable "string" shadows a variable at a preceding level
SA-MP\pawno\include\YSI\y_utils.inc(491) : warning 219: local variable "string" shadows a variable at a preceding level
SA-MP\pawno\include\YSI\y_utils.inc(534) : warning 219: local variable "string" shadows a variable at a preceding level
SA-MP\pawno\include\YSI\y_utils.inc(552) : warning 219: local variable "string" shadows a variable at a preceding level
SA-MP\pawno\include\YSI\y_malloc.inc(216) : warning 219: local variable "string" shadows a variable at a preceding level
SA-MP\pawno\include\sscanf2.inc(305) : warning 219: local variable "string" shadows a variable at a preceding level
SA-MP\pawno\include\sscanf2.inc(305) : warning 219: local variable "string" shadows a variable at a preceding level
SA-MP\pawno\include\sscanf2.inc(365) : warning 219: local variable "string" shadows a variable at a preceding level
SA-MP\pawno\include\sscanf2.inc(365) : warning 219: local variable "string" shadows a variable at a preceding level
SA-MP\pawno\SAMP.pwn(170) : error 001: expected token: ")", but found "return"
SAMP.pwn(171) : warning 209: function "cmd_stats" should return a value
SAMP.pwn(171) : error 055: start of function body without function header
SAMP.pwn(173) : error 021: symbol already defined: "format"
SAMP.pwn(176) : error 010: invalid function or declaration
SAMP.pwn(177) : warning 203: symbol is never used: "string"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase
Reply
#9

PHP код:
if(sscanf(params"u"id)) return SendClientMessage(playerid, -1"/Stats [ID]"); 
And change all 'string' in this as string1 or string2 or anything. Because you already defined a string.
Reply
#10

Try this
pawn Код:
CMD:stats(playerid,params[])
{
     new string[128],pname[MAX_PLAYER_NAME];
     if(sscanf(params, "u", id)) return SendClientMessage(playerid, -1, "/Stats [ID]");
     if(!IsPlayerConnected(id)) return SendClientMessage(playerid,0xFF000080,"Player has not logged in the server!");
     {
          GetPlayerName(id, pname, sizeof(pname));
          format(string, sizeof(string), "Account: %s\nMoney: $%d\nKills: %d\nDeaths: %d",pname,GetPlayerMoney(id),pInfo[id][Kills],pInfo[id][Deaths]);
          ShowPlayerDialog(playerid, dstats, DIALOG_STYLE_MSGBOX, "Account Stats", string, "Close", "");
     }
     return 1;
}
This code would require to always have a ID filled in.
So if you want to check your owns stats you would have to fill in your own ID.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)