Adding a parameter to a command, and if that is right...
#1

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.
Reply
#2

bump.
Reply
#3

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.
Reply
#4

No, just a gamemode password, like, only /secretthing sercretpassword
Reply
#5

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;
}
Reply
#6

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;
}
Reply
#7

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;
}
Reply
#8

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.
Reply
#9

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))
Reply
#10

Fixed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)