Jump to content

[7] Cum faci un sistem de inregistrare [DINI]


Gireada

Recommended Posts

In acest tutorial va voi arata cum sa faceti un sistem de inregistrare pe baza DINI.

In primul rand avem nevoide de bineinteles includerul DINI.

Pasul 1. Vom incepe sa punem includerele.

#include <a_samp>
#include <dini>
Pasul 2. Definim id-urile dialogurilor.
enum
{
    DIALOG_INREGISTRAT = 5,// 5 este numarul dialogului
    DIALOG_LOGIN //va avea id-ul 6
}
Pasul 3. Definim un enum, unde stocam variabilele unui jucator.
enum pData
{
   oras[30],
   varsta,
   sex[20],
   logged,
}
new P_Data[MAX_PLAYERS][pData];
new incercari[MAX_PLAYERS];
Pasul 4. Mergem la OnPlayerConnect si scriem:
new file[20+MAX_PLAYER_NAME];
format(file, sizeof(file), "/Jucatori/%s.ini", pName(playerid));//vom stoca in variabila file, locul unde se afla fisierul jucatorului
incercari[playerid] = 0;
if(!dini_Exists(file))
{
    //daca jucatorul nu este inregistrat
    ShowPlayerDialog(playerid, DIALOG_INREGISTRAT, DIALOG_STYLE_INPUT, "Inregistrare", "Scrieti parola pentru a te inregistra", "OK", "Cancel");
}
else
{
    //daca jucatorul este inregistrat
    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Logare", "Scrieti parola pentru a te loga", "OK", "Cancel");
}
Pasul 5. Mergem la OnPlayerRequestClass si la OnPlayerRequestSpawn si vom scrie acelasi lucru ca la pasul 4 Pasul 6. Mergem la OnDialogResponse si scriem:
new  file[20+MAX_PLAYER_NAME];
format(file, sizeof(file), "/Jucatori/%s.ini", pName(playerid));

