[Ajuda] MySQL problemas
#1

Olб pessoal, boa tarde, preciso de ajuda, meu sistema, salva a skin do jogador no banco de dados, porem quando o jogador loga no server, ela nгo й setada, vou colocar o cуdigo inteiro que eu estou usando de testes.


Код:
new mysql;

forward saveAll();
public saveAll()
{
	new query[128], name[MAX_PLAYER_NAME];
	for(new a=0; a<MAX_PLAYERS; a++)
	{
		if(IsPlayerConnected(a))
		{
			  GetPlayerName(a, name, MAX_PLAYER_NAME);
              format(query, sizeof(query), "UPDATE `contas` SET `skin` = '%d' WHERE `usuario` = '%s'", GetPlayerSkin(a), name);
              mysql_function_query(mysql, query, false, "", "");
		}
	}
}

main()
{

}

public OnGameModeInit()
{
	mysql_debug(1);
	mysql = mysql_connect("127.0.0.1", "user", "sampserver", "senha");


	SetTimer("saveAll", 5000, true);
	return 1;
}

public OnGameModeExit()
{
	return 1;
}

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

public OnPlayerConnect(playerid)
{
	new nome[MAX_PLAYER_NAME], query[1024];
	GetPlayerName(playerid, nome, MAX_PLAYER_NAME);
	format(query, sizeof(query), "SELECT * FROM `contas` WHERE usuario = '%s'", nome);
	mysql_function_query(mysql, query, true, "q_loginRequest", "d", playerid);
	return 1;                                                                                                                            


}

forward q_loginRequest(playerid);
public q_loginRequest(playerid)
{
 new rows, fields, tmp[64], skn;
 cache_get_data(rows, fields);
 
 if(rows)
 {
    cache_get_field_content(0, "skin", tmp);
    skn = strval(tmp);

    SetSpawnInfo(playerid, 0, skn, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0 );
    ShowPlayerDialog(playerid, DIALOG01, DIALOG_STYLE_PASSWORD, "Seja Bem-vindo ao servidor !", "Digite sua senha", "Login", "Kick");
    //Usuario Existe
 }
 else
 {
  ShowPlayerDialog(playerid, DIALOG02, DIALOG_STYLE_PASSWORD, "Voce nгo tem uma conta", "Primeira vez? Registre-se", "Registrar", "Kick");
 //Usuario Nгo existe !
 }
 return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
	return 1;
}

public OnPlayerSpawn(playerid)
{
	return 1;
}


public OnPlayerDeath(playerid, killerid, reason)
{
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch(dialogid){
		case DIALOG01: {
			new query[1024], nome[MAX_PLAYER_NAME];
			GetPlayerName(playerid, nome, MAX_PLAYER_NAME);
			format(query, sizeof(query), "SELECT * FROM `contas` WHERE (usuario) = '%s' AND (senha) = '%s'", nome, inputtext);
			mysql_function_query(mysql, query, true, "q_verify_Pass", "d", playerid);
			SpawnPlayer(playerid);
		}


			// Usuario nгo existe !
			case DIALOG02: {
				if(strlen(inputtext) < 5) {
					ShowPlayerDialog(playerid, DIALOG02, DIALOG_STYLE_PASSWORD, "Voce nгo tem uma conta", "{ff0000}Insira uma senha maior que 5 digitos !", "Registrar", "Kick");
				}
				else
				{


					new query[1024], nome[MAX_PLAYER_NAME];
					GetPlayerName(playerid, nome, MAX_PLAYER_NAME);
					format(query, sizeof(query), "INSERT INTO `contas` (usuario, senha) VALUES ('%s', '%s')", nome, inputtext);
					mysql_function_query(mysql, query, false, "", "");

					//Spawn
					SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0 );
					SpawnPlayer(playerid);
					return 1;
				}
			}
		}
    return 1;
	}

	forward q_verify_Pass(playerid);
	public q_verify_Pass(playerid)
	{
		new rows, fields, tmp[64], skin;
		cache_get_data(rows, fields);

		if(rows)
		{
			cache_get_field_content(0, "skin", tmp);
            skin = strval(tmp);
			
            SetSpawnInfo(playerid, 0, skin, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0 );
			SpawnPlayer(playerid);
			// Senha correta
		}
		else
		{

			ShowPlayerDialog(playerid, DIALOG01, DIALOG_STYLE_PASSWORD, "Seja Bem-vindo ao servidor !", "{fff700}Senha invalida", "Login", "Kick");
			// Senha errada
		}


	}
Reply


Messages In This Thread
MySQL problemas - by iTouchS - 02.04.2017, 19:50
Re: MySQL problemas - by valdirdd - 02.04.2017, 20:21
Re: MySQL problemas - by iTouchS - 02.04.2017, 20:25
Re: MySQL problemas - by iTouchS - 03.04.2017, 17:37
Re: MySQL problemas - by iTouchS - 04.04.2017, 16:17
Re: MySQL problemas - by HoodScript - 04.04.2017, 16:57

Forum Jump:


Users browsing this thread: 1 Guest(s)