Y_INI Register system
#1

Hello. I tried to add ******' register/login system to my gamemode. It somewhat worked fine, apart from the accounts saving after a restart. Also, I have multiple scripts in my OnDialogReponse callback, which sort of mix together.

here is the callback:
Код:
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, "{FFFFFF}Registering...","{FF0000}You have entered an invalid password.\n""{FFFFFF}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_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,"{00FF15}Success!","{00FF15}Great! Your account works perfectly!","Ok", " ");
			}
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == Player[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, Player[playerid][pCash]);
					ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,"{FFFFFF}Success!","{FFFFFF}You have successfully logged in!","Ok","");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"{FFFFFF}Login","{FF0000}You have entered an incorrect password.\n""{FFFFFF}Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
	}  
	if(dialogid == DIALOG_VIP_WEAPONS)
	{
		if(response)
		{
			if(listitem == 0)
			{
				if(GetPlayerMoney(playerid) < 35000)
				{
					SCM(pid, -1, "You don't have enough cash for that!");
					return 1;
				}
				else
				{
				GivePlayerWeapon(playerid, 31, 250);
				GivePlayerMoney(playerid, -35000);
				SCM(pid, -1, "{FFD83D} You have bought an {FF0000}M4 {FFD83D}for {09FF00}$35.000!");
				}
			}
			if(listitem == 1)
			{
				if(GetPlayerMoney(playerid) < 20000)
				{
					SCM(pid, -1, "You don't have enough cash for that!");
					return 1;
				}
				else
				{
				GivePlayerWeapon(playerid, 24, 100);
				GivePlayerMoney(playerid, -20000);
				SCM(pid, -1, "{FFD83D} You have bought a {FF0000}Deagle {FFD83D}for {09FF00}$20.000!");
				}
			}
			if(listitem == 2)
			{
				if(GetPlayerMoney(playerid) < 15000)
				{
					SCM(pid, -1, "You don't have enough cash for that!");
					return 1;
				}
				else
				{
				GivePlayerWeapon(playerid, 29, 200);
				GivePlayerMoney(playerid, -15000);
				SCM(pid, -1, "{FFD83D} You have bought an {FF0000}MP5 {FFD83D}for {09FF00}$15.000!");
				}
			}
			if(listitem == 3)
			{
				if(GetPlayerMoney(playerid) < 40000)
				{
					SCM(pid, -1, "You don't have enough cash for that!");
					return 1;
				}
				else
				{
				GivePlayerWeapon(playerid, 30, 250);
				GivePlayerMoney(playerid, -40000);
				SCM(pid, -1, "{FFD83D} You have bought an {FF0000}AK47 {FFD83D}for {09FF00}$40.000!");
				}
			}
		}
	}
	switch(dialogid) 
    { 
        case DIALOG_ID_VIP_COLORS: 
        { 
            if(response) 
            { 
                new color; 
                switch(listitem) 
                { 
                    // Listitem ID starts from 0. There are 9 items. 
                    case 0: color = 0xF30DFF00; 
                    case 1: color = 0xB10AFF00; 
                    case 2: color = 0x7B7DED00; 
                    case 3: color = 0x00FFAA00; 
                    case 4: color = 0xFF7A2100; 
                    case 5: color = 0x75757500; 
                    case 6: color = 0xFF858500; 
                    case 7: color = 0xF6FF0000; 
                    case 8: color = 0xA34D4D00; 
                } 
                SendClientMessage(playerid, color, " Your colour has been changed."); 
                SetPlayerColor(playerid, color); 
            } 
        } 
    } 
    return 1; 
}
FROM DIALOG_VIP_WEAPONS it's a separate script.
It also spawns me strangely.
Album

EDIT:
I also get these warnings in my server_log:
Код:
[21:21:35] password = ""  (string)
[21:21:35] [0.3.7]JXF's server (V1.0), has been loaded successfully.
[21:21:35] Number of vehicle models: 0
[21:21:39] *** YSI Warning: INI_Open could not find or create file /Users/JXF.ini
[21:34:44] *** YSI Warning: INI_Open could not find or create file /Users/JXF.ini
[21:34:44] [part] JXF has left the server (0:1)
Reply
#2