switch(dialogid)
{
   case DIALOG_INREGISTRAT:
   {
  	if(!response) return Kick(playerid);//daca va da cancel ii vom da kick
  	else
  	{
     	    new pwlength = strlen(inputtext);
     	    if(pwlength > 3)//daca parola are mai mult de 3 caractere
     	   {
        	dini_Create(file); //vom creea fisierul
        	dini_Set(file, "parola", inputtext);//vom seta parola
                dini_Set(file, "oras", "Los Santos"); //vom seta orasul
                dini_IntSet(file, "varsta", 0);  //vom seta varsta
                dini_Set(file, "sex", "Barbat");   //vom seta sex-ul
                P_Data[playerid][logged] = 1;
                SpawnPlayer(playerid);
     	   }
     	   else
     	   {
        	ShowPlayerDialog(playerid, DIALOG_INREGISTRAT, DIALOG_STYLE_MSGBOX, "Inregistrare", "Trebuie sa introduci o parola!", "OK", "Cancel");
     	    }
  	}
   }
   case DIALOG_LOGIN:
   {
  	if(!response) Kick(playerid);
  	else
  	{
        incercari[playerid]++;
        if(incercari[playerid] == 3) return Kick(playerid);
     	new pwlength = strlen(inputtext);
     	if(pwlength > 3)
     	{
        	new pw[200];
        	format(pw, sizeof(pw), "%s", dini_Get(file, "parola");//stocam parola in variabila pw
        	if(strcmp(inputtext, pw) == 0) 
        	{
                    format(P_Data[MAX_PLAYERS][oras], 30, dini_Get(file, "oras");
                    P_Data[playerid][varsta] = dini_Get(file, "varsta");
                    format(P_Data[MAX_PLAYERS][sex], 20, dini_Get(file, "sex");
           	    P_Data[playerid][logged] = 1;
                    SpawnPlayer(playerid);
        	}
        	else
        	{
           	    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_MSGBOX, "Login", "Parola Gresita!", "OK", "Cancel");
        	}
     	}
     	else
     	{
        	ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_MSGBOX,  "Login", "Trebuie sa introduci o parola", "OK", "Cancel");
     	}
  	}
   }
Pasul 7. Mergem la sfarsitul gamemode-ului si scriem:
stock pName(playerid)
{
    new nume[MAX_PLAYER_NAME];
    GetPlayerName(playerid, nume, sizeof(nume));
    return nume;
}

Daca am facut vreo greseala va rog sa imi dati PM.

 

1859311972_BANNER-GIREADAcopy-min.thumb.png.48e5e420ae2185dce5b244965a1d2601.png

 

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...
  • 1 month later...
  • 3 months later...
  • 1 month later...

// This is a comment

// uncomment the line below if you want to write a filterscript

//#define FILTERSCRIPT

#include <a_samp>

#include <dini>

#if defined FILTERSCRIPT

enum

{

    DIALOG_INREGISTRAT = 5,// 5 este numarul dialogului

    DIALOG_LOGIN //va avea id-ul 6

}

enum pData

{

  oras[30],

  varsta,

  sex[20],

  logged,

}

new P_Data[MAX_PLAYERS][pData];

new incercari[MAX_PLAYERS];

public OnFilterScriptInit()

{

print("\n--------------------------------------");

print(" Blank Filterscript by your name here");

print("--------------------------------------\n");

return 1;

}

public OnFilterScriptExit()

{

return 1;

}

#else

main()

{

print("\n----------------------------------");

print(" Blank Gamemode by your name here");

print("----------------------------------\n");

}

#endif

public OnGameModeInit()

{

// Don't use these lines if it's a filterscript

SetGameModeText("Blank Script");

AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);

return 1;

}

public OnGameModeExit()

{

return 1;

}

public OnPlayerRequestClass(playerid, classid)

{

new file[20+MAX_PLAYER_NAME];

format(file, sizeof(file), "/Jucatori/%s.ini", pName(playerid));//vom stoca in variabila file, locul unde se afla fisierul jucatorului

incercari[playerid] = 0;

if(!dini_Exists(file))

{

    //daca jucatorul nu este inregistrat

    ShowPlayerDialog(playerid, DIALOG_INREGISTRAT, DIALOG_STYLE_INPUT, "Inregistrare", "Scrieti parola pentru a te inregistra", "OK", "Cancel");

}

else

{

    //daca jucatorul este inregistrat

    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Logare", "Scrieti parola pentru a te loga", "OK", "Cancel");

}

SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);

SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);

SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);

return 1;

}

public OnPlayerConnect(playerid)

{

new file[20+MAX_PLAYER_NAME];

format(file, sizeof(file), "/Jucatori/%s.ini", pName(playerid));//vom stoca in variabila file, locul unde se afla fisierul jucatorului

incercari[playerid] = 0;

if(!dini_Exists(file))

{

    //daca jucatorul nu este inregistrat

    ShowPlayerDialog(playerid, DIALOG_INREGISTRAT, DIALOG_STYLE_INPUT, "Inregistrare", "Scrieti parola pentru a te inregistra", "OK", "Cancel");

}

else

{

    //daca jucatorul este inregistrat

    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Logare", "Scrieti parola pentru a te loga", "OK", "Cancel");

}

return 1;

}

public OnPlayerDisconnect(playerid, reason)

{

return 1;

}

public OnPlayerSpawn(playerid)

{

return 1;

}

public OnPlayerDeath(playerid, killerid, reason)

{

return 1;

}

public OnVehicleSpawn(vehicleid)

{

return 1;

}

public OnVehicleDeath(vehicleid, killerid)

{

return 1;

}

public OnPlayerText(playerid, text[])

{

return 1;

}

public OnPlayerCommandText(playerid, cmdtext[])

{

if (strcmp("/mycommand", cmdtext, true, 10) == 0)

{

// Do something here

return 1;

}

return 0;

}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)

{

return 1;

}

public OnPlayerExitVehicle(playerid, vehicleid)

{

return 1;

}

public OnPlayerStateChange(playerid, newstate, oldstate)

