SA-MP Forums Archive
Adding a parameter to a command, and if that is right... - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Adding a parameter to a command, and if that is right... (/showthread.php?tid=361629)



Adding a parameter to a command, and if that is right... - The__ - 21.07.2012

So I got this command.
pawn Код:
dcmd_secretthing(playerid, params[])
{
    if(sscanf(params, "password[32]", result)) return SendClientMessage(playerid, COLOR_GRAD2, "Wrong password.");
    if(passwordcorrect)
    {
         ...
    }
    return 1;
}
How to make it like, /buy 1, so I can make like, /secretthing 3534635, and that number will be the password.


Re: Adding a parameter to a command, and if that is right... - The__ - 22.07.2012

bump.


Re: Adding a parameter to a command, and if that is right... - Kindred - 22.07.2012

First, let me ask this, is there ONE password you need? Like, you do not want to set it in game and then use a command with that password?

If you want to change it in-game, and save it, and then load it on gamemode startup, tell me what file saving system you use.


Re: Adding a parameter to a command, and if that is right... - The__ - 22.07.2012

No, just a gamemode password, like, only /secretthing sercretpassword


Re: Adding a parameter to a command, and if that is right... - ReneG - 22.07.2012

An example using ZCMD.

pawn Код:
CMD:secretthing(playerid, params[])
{
    if(isnull(params))
    {
        SendClientMessage(playerid, -1, "USAGE: /secretthing [password]");
        return 1;  
    }
   
    if(!strcmp(params, "secretpassword"))
    {
        // if they typed "secret password"
        // this section will be ran.
        SendClientMessage(playerid, -1, "Right password!");
        return 1;
    }
   
    else
    {
        // the password was wrong
        SendClientMessage(playerid, -1, "Wrong password!");
    }
    return 1;
}



Re: Adding a parameter to a command, and if that is right... - maramizo - 22.07.2012

pawn Код:
dcmd_secretthing(playerid, params[])
{
    new result[32];
    if(sscanf(params, "s[32]", result)) return SendClientMessage(playerid, COLOR_GRAD2, "Wrong password.");
    if(passwordcorrect)
    {
         ...    return 1;
}



Re: Adding a parameter to a command, and if that is right... - The__ - 22.07.2012

Will this work ?
pawn Код:
dcmd_secret(playerid, params[])
{
    new result;
    if(sscanf(params, "d", result)) return SendClientMessage(playerid, COLOR_GRAD2, "...");
    if(!strcmp(params,"..",true) == 0 && IsPlayerInRangeOfPoint(playerid, 5.0, ...))
    {
         ...
    }
    else
    {
        SendClientMessage(playerid, COLOR_GRAD2, "Wrong password.");
        return 1;
    }
    return 1;
}



Re: Adding a parameter to a command, and if that is right... - Kindred - 22.07.2012

Not sure. It might, but let me fix one simple thing up for you:

pawn Код:
dcmd_secret(playerid, params[])
{
    new result[128];
    if(sscanf(params, "s[128]", result)) return SendClientMessage(playerid, COLOR_GRAD2, "...");
    if(!strcmp(result,"..",true) == 0 && IsPlayerInRangeOfPoint(playerid, 5.0, ...))
    {
         ...
    }
    else
    {
        SendClientMessage(playerid, COLOR_GRAD2, "Wrong password.");
        return 1;
    }
    return 1;
}
I made it so its using result instead of params, considering you are using at first, why not again.

Plus, you made it an integer, meaning it MUST be numbers (no decimals either), so I changed it to a string so you can have numbers AND letters in it.

PS: change 128 to the largest thing string size you want the password, meaning if the string will ONLY be test, just lower it down to 4 characters.


Re: Adding a parameter to a command, and if that is right... - The__ - 22.07.2012

Quote:
Originally Posted by Kindred
Посмотреть сообщение
Not sure. It might, but let me fix one simple thing up for you:

pawn Код:
dcmd_secret(playerid, params[])
{
    new result[128];
    if(sscanf(params, "s[128]", result)) return SendClientMessage(playerid, COLOR_GRAD2, "...");
    if(!strcmp(result,"..",true) == 0 && IsPlayerInRangeOfPoint(playerid, 5.0, ...))
    {
         ...
    }
    else
    {
        SendClientMessage(playerid, COLOR_GRAD2, "Wrong password.");
        return 1;
    }
    return 1;
}
I made it so its using result instead of params, considering you are using at first, why not again.

Plus, you made it an integer, meaning it MUST be numbers (no decimals either), so I changed it to a string so you can have numbers AND letters in it.

PS: change 128 to the largest thing string size you want the password, meaning if the string will ONLY be test, just lower it down to 4 characters.
Tag mismatch, at argument 1 here.
pawn Код:
if(!strcmp(result,"9999",true) == 0 && IsPlayerInRangeOfPoint(playerid, 5.0, X,Y,Z))



Re: Adding a parameter to a command, and if that is right... - The__ - 23.07.2012

Fixed.