Dialog Login/Register
#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


Messages In This Thread
Dialog Login/Register - by jamesb93 - 25.10.2009, 22:55
Re: DILOG Login/Register - by Annihalation - 26.10.2009, 00:47
Re: Dialog Login/Register - by jamesb93 - 26.10.2009, 01:35
Re: Dialog Login/Register - by Ritchie999 - 26.10.2009, 01:35
Re: Dialog Login/Register - by (Jeff) - 26.11.2009, 08:38

Forum Jump:


Users browsing this thread: 2 Guest(s)