{

return 1;

}

public OnPlayerEnterCheckpoint(playerid)

{

return 1;

}

public OnPlayerLeaveCheckpoint(playerid)

{

return 1;

}

public OnPlayerEnterRaceCheckpoint(playerid)

{

return 1;

}

public OnPlayerLeaveRaceCheckpoint(playerid)

{

return 1;

}

public OnRconCommand(cmd[])

{

return 1;

}

public OnPlayerRequestSpawn(playerid)

{

new file[20+MAX_PLAYER_NAME];

format(file, sizeof(file), "/Jucatori/%s.ini", pName(playerid));//vom stoca in variabila file, locul unde se afla fisierul jucatorului

incercari[playerid] = 0;

if(!dini_Exists(file))

{

    //daca jucatorul nu este inregistrat

    ShowPlayerDialog(playerid, DIALOG_INREGISTRAT, DIALOG_STYLE_INPUT, "Inregistrare", "Scrieti parola pentru a te inregistra", "OK", "Cancel");

}

else

{

    //daca jucatorul este inregistrat

    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Logare", "Scrieti parola pentru a te loga", "OK", "Cancel");

}

return 1;

}

public OnObjectMoved(objectid)

{

return 1;

}

public OnPlayerObjectMoved(playerid, objectid)

{

return 1;

}

public OnPlayerPickUpPickup(playerid, pickupid)

{

return 1;

}

public OnVehicleMod(playerid, vehicleid, componentid)

{

return 1;

}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)

{

return 1;

}

public OnVehicleRespray(playerid, vehicleid, color1, color2)

{

return 1;

}

public OnPlayerSelectedMenuRow(playerid, row)

{

return 1;

}

public OnPlayerExitedMenu(playerid)

{

return 1;

}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)

{

return 1;

}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)

{

return 1;

}

public OnRconLoginAttempt(ip[], password[], success)

{

return 1;

}

public OnPlayerUpdate(playerid)

{

return 1;

}

public OnPlayerStreamIn(playerid, forplayerid)

{

return 1;

}

public OnPlayerStreamOut(playerid, forplayerid)

{

return 1;

}

public OnVehicleStreamIn(vehicleid, forplayerid)

{

return 1;

}

public OnVehicleStreamOut(vehicleid, forplayerid)

{

return 1;

}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])

