Help Converting Dialog To CMD
#1

Hey I got this code:
Код:
if(dialogid == 201)
    {
        if(!strlen(inputtext)) return ShowPlayerDialog(playerid,201,DIALOG_STYLE_INPUT,"Registration","ERROR: You did not enter a password.\nPlease enter a password to register this account!","Register","Cancel");
        new playerfile[128], pname[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pname, sizeof(pname));
        format(playerfile, sizeof(playerfile), "EAdmin/Users/%s.ini",pname);
         if(dini_Exists(playerfile)) return SendClientMessage(playerid, red, "You are already registered!");
        new playerip[20];
        GetPlayerIp(playerid, playerip, sizeof(playerip));
        dini_Create(playerfile);
          dini_IntSet(playerfile, "Password", udb_hash(inputtext));
        dini_Set(playerfile, "Ip", playerip);
        dini_IntSet(playerfile, "Level", 0);
        dini_IntSet(playerfile, "Cash", 0);
        dini_IntSet(playerfile, "Score", 0);
        logged[playerid] = 1;
        SendClientMessage(playerid, yellow, "You have registered your account! You have also been logged in.");
    }
    if(dialogid == 200)
    {
        if(!strlen(inputtext)) return ShowPlayerDialog(playerid,200,DIALOG_STYLE_INPUT,"Login","ERROR: You did not enter a password.\nPlease enter a password to login to this account!","Login","Cancel");
        new playerfile[100], pname[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pname, sizeof(pname));
        format(playerfile, sizeof(playerfile), "EAdmin/Users/%s.ini",pname);
         if(!dini_Exists(playerfile)) return SendClientMessage(playerid, red, "This account is not yet registered, please type /register.");
        new tmp[256];
        tmp = dini_Get(playerfile, "Password");
        if(udb_hash(inputtext) == strval(tmp))
        {
        new playerip[20];
        GetPlayerIp(playerid, playerip, sizeof(playerip));
        level[playerid] = dini_Int(playerfile, "Level");
        logged[playerid] = 1;
        dini_Set(playerfile, "Ip", playerip);
        GivePlayerMoney(playerid, dini_Int(playerfile, "Cash"));
        SetPlayerScore(playerid, dini_Int(playerfile, "Score"));
        logged[playerid] = 1;
        SendClientMessage(playerid, yellow, "You have logged in!");
        } else return ShowPlayerDialog(playerid,200,DIALOG_STYLE_INPUT,"Login","ERROR: Invalid Password.\nPlease enter a password to login to this account!","Login","Cancel");
    }
I want to switch these to a command like /login [password] and /register [password]

Can anyone help me out PS: I tried it but I failed
Reply
#2

Quote:
Originally Posted by Hal
Посмотреть сообщение
Hey pro scripter, if i pay you can you fix the problem i have in the topic above me?
Hey asshole, can you help people or just flame?

You need to create the commands, use dcmd or zcmd. When finished it will look something like this (this code is untested):

Код:
public OnPlayerCommandText(playerid, cmdtext[]) {
     dcmd(login, 5, cmdtext);
     dcmd(register, 8, cmdtext);

     return 1;
}

