Dialog Login/Register
#1

Hey,

I'm really stuck with the dialog login and register box. Can someone guide me a little on how to do it.

My /login:

Code:
new tmp[256];
  new playername[MAX_PLAYER_NAME];
  if (strcmp(cmd, "/login", true) ==0 )
	{
	  if(IsPlayerConnected(playerid))
	  {
	    new tmppass[64];
			if(gPlayerLogged[playerid] == 1)
			{
				SendClientMessage(playerid, COLOR_GREY, "	You are already logged in.");
				return 1;
			}
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GREY, "	USAGE: /login [password]");
				return 1;
			}
			strmid(tmppass, tmp, 0, strlen(cmdtext), 255);
			OnPlayerLogin(playerid,tmppass);
		}
		return 1;
My /register:

Code:
	if (strcmp(cmd, "/register", true)==0)
	{
		new string[265];
		tmp = strtok(cmdtext, idx);
		if(!strlen(tmp))
		{
			SendClientMessage(playerid, COLOR_GREY, "USAGE: /register [password]");
			return 1;
		}
		if (gPlayerAccount[playerid] == 1)
		{
			SendClientMessage(playerid, COLOR_GREY, "  That name is already registered");
			return 1;
		}

		strmid(PlayerInfo[playerid][pPassword], tmp, 0, strlen(cmdtext), 255);
		GetPlayerName(playerid, playername, sizeof(playername));
		format(string, sizeof(string), "%s.ini", playername);
		new File: file = fopen(string, io_read);
		if (file)
		{
			SendClientMessage(playerid, COLOR_GREY, "  That name is already registered");
			fclose(file);
			return 1;
		}
		new File:hFile;
		hFile = fopen(string, io_append);
		new var[32];//
    format(var, 32, "%s\n", PlayerInfo[playerid][pPassword]);fwrite(hFile, var);
    format(var, 32, "Rank=%d\n",PlayerInfo[playerid][pRank]);fwrite(hFile, var);
    format(var, 32, "Reborn=%d\n",PlayerInfo[playerid][pReborn]);fwrite(hFile, var);
    format(var, 32, "Exp=%d\n",PlayerInfo[playerid][pExp]);fwrite(hFile, var);
    format(var, 32, "van=%d\n",PlayerInfo[playerid][pVan]);fwrite(hFile, var);
    format(var, 32, "Kills=%d\n",PlayerInfo[playerid][pKills]);fwrite(hFile, var);
    format(var, 32, "TKills=%d\n",PlayerInfo[playerid][pTKills]);fwrite(hFile, var);
    format(var, 32, "GrenadeKills=%d\n",PlayerInfo[playerid][pGrenadekill]);fwrite(hFile, var);
    format(var, 32, "Mp5Kills=%d\n",PlayerInfo[playerid][pMp5kill]);fwrite(hFile, var);
    format(var, 32, "KnuckleKills=%d\n",PlayerInfo[playerid][pKnucklekill]);fwrite(hFile, var);
    format(var, 32, "MenuGoal=%d\n",PlayerInfo[playerid][pMenugoal]);fwrite(hFile, var);
    format(var, 32, "HeliGoal=%d\n",PlayerInfo[playerid][pHeligoal]);fwrite(hFile, var);
    format(var, 32, "Armourgoal=%d\n",PlayerInfo[playerid][pArmourgoal]);fwrite(hFile, var);
    format(var, 32, "Mapgoal=%d\n",PlayerInfo[playerid][pMapgoal]);fwrite(hFile, var);
    format(var, 32, "Deaths=%d\n",PlayerInfo[playerid][pDeaths]);fwrite(hFile, var);
		format(var, 32, "Admin=%d\n",PlayerInfo[playerid][pAdmin]);fwrite(hFile, var);
		format(var, 32, "GM=%d\n",PlayerInfo[playerid][pGM]);fwrite(hFile, var);
		format(var, 32, "Premium=%d\n",PlayerInfo[playerid][pPremium]);fwrite(hFile, var);
    format(var, 32, "Money=%d\n",PlayerInfo[playerid][pCash]);fwrite(hFile, var);
		fclose(hFile);
		SendClientMessage(playerid, COLOR_WHITE, "Succesfully Registered!");
		SendClientMessage(playerid, COLOR_WHITE, "Next time you connect, type /login <password> to log in.");
		OnPlayerLogin(playerid,PlayerInfo[playerid][pPassword]);
		return 1;
	}
Any help appericated

Thanks,
Reply
#2

I think you should redo the whole system, make it to where as soon as they connect, one of two dialogs pops up: either the register one or the login one. Heres some code that I'm using at the moment