{

new  file[20+MAX_PLAYER_NAME];

format(file, sizeof(file), "/Jucatori/%s.ini", pName(playerid));

switch(dialogid)

{

  case DIALOG_INREGISTRAT:

  {

  if(!response) return Kick(playerid);//daca va da cancel ii vom da kick

  else

  {

        new pwlength = strlen(inputtext);

        if(pwlength > 3)//daca parola are mai mult de 3 caractere

      {

        dini_Create(file); //vom creea fisierul

        dini_Set(file, "parola", inputtext);//vom seta parola

                dini_Set(file, "oras", "Los Santos"); //vom seta orasul

                dini_IntSet(file, "varsta", 0);  //vom seta varsta

                dini_Set(file, "sex", "Barbat");  //vom seta sex-ul

                P_Data[playerid][logged] = 1;

                SpawnPlayer(playerid);

      }

      else

      {

        ShowPlayerDialog(playerid, DIALOG_INREGISTRAT, DIALOG_STYLE_MSGBOX, "Inregistrare", "Trebuie sa introduci o parola!", "OK", "Cancel");

        }

  }

  }

  case DIALOG_LOGIN:

  {

  if(!response) Kick(playerid);

  else

  {

        incercari[playerid]++;

        if(incercari[playerid] == 3) return Kick(playerid);

    new pwlength = strlen(inputtext);

    if(pwlength > 3)

    {

        new pw[200];

        format(pw, sizeof(pw), "%s", dini_Get(file, "parola");//stocam parola in variabila pw

        if(strcmp(inputtext, pw) == 0)

        {

                    format(P_Data[MAX_PLAYERS][oras], 30, dini_Get(file, "oras");

                    P_Data[playerid][varsta] = dini_Get(file, "varsta");

                    format(P_Data[MAX_PLAYERS][sex], 20, dini_Get(file, "sex");

              P_Data[playerid][logged] = 1;

                    SpawnPlayer(playerid);

        }

        else

        {

              ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_MSGBOX, "Login", "Parola Gresita!", "OK", "Cancel");

        }

    }

    else

    {

        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_MSGBOX,  "Login", "Trebuie sa introduci o parola", "OK", "Cancel");

    }

  }

  }

return 1;

}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)

{

return 1;

}

stock pName(playerid)

{

    new nume[MAX_PLAYER_NAME];

    GetPlayerName(playerid, nume, sizeof(nume));

    return nume;

}

si erroarile

C:\Users\Desktop\SERVER OFF\samp servere\server samp de la zero\pawno\Untitled.pwn(66) : error 017: undefined symbol "incercari"

C:\Users\Desktop\SERVER OFF\samp servere\server samp de la zero\pawno\Untitled.pwn(66) : warning 215: expression has no effect

C:\Users\Desktop\SERVER OFF\samp servere\server samp de la zero\pawno\Untitled.pwn(66) : error 001: expected token: ";", but found "]"

C:\Users\Desktop\SERVER OFF\samp servere\server samp de la zero\pawno\Untitled.pwn(66) : error 029: invalid expression, assumed zero

C:\Users\Desktop\SERVER OFF\samp servere\server samp de la zero\pawno\Untitled.pwn(66) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase

4 Errors.

ce trebuie sa fac pentru a rezolva problema ?

Link to comment
Share on other sites

C:\Users\laceanu cel voinic\Desktop\0 de la nenea George\gamemodes\gamemode.pwn(171) : warning 217: loose indentation

C:\Users\laceanu cel voinic\Desktop\0 de la nenea George\gamemodes\gamemode.pwn(271) : warning 217: loose indentation

C:\Users\laceanu cel voinic\Desktop\0 de la nenea George\gamemodes\gamemode.pwn(277) : warning 217: loose indentation

C:\Users\laceanu cel voinic\Desktop\0 de la nenea George\gamemodes\gamemode.pwn(294) : error 001: expected token: ",", but found ";"

C:\Users\laceanu cel voinic\Desktop\0 de la nenea George\gamemodes\gamemode.pwn(297) : error 032: array index out of bounds (variable "P_Data")

C:\Users\laceanu cel voinic\Desktop\0 de la nenea George\gamemodes\gamemode.pwn(297) : error 001: expected token: ",", but found ";"

C:\Users\laceanu cel voinic\Desktop\0 de la nenea George\gamemodes\gamemode.pwn(298) : error 006: must be assigned to an array

C:\Users\laceanu cel voinic\Desktop\0 de la nenea George\gamemodes\gamemode.pwn(299) : error 032: array index out of bounds (variable "P_Data")

C:\Users\laceanu cel voinic\Desktop\0 de la nenea George\gamemodes\gamemode.pwn(299) : error 001: expected token: ",", but found ";"

C:\Users\laceanu cel voinic\Desktop\0 de la nenea George\gamemodes\gamemode.pwn(300) : warning 217: loose indentation

C:\Users\laceanu cel voinic\Desktop\0 de la nenea George\gamemodes\gamemode.pwn(301) : warning 217: loose indentation

C:\Users\laceanu cel voinic\Desktop\0 de la nenea George\gamemodes\gamemode.pwn(314) : error 002: only a single statement (or expression) can follow each "case"

C:\Users\laceanu cel voinic\Desktop\0 de la nenea George\gamemodes\gamemode.pwn(314) : warning 215: expression has no effect

C:\Users\laceanu cel voinic\Desktop\0 de la nenea George\gamemodes\gamemode.pwn(315) : warning 209: function "OnDialogResponse" should return a value

Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase

[pawn]// This is a comment

// uncomment the line below if you want to write a filterscript

//#define FILTERSCRIPT

#include <a_samp>

#include <dini>

enum

{

    DIALOG_INREGISTRAT = 5,// 5 este numarul dialogului

    DIALOG_LOGIN //va avea id-ul 6

}

enum pData

{

  oras[30],

  varsta,

  sex[20],

  logged,

}

new P_Data[MAX_PLAYERS][pData];

new incercari[MAX_PLAYERS];

main()

{

print("\n----------------------------------");

print("RPG/RP by POL_george");

print("----------------------------------\n");

}

public OnGameModeInit()

{

SetGameModeText("RPG/RP");

return 1;

}

public OnGameModeExit()

{

return 1;

}

public OnPlayerRequestClass(playerid, classid)

{

new file[20+MAX_PLAYER_NAME];

format(file, sizeof(file), "/Jucatori/%s.ini", pName(playerid));//vom stoca in variabila file, locul unde se afla fisierul jucatorului

incercari[playerid] = 0;

if(!dini_Exists(file))

{

    //daca jucatorul nu este inregistrat

    ShowPlayerDialog(playerid, DIALOG_INREGISTRAT, DIALOG_STYLE_INPUT, "Inregistrare", "Scrieti parola pentru a te inregistra", "OK", "Cancel");

}

else

{

    //daca jucatorul este inregistrat

    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Logare", "Scrieti parola pentru a te loga", "OK", "Cancel");

}

return 1;

}

public OnPlayerConnect(playerid)

{

new file[20+MAX_PLAYER_NAME];

format(file, sizeof(file), "/Jucatori/%s.ini", pName(playerid));//vom stoca in variabila file, locul unde se afla fisierul jucatorului

incercari[playerid] = 0;

if(!dini_Exists(file))

{

    //daca jucatorul nu este inregistrat

    ShowPlayerDialog(playerid, DIALOG_INREGISTRAT, DIALOG_STYLE_INPUT, "Inregistrare", "Scrieti parola pentru a te inregistra", "OK", "Cancel");

}

else

{

    //daca jucatorul este inregistrat

    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Logare", "Scrieti parola pentru a te loga", "OK", "Cancel");

}

return 1;

}

public OnPlayerDisconnect(playerid, reason)

{

return 1;

}

public OnPlayerSpawn(playerid)

{

return 1;

}

public OnPlayerDeath(playerid, killerid, reason)

{

return 1;

}

public OnVehicleSpawn(vehicleid)

{

return 1;

}

public OnVehicleDeath(vehicleid, killerid)

{

return 1;

}

public OnPlayerText(playerid, text[])

{

return 1;

}

public OnPlayerCommandText(playerid, cmdtext[])

{

if (strcmp("/mycommand", cmdtext, true, 10) == 0)

{

// Do something here

return 1;

}

return 0;

}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)

