[HELP] I need help with register/login system
#1

PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
    
dcmd(infammoon9cmdtext);
    
dcmd(infammooff10cmdtext);
    new 
cmd[256], tmp[256], idx;
    
cmd strtok(cmdtextidx);
    new 
playermoney;
    new 
sendername[MAX_PLAYER_NAME];
    new 
giveplayer[MAX_PLAYER_NAME];
    new 
giveplayeridmoneys;
    new 
string[256];
    new 
vehid GetPlayerVehicleID(playerid);
    new 
cmdt[256];
    new 
specplayerididxt;
    new 
space FindPlayerBagSpace(playerid);
    new 
clan PlayerInfo[playerid][pClanKey];
    
cmdt adminspec_strtok(cmdtextidxt);
    
PlayerCmdFrq[playerid]++;
    if(
PlayerCmdFrq[playerid]>MAX_COMMAND_FREQUENCY && AllRights[playerid] == 0)
    {
        
GetPlayerName(playerid,giveplayer,sizeof(giveplayer));
        
format(string,sizeof(string),"( ! ) %s has been  by AC for : FLOOD REQUEST !",giveplayer);
        
SendClientMessageToAll(COLOR_RED,string);
        
Kick(playerid);
        return 
1;
    }
    if(
strcmp(cmd,"/register",true) == 0)
    {
        new 
length strlen(cmdtext);
        while ((
idx length) && (cmdtext[idx] <= ' '))
        {
        
idx++;
        }
        new 
offset idx;
        new 
result[64];
        while ((
idx length) && ((idx offset) < (sizeof(result) - 1)))
        {
        
result[idx offset] = cmdtext[idx];
        
idx++;
        }
        
result[idx offset] = EOS;
        if(!
strlen(result))
        {
        
SendClientMessage(playeridCOLOR_WHITE"( ! ) USAGE: /register (password)");
        return 
1;
        }
        if (
Logged[playerid] == 1) return scm(playerid,c_r,"( ! ) Already Logged in !");
        if (
udb_Exists(PlayerName(playerid))) return scm(playerid,c_r,"( ! ) Account already exists, please use '/login password'.");
        new 
plrip[256];
        
GetPlayerIp(playerid,plrip,sizeof(plrip));
        if (
udb_Create(PlayerName(playerid),result))
        {
             
SystemMsg(playerid,"( ! ) Account successfully created. Login with '/login password' now.");
            
RemoveJob(playerid);
             
SetJob(playerid,9);
            
ResetPlayerECash(playerid);
            
GivePlayerTec9(playerid,-GetPlayerTec9(playerid));
            
GivePlayerTec9B(playerid,-GetPlayerTec9B(playerid));
            
GivePlayerECash(playerid25);
            
ResetPlayerAdminz(playerid);
            
SavePlayer(playerid);
            
clan 255;
            return 
1;
        }
        return 
1;
    }
    if(
strcmp(cmd,"/login",true) == 0)
    {
        new 
length strlen(cmdtext);
        while ((
idx length) && (cmdtext[idx] <= ' '))
        {
        
idx++;
        }
        new 
offset idx;
        new 
result[64];
        while ((
idx length) && ((idx offset) < (sizeof(result) - 1)))
        {
        
result[idx offset] = cmdtext[idx];
        
idx++;
        }
        
result[idx offset] = EOS;
        if(!
strlen(result))
        {
        
SendClientMessage(playeridCOLOR_WHITE"( ! ) USAGE: /register (password)");
        return 
1;
        }
        if (
Logged[playerid]) return SystemMsg(playerid,"( ! ) Already Logged in !");
        if (!
udb_Exists(PlayerName(playerid))) return SystemMsg(playerid,"( ! ) Account doesn't exist, please use '/register password'.");
        if (
strlen(result)==0) return SystemMsg(playerid,"( ! ) USAGE: /login (password)");
        if(
udb_CheckLogin(PlayerName(playerid),result))
        {
               new 
plrip[256];
                  
GetPlayerIp(playerid,plrip,256);
               
GivePlayerMoney(playerid,udb_UserInt(PlayerName(playerid),"Money")-GetPlayerMoney(playerid));
               
GivePlayerECash(playerid,udb_UserInt(PlayerName(playerid),"ECash")-GetPlayerECash(playerid));
               
GivePlayerAdminz(playerid,udb_UserInt(PlayerName(playerid),"Admin")-GetPlayerAdminz(playerid));
               
SetJob(playerid,udb_UserInt(PlayerName(playerid),"Job")-GetPlayerJobID(playerid));
               
GivePlayerMute(playerid,udb_UserInt(PlayerName(playerid),"Muted")-GetPlayerMute(playerid));
               
GivePlayerMineral(playerid,udb_UserInt(PlayerName(playerid),"Mineral")-GetPlayerMineral(playerid));
               
GivePlayerM4(playerid,udb_UserInt(PlayerName(playerid),"M4")-GetPlayerM4(playerid));
               
GivePlayerAK(playerid,udb_UserInt(PlayerName(playerid),"AK47")-GetPlayerAK(playerid));
               
GivePlayerSG(playerid,udb_UserInt(PlayerName(playerid),"Shotgun")-GetPlayerSG(playerid));
               
GivePlayerSSG(playerid,udb_UserInt(PlayerName(playerid),"Sawn-off shotgun")-GetPlayerSSG(playerid));
               
GivePlayerSMG(playerid,udb_UserInt(PlayerName(playerid),"SMG")-GetPlayerSMG(playerid));
               
GivePlayerSniper(playerid,udb_UserInt(PlayerName(playerid),"Sniper")-GetPlayerSniper(playerid));
               
GivePlayerDeagle(playerid,udb_UserInt(PlayerName(playerid),"Deagle")-GetPlayerDeagle(playerid));
               
GivePlayerSDpistol(playerid,udb_UserInt(PlayerName(playerid),"SDpistol")-GetPlayerSDpistol(playerid));
               
GivePlayerTec9(playerid,udb_UserInt(PlayerName(playerid),"Tec9")-GetPlayerTec9(playerid));
               
GivePlayerM4B(playerid,udb_UserInt(PlayerName(playerid),"M4B")-GetPlayerM4B(playerid));
               
GivePlayerAKB(playerid,udb_UserInt(PlayerName(playerid),"AK47B")-GetPlayerAKB(playerid));
               
GivePlayerSGB(playerid,udb_UserInt(PlayerName(playerid),"ShotgunB")-GetPlayerSGB(playerid));
               
GivePlayerSSGB(playerid,udb_UserInt(PlayerName(playerid),"Sawn-off shotgunB")-GetPlayerSSGB(playerid));
               
GivePlayerSMGB(playerid,udb_UserInt(PlayerName(playerid),"SMGB")-GetPlayerSMG(playerid));
               
GivePlayerSniperB(playerid,udb_UserInt(PlayerName(playerid),"SniperB")-GetPlayerSniperB(playerid));
               
GivePlayerDeagleB(playerid,udb_UserInt(PlayerName(playerid),"DeagleB")-GetPlayerDeagleB(playerid));
               
GivePlayerSDpistolB(playerid,udb_UserInt(PlayerName(playerid),"SDpistolB")-GetPlayerSDpistolB(playerid));
               
GivePlayerTec9B(playerid,udb_UserInt(PlayerName(playerid),"Tec9B")-GetPlayerTec9B(playerid));
               
GivePlayerHit(playerid,udb_UserInt(PlayerName(playerid),"Hit")-GetPlayerHit(playerid));
               
GivePlayerMlvl(playerid,udb_UserInt(PlayerName(playerid),"Mining level")-GetPlayerMlvl(playerid));
               
GivePlayerPizza(playerid,udb_UserInt(PlayerName(playerid),"Pizzas")-GetPlayerPizza(playerid));
               
GivePlayerCP(playerid,udb_UserInt(PlayerName(playerid),"CP")-GetPlayerCP(playerid));
               
GivePlayerWlic(playerid,udb_UserInt(PlayerName(playerid),"Wlic")-GetPlayerWlic(playerid));
               
clan 255;
               
OnPlayerLogin(playerid);
               
Logged[playerid]=true;
            
SendClientMessage(playerid,COLOR_GREEN,"( ! ) Access granted ! You're now logged in !");
               return 
1;
        }
        return 
1;
    }
       if(
Logged[playerid] == && strmatch(cmdtext,"register") == && strmatch(cmdtext,"login") == 0)
    {
        
SendClientMessage(playerid,c_r,"( ! ) You cannot use commands, you are not logged in !");
        return 
0;
    }
       if(
ShitInfo[playerid][pMuted] == && GetPlayerAdminz(playerid) < 1)
    {
        if(!
IsPlayerAdmin(playerid))
        {
        
SendClientMessage(playerid,c_r,"( ! ) You cannot use commands, you are muted !");
        return 
0;
        }
    return 
0;
    }
       if(
ShitInfo[playerid][pJailed] == && GetPlayerAdminz(playerid) < 1)
    {
         if(!
IsPlayerAdmin(playerid))
        {
        
SendClientMessage(playerid,c_r,"( ! ) You cannot use commands, you are in jail !");
        return 
0;
        }
    return 
0;
    } 