Quote:
Originally Posted by JXF
Посмотреть сообщение
Hello. I tried to add ******' register/login system to my gamemode. It somewhat worked fine, apart from the accounts saving after a restart. Also, I have multiple scripts in my OnDialogReponse callback, which sort of mix together.

here is the callback:
Код:
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, "{FFFFFF}Registering...","{FF0000}You have entered an invalid password.\n""{FFFFFF}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_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,"{00FF15}Success!","{00FF15}Great! Your account works perfectly!","Ok", " ");
			}
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == Player[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, Player[playerid][pCash]);
					ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,"{FFFFFF}Success!","{FFFFFF}You have successfully logged in!","Ok","");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"{FFFFFF}Login","{FF0000}You have entered an incorrect password.\n""{FFFFFF}Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
	}  
	if(dialogid == DIALOG_VIP_WEAPONS)
	{
		if(response)
		{
			if(listitem == 0)
			{
				if(GetPlayerMoney(playerid) < 35000)
				{
					SCM(pid, -1, "You don't have enough cash for that!");
					return 1;
				}
				else
				{
				GivePlayerWeapon(playerid, 31, 250);
				GivePlayerMoney(playerid, -35000);
				SCM(pid, -1, "{FFD83D} You have bought an {FF0000}M4 {FFD83D}for {09FF00}$35.000!");
				}
			}
			if(listitem == 1)
			{
				if(GetPlayerMoney(playerid) < 20000)
				{
					SCM(pid, -1, "You don't have enough cash for that!");
					return 1;
				}
				else
				{
				GivePlayerWeapon(playerid, 24, 100);
				GivePlayerMoney(playerid, -20000);
				SCM(pid, -1, "{FFD83D} You have bought a {FF0000}Deagle {FFD83D}for {09FF00}$20.000!");
				}
			}
			if(listitem == 2)
			{
				if(GetPlayerMoney(playerid) < 15000)
				{
					SCM(pid, -1, "You don't have enough cash for that!");
					return 1;
				}
				else
				{
				GivePlayerWeapon(playerid, 29, 200);
				GivePlayerMoney(playerid, -15000);
				SCM(pid, -1, "{FFD83D} You have bought an {FF0000}MP5 {FFD83D}for {09FF00}$15.000!");
				}
			}
			if(listitem == 3)
			{
				if(GetPlayerMoney(playerid) < 40000)
				{
					SCM(pid, -1, "You don't have enough cash for that!");
					return 1;
				}
				else
				{
				GivePlayerWeapon(playerid, 30, 250);
				GivePlayerMoney(playerid, -40000);
				SCM(pid, -1, "{FFD83D} You have bought an {FF0000}AK47 {FFD83D}for {09FF00}$40.000!");
				}
			}
		}
	}
	switch(dialogid) 
    { 
        case DIALOG_ID_VIP_COLORS: 
        { 
            if(response) 
            { 
                new color; 
                switch(listitem) 
                { 
                    // Listitem ID starts from 0. There are 9 items. 
                    case 0: color = 0xF30DFF00; 
                    case 1: color = 0xB10AFF00; 
                    case 2: color = 0x7B7DED00; 
                    case 3: color = 0x00FFAA00; 
                    case 4: color = 0xFF7A2100; 
                    case 5: color = 0x75757500; 
                    case 6: color = 0xFF858500; 
                    case 7: color = 0xF6FF0000; 
                    case 8: color = 0xA34D4D00; 
                } 
                SendClientMessage(playerid, color, " Your colour has been changed."); 
                SetPlayerColor(playerid, color); 
            } 
        } 
    } 
    return 1; 
}
FROM DIALOG_VIP_WEAPONS it's a separate script.
It also spawns me strangely.
Album