dcmd_login(playerid, params) {
     ShowPlayerDialog(playerid,201,DIALOG_STYLE_INPUT,"Registration",Please enter a password to register this account!","Register","Cancel");

     return 1;
}

dcmd_register(playerid, params) {
     ShowPlayerDialog(playerid,200,DIALOG_STYLE_INPUT,"Login","Please enter a password to login to this account!","Login","Cancel");

     return 1;
}
Reply
#3

I never said strcmp is better, learn to read.
I'm just saying that even if dcmd and zcmd is better, faster and more efficient, you shouldn't "force him" to use it. It still is optional, so by saying "use dcmd or zcmd" you're telling him that it won't work elseway.
What if he's not familiar with zcmd or dcmd? What if he don't know how to use it? What if he's not smart enough (most likely) to learn zcmd or dcmd?
I'm just saying.
Reply
#4

strcmp is better when you have a command which has only one ( string ) parameter

and strtok is better when you have a command with an indeterminate number of parameters

pawn Код:
CMD:gethere(playerid,params[])
{
     new tmp[25],idx,targetid;
     new Float:x,Float:y,Float:z;
     GetPlayerPos(playerid,x,y,z);
     tmp = strtok(params, idx);
     while(strlen(tmp) > 0)
     {
           targetid = ReturnUser(tmp);
           if(IsPlayerConnected(targetid))
           {
                SetPlayerPos(targetid,x,y+1,z);
           }
           tmp = strtok(params,idx);
     }
      return 1;
}
ps: this is just a rough example
Reply
#5

Quote:
Originally Posted by Rachael
Посмотреть сообщение
strcmp is better when you have a command which has only one ( string ) parameter

and strtok is better when you have a command with an indeterminate number of parameters

pawn Код:
CMD:gethere(playerid,params[])
{
     new tmp[25],idx,targetid
     new Float:x,Float:y,Float:z;
     GetPlayerPos(playerid,x,y,z);
     tmp = strtok(params, idx);
     while(strlen(tmp) > 0)
     {
           targetid = ReturnUser(tmp);
           if(IsPlayerConnected(targetid))
           {
                SetPlayerPos(targetid,x,y+1,z);
           }
           tmp = strtok(params,idx);
     }
      return 1;
}
ps: this is just a rough example
Zcmd + sscanf(2) is best no matter how many params you have.

And never, ever, ever, ever, ever! use strtok together with zcmd.
That's like putting a Lada engine in a Ferrari, just ridiculous.
Reply
#6

how would you script the command I used as an example with sscanf?
Reply
#7

pawn Код:
CMD:gethere(playerid,params[])
{
    new
        Float:x,
        Float:y,
        Float:z,
        iPlayer;

    if(sscanf(params, "u", iPlayer))
        return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /gethere [playerid/part of name]");
    GetPlayerPos(playerid,x,y,z);
    SetPlayerPos(targetid,x,y+1,z);
    return 1;
}
Reply
#8

Quote:
Originally Posted by LarzI
Посмотреть сообщение
I never said strcmp is better, learn to read.
I'm just saying that even if dcmd and zcmd is better, faster and more efficient, you shouldn't "force him" to use it. It still is optional, so by saying "use dcmd or zcmd" you're telling him that it won't work elseway.
What if he's not familiar with zcmd or dcmd? What if he don't know how to use it? What if he's not smart enough (most likely) to learn zcmd or dcmd?
I'm just saying.
I know how to read. Why are people so quick to flame? I'm not forcing him to use anything, I am suggesting the best usage for programming in pawn. If he doesn't know how to use it, he should learn. I posted an example to show him. If he's not smart enough to learn from it, it's not my problem. I'm not going to dumb down my suggestions.
Reply
#9

you can read about / download the zcmd include here
https://sampforum.blast.hk/showthread.php?tid=91354

converting from dialogue is pretty simple then
pawn Код:
#include <zcmd>


CMD:register(playerid,params[])
{
    if(isnull(params)) return SendClientMessage(playerid,yellow,"Registration","ERROR: You did not enter a password.");
    new playerfile[128], pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    format(playerfile, sizeof(playerfile), "EAdmin/Users/%s.ini",pname);
    if(dini_Exists(playerfile)) return SendClientMessage(playerid, red, "You are already registered!");
    new playerip[20];
    GetPlayerIp(playerid, playerip, sizeof(playerip));
    dini_Create(playerfile);
    dini_IntSet(playerfile, "Password", udb_hash(inputtext));
    dini_Set(playerfile, "Ip", playerip);
    dini_IntSet(playerfile, "Level", 0);
    dini_IntSet(playerfile, "Cash", 0);
    dini_IntSet(playerfile, "Score", 0);
    logged[playerid] = 1;
    SendClientMessage(playerid, yellow, "You have registered your account! You have also been logged in.");
    return 1;
}
CMD:login(playerid,params[])
{
    if(isnull(params)) return SendClientMessage(playerid,yellow,"Login","ERROR: You did not enter a password.");
    new playerfile[100], pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    format(playerfile, sizeof(playerfile), "EAdmin/Users/%s.ini",pname);
     if(!dini_Exists(playerfile)) return SendClientMessage(playerid, red, "This account is not yet registered, please type /register.");
    new tmp[256];
    tmp = dini_Get(playerfile, "Password");
    if(udb_hash(inputtext) == strval(tmp))
    {
        new playerip[20];
        GetPlayerIp(playerid, playerip, sizeof(playerip));
        level[playerid] = dini_Int(playerfile, "Level");
        logged[playerid] = 1;
        dini_Set(playerfile, "Ip", playerip);
        GivePlayerMoney(playerid, dini_Int(playerfile, "Cash"));
        SetPlayerScore(playerid, dini_Int(playerfile, "Score"));
        logged[playerid] = 1;
        SendClientMessage(playerid, yellow, "You have logged in!");
    } else  {
        SendClientMessage(playerid,yellow,"Login","ERROR: Invalid Password");
        return 1;
    }
    return 1;
}
Reply
#10

i GOT IT WORKING THX TO U
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)