{

return 1;

}

public OnPlayerExitVehicle(playerid, vehicleid)

{

return 1;

}

public OnPlayerStateChange(playerid, newstate, oldstate)

{

return 1;

}

public OnPlayerEnterCheckpoint(playerid)

{

return 1;

}

public OnPlayerLeaveCheckpoint(playerid)

{

return 1;

}

public OnPlayerEnterRaceCheckpoint(playerid)

{

return 1;

}

public OnPlayerLeaveRaceCheckpoint(playerid)

{

return 1;

}

public OnRconCommand(cmd[])

{

return 1;

}

public OnPlayerRequestSpawn(playerid)

{

new file[20+MAX_PLAYER_NAME];

format(file, sizeof(file), "/Jucatori/%s.ini", pName(playerid));//vom stoca in variabila file, locul unde se afla fisierul jucatorului

incercari[playerid] = 0;

if(!dini_Exists(file))

{

    //daca jucatorul nu este inregistrat

    ShowPlayerDialog(playerid, DIALOG_INREGISTRAT, DIALOG_STYLE_INPUT, "Inregistrare", "Scrieti parola pentru a te inregistra", "OK", "Cancel");

}

else

{

    //daca jucatorul este inregistrat

    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Logare", "Scrieti parola pentru a te loga", "OK", "Cancel");

}

return 1;

}