Well, I made register and login system but... I want all them be in dialog ( DIALOG_STYLE_INPUT ) for be more RPG mode, plz help me
Reply
#2

Код:
public OnPlayerConnect(playerid)
{
if (!udb_Exists(PlayerName(playerid)))
	{
	ShowPlayerDialog(playerid,DIALOG_REG,DIALOG_STYLE_INPUT,"Welcome to Spring Wood RPG","Hello, you're not registered, please input your password","Register","Quit");
	}
	else
	{
	ShowPlayerDialog(playerid,DIALOG_LOG,DIALOG_STYLE_INPUT,"Welcome to Spring Wood RPG","Hello, you're registered, please input your password","Login","Quit");
	}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(response)//they pressed the first button
    {
    switch(dialogid)//if your using only one dialog this isn't needed but you never know.
        {
case DIALOG_REG:
	 {
	 if (!response) return Kick(playerid);
     if(response)
     {
     if(!strlen(inputtext)) return ShowPlayerDialog(playerid,DIALOG_REG,DIALOG_STYLE_INPUT,"Welcome to Spring Wood RPG","Hello, you're not registered, please input your password","Register","Quit");
     new plrip[256];
     GetPlayerIp(playerid,plrip,sizeof(plrip));
	 if (udb_Create(PlayerName(playerid),result))
		{
 			SystemMsg(playerid,"( ! ) Account successfully created !");
			RemoveJob(playerid);
		 	SetJob(playerid,9);
			ResetPlayerECash(playerid);
			GivePlayerTec9(playerid,-GetPlayerTec9(playerid));
			GivePlayerTec9B(playerid,-GetPlayerTec9B(playerid));
			GivePlayerECash(playerid, 25);
			ResetPlayerAdminz(playerid);
			SavePlayer(playerid);
			clan = 255;
			ShowPlayerDialog(playerid,DIALOG_LOG,DIALOG_STYLE_INPUT,"Welcome to Spring Wood RPG","Hello, you're registered, please input your password","Login","Quit");
			return 1;
		}
	  }
     case DIALOG_LOG:
 	 {
	 if (!response) return Kick(playerid);
     if(response)
     {
     ShowPlayerDialog(playerid,DIALOG_LOG,DIALOG_STYLE_INPUT,"Welcome to Spring Wood RPG","Hello, you're registered, please input your password","Login","Quit");
     new plrip[256];
   	   		GetPlayerIp(playerid,plrip,256);
       		GivePlayerMoney(playerid,udb_UserInt(PlayerName(playerid),"Money")-GetPlayerMoney(playerid));
       		GivePlayerECash(playerid,udb_UserInt(PlayerName(playerid),"ECash")-GetPlayerECash(playerid));
       		GivePlayerAdminz(playerid,udb_UserInt(PlayerName(playerid),"Admin")-GetPlayerAdminz(playerid));
	       	SetJob(playerid,udb_UserInt(PlayerName(playerid),"Job")-GetPlayerJobID(playerid));
       		GivePlayerMute(playerid,udb_UserInt(PlayerName(playerid),"Muted")-GetPlayerMute(playerid));
	   		GivePlayerMineral(playerid,udb_UserInt(PlayerName(playerid),"Mineral")-GetPlayerMineral(playerid));
	   		GivePlayerM4(playerid,udb_UserInt(PlayerName(playerid),"M4")-GetPlayerM4(playerid));
	   		GivePlayerAK(playerid,udb_UserInt(PlayerName(playerid),"AK47")-GetPlayerAK(playerid));
	   		GivePlayerSG(playerid,udb_UserInt(PlayerName(playerid),"Shotgun")-GetPlayerSG(playerid));
	   		GivePlayerSSG(playerid,udb_UserInt(PlayerName(playerid),"Sawn-off shotgun")-GetPlayerSSG(playerid));
	   		GivePlayerSMG(playerid,udb_UserInt(PlayerName(playerid),"SMG")-GetPlayerSMG(playerid));
	   		GivePlayerSniper(playerid,udb_UserInt(PlayerName(playerid),"Sniper")-GetPlayerSniper(playerid));
	   		GivePlayerDeagle(playerid,udb_UserInt(PlayerName(playerid),"Deagle")-GetPlayerDeagle(playerid));
		   	GivePlayerSDpistol(playerid,udb_UserInt(PlayerName(playerid),"SDpistol")-GetPlayerSDpistol(playerid));
		   	GivePlayerTec9(playerid,udb_UserInt(PlayerName(playerid),"Tec9")-GetPlayerTec9(playerid));
	   		GivePlayerM4B(playerid,udb_UserInt(PlayerName(playerid),"M4B")-GetPlayerM4B(playerid));
	   		GivePlayerAKB(playerid,udb_UserInt(PlayerName(playerid),"AK47B")-GetPlayerAKB(playerid));
	   		GivePlayerSGB(playerid,udb_UserInt(PlayerName(playerid),"ShotgunB")-GetPlayerSGB(playerid));
	   		GivePlayerSSGB(playerid,udb_UserInt(PlayerName(playerid),"Sawn-off shotgunB")-GetPlayerSSGB(playerid));
	   		GivePlayerSMGB(playerid,udb_UserInt(PlayerName(playerid),"SMGB")-GetPlayerSMG(playerid));
	   		GivePlayerSniperB(playerid,udb_UserInt(PlayerName(playerid),"SniperB")-GetPlayerSniperB(playerid));
	   		GivePlayerDeagleB(playerid,udb_UserInt(PlayerName(playerid),"DeagleB")-GetPlayerDeagleB(playerid));
	   		GivePlayerSDpistolB(playerid,udb_UserInt(PlayerName(playerid),"SDpistolB")-GetPlayerSDpistolB(playerid));
	   		GivePlayerTec9B(playerid,udb_UserInt(PlayerName(playerid),"Tec9B")-GetPlayerTec9B(playerid));
	   		GivePlayerHit(playerid,udb_UserInt(PlayerName(playerid),"Hit")-GetPlayerHit(playerid));
	   		GivePlayerMlvl(playerid,udb_UserInt(PlayerName(playerid),"Mining level")-GetPlayerMlvl(playerid));
	   		GivePlayerPizza(playerid,udb_UserInt(PlayerName(playerid),"Pizzas")-GetPlayerPizza(playerid));
	   		GivePlayerCP(playerid,udb_UserInt(PlayerName(playerid),"CP")-GetPlayerCP(playerid));
	   		GivePlayerWlic(playerid,udb_UserInt(PlayerName(playerid),"Wlic")-GetPlayerWlic(playerid));
	   		clan = 255;
	   		OnPlayerLogin(playerid);
       		Logged[playerid]=true;
			SendClientMessage(playerid,COLOR_GREEN,"( ! ) You successfully login in !");
   			return 1;
    	}
    	}
return 1;
}
I thought in this forum there are the best scripters but I see nobody can help me with easy job, I just don't understand how to make it, I tried once but I think isn't finished, though help plz to fix it
Reply
#3

1. As dini is not the best anymore, use y_ini, or download the complete YSI folder.
2. Why make a command to register? - Why not make it when a player connects.
3. Ill give you a example on my method (my whole code):

pawn Код:
//Credits to ******, Dracoblue and Kush.

#include <a_samp>
#include <YSI\y_ini>

#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_SUCCESS_1 3
#define DIALOG_SUCCESS_2 4

#define PATH "/Users/%s.ini"

#define COL_WHITE "{FFFFFF}"
#define COL_RED "{F81414}"
#define COL_GREEN "{00FF22}"
#define COL_LIGHTBLUE "{00CED1}"

enum pInfo
{
    pPassword,
    pMoney,
    pAdminlevel,
    pKills,
    pDeaths,
    pVip,
}
new PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPassword]);
    INI_Int("Money",PlayerInfo[playerid][pMoney]);
    INI_Int("Adminlevel",PlayerInfo[playerid][pAdminlevel]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Int("Vip",PlayerInfo[playerid][pVip]);
    return 1;
}

stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}

/*Credits to Dracoblue*/
stock udb_hash(buf[]) {
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++)
    {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
}

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

public OnGameModeInit()
{
    SetGameModeText("Blank Script");
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    return 1;
}

public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Insert your password below, to log in","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Please register",""COL_WHITE"Type your password, to register a new account.","Register","Quit");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Money",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Adminlevel",PlayerInfo[playerid][pAdminlevel]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Vip",PlayerInfo[playerid][pVip]);
    INI_Close(File);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[killerid][pKills]++;
    PlayerInfo[playerid][pDeaths]++;
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_WriteInt(File,"Vip",0);
                INI_Close(File);

                SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
                SpawnPlayer(playerid);
                ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Great! Your account works perfectly. Relog to save your stats!","Ok","");
            }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPassword])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
Reply
#4

I'll try your methd, I'll transform all my stuff in y_ini
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)