EDIT:
I also get these warnings in my server_log:
Код:
[21:21:35] password = ""  (string)
[21:21:35] [0.3.7]JXF's server (V1.0), has been loaded successfully.
[21:21:35] Number of vehicle models: 0
[21:21:39] *** YSI Warning: INI_Open could not find or create file /Users/JXF.ini
[21:34:44] *** YSI Warning: INI_Open could not find or create file /Users/JXF.ini
[21:34:44] [part] JXF has left the server (0:1)
Does the folder /Users/ exist? And if you're on a host, then are the permissions set to 777?
Reply
#3

I'm not on a host, and no I don't have the Users folder. Is it supposed to be in the scriptfiles folder?
Reply
#4

Yes, you have to make a file named Users in your scriptfiles
Reply
#5

Great. That works.
My other problem is that some separate scripts in the OnDialogResponse mix up.
For example: I have a VIP Weapon dialog menu, and when I choose a weapon it shows a dialog with "You have entered an incorrect password".
Код:
case DIALOG_LOGIN:
        {
            if ( !response )
			{
				Kick(playerid);
				SCM(pid, COLOR_BISQUE, "You have been kicked because you didn't register!");
			}
            if( response )
            {
                if(udb_hash(inputtext) == Player[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, Player[playerid][pCash]);
					ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,"{FFFFFF}Success!","{FFFFFF}You have successfully logged in!","Ok", "Cancel");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"{1AFF00}Login","{FF0000}You have entered an invalid password.\n""{38E2EB}Type your password below to {B7E82E}login.","Login","Quit");
					return 1;
                }
            }
			return 0;
        }
	if(dialogid == DIALOG_VIP_WEAPONS)
	{
		if(response)
		{
			if(listitem == 0)
			{
				if(GetPlayerMoney(playerid) < 35000)
				{
					SCM(pid, -1, "You don't have enough cash for that!");
					return 1;
				}
				else
				{
				GivePlayerWeapon(playerid, 31, 250);
				GivePlayerMoney(playerid, -35000);
				SCM(pid, -1, "{FFD83D} You have bought an {FF0000}M4 {FFD83D}for {09FF00}$35.000!");
				}
			}
			if(listitem == 1)
			{
				if(GetPlayerMoney(playerid) < 20000)
				{
					SCM(pid, -1, "You don't have enough cash for that!");
					return 1;
				}
				else
				{
				GivePlayerWeapon(playerid, 24, 100);
				GivePlayerMoney(playerid, -20000);
				SCM(pid, -1, "{FFD83D} You have bought a {FF0000}Deagle {FFD83D}for {09FF00}$20.000!");
				}
			}
			if(listitem == 2)
			{
				if(GetPlayerMoney(playerid) < 15000)
				{
					SCM(pid, -1, "You don't have enough cash for that!");
					return 1;
				}
				else
				{
				GivePlayerWeapon(playerid, 29, 200);
				GivePlayerMoney(playerid, -15000);
				SCM(pid, -1, "{FFD83D} You have bought an {FF0000}MP5 {FFD83D}for {09FF00}$15.000!");
				}
			}
			if(listitem == 3)
			{
				if(GetPlayerMoney(playerid) < 40000)
				{
					SCM(pid, -1, "You don't have enough cash for that!");
					return 1;
				}
				else
				{
				GivePlayerWeapon(playerid, 30, 250);
				GivePlayerMoney(playerid, -40000);
				SCM(pid, -1, "{FFD83D} You have bought an {FF0000}AK47 {FFD83D}for {09FF00}$40.000!");
				}
			}
		}
	}
Reply
#6

Make sure all of your dialog IDs are unique while defining them. If two of them has the same ID then it's possible the dialog can be mixed up. Also, put all the dialog IDs inside one switch. It looks like you are using switch for some dialogs and if statement for others.
Reply
#7

Great. Thank you.
One more thing though, when I login or register, it spawns me like this:
Click
Reply
#8

Well, are you writing a gamemode from scratch? Because that's by the default and you will have to code your own spawn points in order to get it the way you want.
Reply
#9

I've got this line in my login script as well
Код:
SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
					SpawnPlayer(playerid);
Reply
#10

Post your OnPlayerRequestClass callback
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)