public OnObjectMoved(objectid)

{

return 1;

}

public OnPlayerObjectMoved(playerid, objectid)

{

return 1;

}

public OnPlayerPickUpPickup(playerid, pickupid)

{

return 1;

}

public OnVehicleMod(playerid, vehicleid, componentid)

{

return 1;

}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)

{

return 1;

}

public OnVehicleRespray(playerid, vehicleid, color1, color2)

{

return 1;

}

public OnPlayerSelectedMenuRow(playerid, row)

{

return 1;

}

public OnPlayerExitedMenu(playerid)

{

return 1;

}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)

{

return 1;

}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)

{

return 1;

}

public OnRconLoginAttempt(ip[], password[], success)

{

return 1;

}

public OnPlayerUpdate(playerid)

{

return 1;

}

public OnPlayerStreamIn(playerid, forplayerid)

{

return 1;

}

public OnPlayerStreamOut(playerid, forplayerid)

{

return 1;

}

public OnVehicleStreamIn(vehicleid, forplayerid)

{

return 1;

}

public OnVehicleStreamOut(vehicleid, forplayerid)

{

return 1;

}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])

{

new  file[20+MAX_PLAYER_NAME];

format(file, sizeof(file), "/Jucatori/%s.ini", pName(playerid));

switch(dialogid)

{

  case DIALOG_INREGISTRAT:

  {

  if(!response) return Kick(playerid);//daca va da cancel ii vom da kick

  else

  {

        new pwlength = strlen(inputtext);

        if(pwlength > 3)//daca parola are mai mult de 3 caractere

      {

        dini_Create(file); //vom creea fisierul

        dini_Set(file, "parola", inputtext);//vom seta parola

                dini_Set(file, "oras", "Los Santos"); //vom seta orasul

                dini_IntSet(file, "varsta", 0);  //vom seta varsta

                dini_Set(file, "sex", "Barbat");  //vom seta sex-ul

                P_Data[playerid][logged] = 1;

                SpawnPlayer(playerid);

      }

      else

      {

        ShowPlayerDialog(playerid, DIALOG_INREGISTRAT, DIALOG_STYLE_MSGBOX, "Inregistrare", "Trebuie sa introduci o parola!", "OK", "Cancel");

        }

  }

  }

  case DIALOG_LOGIN:

  {

  if(!response) Kick(playerid);

  else

  {

        incercari[playerid]++;

        if(incercari[playerid] == 3) return Kick(playerid);

    new pwlength = strlen(inputtext);

    if(pwlength > 3)

    {

        new pw[200];

        format(pw, sizeof(pw), "%s", dini_Get(file, "parola");//stocam parola in variabila pw

        if(strcmp(inputtext, pw) == 0)

        {

                    format(P_Data[MAX_PLAYERS][oras], 30, dini_Get(file, "oras");

                    P_Data[playerid][varsta] = dini_Get(file, "varsta");

                    format(P_Data[MAX_PLAYERS][sex], 20, dini_Get(file, "sex");

              P_Data[playerid][logged] = 1;

                    SpawnPlayer(playerid);

        }

        else

        {

              ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_MSGBOX, "Login", "Parola Gresita!", "OK", "Cancel");

        }

    }

    else

    {

        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_MSGBOX,  "Login", "Trebuie sa introduci o parola", "OK", "Cancel");

    }

  }

  }

return 1;

}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)

{

return 1;

}

stock pName(playerid)

{

    new nume[MAX_PLAYER_NAME];

    GetPlayerName(playerid, nume, sizeof(nume));

    return nume;

}[/pawn]

Link to comment
Share on other sites

Gireada ma ajuti ?

In acest tutorial va voi arata cum sa faceti un sistem de inregistrare pe baza DINI.

In primul rand avem nevoide de bineinteles includerul DINI.

Pasul 1. Vom incepe sa punem includerele.

#include <a_samp>
#include <dini>
Pasul 2. Definim id-urile dialogurilor.
enum
{
    DIALOG_INREGISTRAT = 5,// 5 este numarul dialogului
    DIALOG_LOGIN //va avea id-ul 6
}
Pasul 3. Definim un enum, unde stocam variabilele unui jucator.
enum pData
{
   oras[30],
   varsta,
   sex[20],
   logged,
}
new P_Data[MAX_PLAYERS][pData];
new incercari[MAX_PLAYERS];
Pasul 4. Mergem la OnPlayerConnect si scriem:
new file[20+MAX_PLAYER_NAME];
format(file, sizeof(file), "/Jucatori/%s.ini", pName(playerid));//vom stoca in variabila file, locul unde se afla fisierul jucatorului
incercari[playerid] = 0;
if(!dini_Exists(file))
{
    //daca jucatorul nu este inregistrat
    ShowPlayerDialog(playerid, DIALOG_INREGISTRAT, DIALOG_STYLE_INPUT, "Inregistrare", "Scrieti parola pentru a te inregistra", "OK", "Cancel");
}
else
{
    //daca jucatorul este inregistrat
    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Logare", "Scrieti parola pentru a te loga", "OK", "Cancel");
}
Pasul 5. Mergem la OnPlayerRequestClass si la OnPlayerRequestSpawn si vom scrie acelasi lucru ca la pasul 4 Pasul 6. Mergem la OnDialogResponse si scriem:
new  file[20+MAX_PLAYER_NAME];
format(file, sizeof(file), "/Jucatori/%s.ini", pName(playerid));

switch(dialogid)
{
   case DIALOG_INREGISTRAT:
   {
  	if(!response) return Kick(playerid);//daca va da cancel ii vom da kick
  	else
  	{
     	    new pwlength = strlen(inputtext);
     	    if(pwlength > 3)//daca parola are mai mult de 3 caractere
     	   {
        	dini_Create(file); //vom creea fisierul
        	dini_Set(file, "parola", inputtext);//vom seta parola
                dini_Set(file, "oras", "Los Santos"); //vom seta orasul
                dini_IntSet(file, "varsta", 0);  //vom seta varsta
                dini_Set(file, "sex", "Barbat");   //vom seta sex-ul
                P_Data[playerid][logged] = 1;
                SpawnPlayer(playerid);
     	   }
     	   else
     	   {
        	ShowPlayerDialog(playerid, DIALOG_INREGISTRAT, DIALOG_STYLE_MSGBOX, "Inregistrare", "Trebuie sa introduci o parola!", "OK", "Cancel");
     	    }
  	}
   }
   case DIALOG_LOGIN:
   {
  	if(!response) Kick(playerid);
  	else
  	{
        incercari[playerid]++;
        if(incercari[playerid] == 3) return Kick(playerid);
     	new pwlength = strlen(inputtext);
     	if(pwlength > 3)
     	{
        	new pw[200];
        	format(pw, sizeof(pw), "%s", dini_Get(file, "parola");//stocam parola in variabila pw
        	if(strcmp(inputtext, pw) == 0) 
        	{
                    format(P_Data[MAX_PLAYERS][oras], 30, dini_Get(file, "oras");
                    P_Data[playerid][varsta] = dini_Get(file, "varsta");
                    format(P_Data[MAX_PLAYERS][sex], 20, dini_Get(file, "sex");
           	    P_Data[playerid][logged] = 1;
                    SpawnPlayer(playerid);
        	}
        	else
        	{
           	    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_MSGBOX, "Login", "Parola Gresita!", "OK", "Cancel");
        	}
     	}
     	else
     	{
        	ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_MSGBOX,  "Login", "Trebuie sa introduci o parola", "OK", "Cancel");
     	}
  	}
   }
Pasul 7. Mergem la sfarsitul gamemode-ului si scriem:
stock pName(playerid)
{
    new nume[MAX_PLAYER_NAME];
    GetPlayerName(playerid, nume, sizeof(nume));
    return nume;
}

Daca am facut vreo greseala va rog sa imi dati PM.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.