Code:
public OnPlayerConnect(playerid)
{
	if(IsPlayerNPC(playerid)) return 1;
	new pName[24], s[128], pstr[64];
	GetPlayerName(playerid,pName,sizeof(pName));
	format(pstr, sizeof(pstr), "players/%s.ini", pName);
	if(!fexist(pstr))
	{
		format(s, sizeof(s),"%s is not registered.\nPlease enter a password of your choice into the input, then press Register.", pName);
		ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Please Register",s,"Register","Cancel");
	}
	if(fexist(pstr))
	{
	  format(s, sizeof(s), "%s is registered.\nPlease login.", pName);
		ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Please Login",s,"Login","Cancel");
	}
	return 1;
}
and heres the rest that is in the Dialog Callback:

Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if(dialogid == 1)
	{
		TogglePlayerControllable(playerid, 0);
		new pName[24], str[128];
		GetPlayerName(playerid,pName,sizeof(pName));
		format(str,sizeof(str),"players/%s.ini",pName);
		if(response == 1)
		{
		  dini_Create(str);
			dini_Set(str,"password",inputtext);
			dini_IntSet(str,"cash",500);
			dini_IntSet(str,"bank",0);
			dini_IntSet(str,"posX",0);
			dini_IntSet(str,"posY",0);
			dini_IntSet(str,"posZ",0);
			SendClientMessage(playerid, 0xFF0000AA, "You are now registered on this server.");
			SendClientMessage(playerid, 0xFF0000AA, "You start out with $500.");
			TogglePlayerControllable(playerid, 1);
		}
		if(response == 0)
		{
		  SendClientMessage(playerid, 0xFFFF0000, "You must log in or register to use this server");
			Kick(playerid);
		}
		return 1;
	}
	if(dialogid ==2)
	{
		TogglePlayerControllable(playerid, 0);
		new pName[24], str[128];
		GetPlayerName(playerid, pName, sizeof(pName));
		format(str, sizeof(str),"players/%s.ini",pName);
		new PW[256];
		PW = dini_Get(str,"password");
		if(response == 1)
		{
		  if(strval(inputtext) == udb_hash(PW)) // successful login
		  {
		    pstat[playerid][skin] = dini_Int(str,"skin");
		    pstat[playerid][cash] = dini_Int(str,"cash");
		    pstat[playerid][bank] = dini_Int(str,"bank");
		    pstat[playerid][posX] = dini_Int(str,"posX");
		    pstat[playerid][posY] = dini_Int(str,"posY");
		    pstat[playerid][posZ] = dini_Int(str,"posZ");
		    GivePlayerMoney(playerid, pstat[playerid][cash]);
		    SetPlayerSkin(playerid, pstat[playerid][skin]);
		    SetPlayerPos(playerid, pstat[playerid][posX], pstat[playerid][posY], pstat[playerid][posZ]);
			}
			else
			{
			  ShowPlayerDialog(playerid, 2, 1,"Wrong Password", "That Password is incorrect. Please try again.","login", "cancel");
			}
			return 1;
		}
	}
	return 1;
}
dont flame me for using dini, Im too lazy to make my own =P

Basically what all that code does is make it to where if the server has your file saved, it will ask you to log in. If not, it will ask you to register.
Reply
#3

Thanks,

Looks Good And All But:
Code:
C:\Program Files\Rockstar Games\samp03asvr_R2_win32\gamemodes\Tets.pwn(41) : error 012: invalid function call, not a valid address
C:\Program Files\Rockstar Games\samp03asvr_R2_win32\gamemodes\Tets.pwn(41) : warning 215: expression has no effect
C:\Program Files\Rockstar Games\samp03asvr_R2_win32\gamemodes\Tets.pwn(41) : error 001: expected token: ";", but found ")"
C:\Program Files\Rockstar Games\samp03asvr_R2_win32\gamemodes\Tets.pwn(41) : error 029: invalid expression, assumed zero
C:\Program Files\Rockstar Games\samp03asvr_R2_win32\gamemodes\Tets.pwn(41) : fatal error 107: too many error messages on one line

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


4 Errors.
Reply
#4

Code:
C:\Users\richard\Desktop\Gta sa Related\samp03_R2svr.exe\gamemodes\WorldWideRP.pwn(1192) : error 017: undefined symbol "pstat"
C:\Users\richard\Desktop\Gta sa Related\samp03_R2svr.exe\gamemodes\WorldWideRP.pwn(1192) : warning 215: expression has no effect
C:\Users\richard\Desktop\Gta sa Related\samp03_R2svr.exe\gamemodes\WorldWideRP.pwn(1192) : error 001: expected token: ";", but found "]"
C:\Users\richard\Desktop\Gta sa Related\samp03_R2svr.exe\gamemodes\WorldWideRP.pwn(1192) : error 029: invalid expression, assumed zero
C:\Users\richard\Desktop\Gta sa Related\samp03_R2svr.exe\gamemodes\WorldWideRP.pwn(1192) : fatal error 107: too many error messages on one line
pawn Code:
1192:           pstat[playerid][skin] = dini_Int(str,"skin");
1193:           pstat[playerid][cash] = dini_Int(str,"cash");
1194:           pstat[playerid][bank] = dini_Int(str,"bank");
1195:           pstat[playerid][posX] = dini_Int(str,"posX");
1196:           pstat[playerid][posY] = dini_Int(str,"posY");
1197:           pstat[playerid][posZ] = dini_Int(str,"posZ");
Reply
#5

hi, how can i make the inputtext a variable like pPass?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)