[Ajuda] Erro console do GM e MySQL
#1

Fala aн galera beleza?

Seguinto ontem resolvi que ia aprende a usar MySQL no pawn,

Entгo seguindo o tutorial do BlueX sobre MySQL fiz o seguinte script:

pawn Код:
#include <a_samp>
#include <a_mysql>

#define MAX_SLOTS (25)
#define D_LOGIN 1
#define D_REGISTER 2

new const
    mysql_host[] = "localhost",
    mysql_user[] = "root",
    mysql_database[] = "server",
    mysql_password[] = "1234";

new PlayerName[25];
new Query[500];
new MysqlC;

enum pInfo{
    Level,
    Dinheiro,
    Banco,
    Skin,
    Aviso
};
new PlayerInfo[MAX_SLOTS][pInfo];

forward MySQL_Start();
forward r@MySQL_Start(text[]);

forward MySQL_CheckAccount(playerid);
forward r@MySQL_CheckAccount(playerid);

forward MySQL_CheckPassword(playerid,password[]);
forward r@MySQL_CheckPassword(playerid);

forward MySQL_CreateAccount(playerid,password[]);
forward r@MySQL_CreateAccount(playerid);

forward MySQL_LoadAccount(playerid);
forward r@MySQL_LoadAccount(playerid);

forward MySQL_SaveAccount(playerid);
forward r@MySQL_SaveAccount(playerid);

forward PlayerSpawn(playerid);

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

public OnGameModeInit()
{
    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    MySQL_Start();
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerConnect(playerid)
{
    MySQL_CheckAccount(playerid);
    return 1;
}

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

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid){
        case D_LOGIN:{
            if(!response){
                Kick(playerid);
            }else {
                if(strlen(inputtext) < 4)
                    return ShowPlayerDialog(playerid,D_LOGIN,3,"login","insira a sua password para logar","logar","sair");
                else
                    MySQL_CheckPassword(playerid,inputtext);
            }
        }
        case D_REGISTER:{
            if(!response){
                Kick(playerid);
            }else {
                if( 5 < (strlen(inputtext)) > 25)
                    return ShowPlayerDialog(playerid,D_REGISTER,3,"registro","insira uma password para registrar","registrar","sair");
                else
                    MySQL_CreateAccount(playerid,inputtext);
            }
        }
    }
    return 1;
}

public MySQL_CheckPassword(playerid,password[]){
    GetPlayerName(playerid,PlayerName,25);
    format(Query,sizeof(Query),"SELECT * FROM `users` WHERE name='%s' AND password='%s'",PlayerName,password);
    mysql_function_query(MysqlC,Query,true,"r@MySQL_CheckPassword","ds",playerid);
    return 1;
}
public r@MySQL_CheckPassword(playerid){
    new rows,fields;
    cache_get_data(rows,fields,MysqlC);
    if(rows)
        MySQL_LoadAccount(playerid);
    else
        ShowPlayerDialog(playerid,D_LOGIN,3,"login","insira a sua password para logar","logar","sair");
    return 1;
}

public MySQL_CreateAccount(playerid,password[]){
    GetPlayerName(playerid,PlayerName,25);
    format(Query,sizeof(Query),"INSERT INTO `users` (name,password,level,money,bank,skin) VALUES ('%s','%s','2','4500','0','240');",PlayerName,password);
    mysql_function_query(MysqlC,Query,true,"r@MySQL_CreateAccount","s",playerid);
    return 1;
}
public r@MySQL_CreateAccount(playerid){
    SendClientMessage(playerid,-1,"Registrado com sucesso, aguarde um pouco...");
    MySQL_LoadAccount(playerid);
    return 1;
}

public MySQL_LoadAccount(playerid){
    GetPlayerName(playerid,PlayerName,25);
    format(Query,sizeof(Query),"SELECT * FROM `users` WHERE name='%s'",PlayerName);
    mysql_function_query(MysqlC,Query,true,"r@MySQL_LoadAccount","d",playerid);
    return 1;
}
public r@MySQL_LoadAccount(playerid){
    new rows,fields;
    cache_get_data(rows,fields,MysqlC);
    if(rows){
        cache_get_field_content(0,"level",Query,MysqlC);
        PlayerInfo[playerid][Level] = strval(Query);

        cache_get_field_content(0,"money",Query,MysqlC);
        PlayerInfo[playerid][Dinheiro] = strval(Query);

        cache_get_field_content(0,"bank",Query,MysqlC);
        PlayerInfo[playerid][Banco] = strval(Query);

        cache_get_field_content(0,"skin",Query,MysqlC);
        PlayerInfo[playerid][Skin] = strval(Query);

        PlayerSpawn(playerid);
    }
    else
        SendClientMessage(playerid,-1,"Houve um erro com a sua conta"),Kick(playerid);
    return 1;
}

public PlayerSpawn(playerid){
    SpawnPlayer(playerid);

    GivePlayerMoney(playerid,PlayerInfo[playerid][Dinheiro]);
    SetPlayerScore(playerid,PlayerInfo[playerid][Level]);
    SetPlayerSkin(playerid,PlayerInfo[playerid][Skin]);

    SendClientMessage(playerid,-1,"Seja bem vindo!");
    return 1;
}

public MySQL_SaveAccount(playerid){
    GetPlayerName(playerid,PlayerName,25);
    format(Query,sizeof(Query),"UPDATE `users` SET level='%d',money='%d',bank='%d',skin='%d' WHERE name='%s'",PlayerInfo[playerid][Level],PlayerInfo[playerid][Dinheiro],PlayerInfo[playerid][Banco],PlayerInfo[playerid][Skin],PlayerName);
    mysql_function_query(MysqlC,Query,false,"r@MySQL_SaveAccount","d",playerid);
    return 1;
}

public r@MySQL_SaveAccount(playerid)
    return printf("Conta %d salva com sucesso.",playerid);

public MySQL_Start(){
    MysqlC = mysql_connect(mysql_host,mysql_user,mysql_database,mysql_password);
    if(!MysqlC)
        return print("Nгo foi possivel conectar a database, verifique as definiзхes novamente.");
    else {
        mysql_function_query(MysqlC,
            "CREATE TABLE IF NOT EXISTS `users` (\
                `id` int(11) NOT NULL, AUTO_INCREMENT,\
                `name` varchar(25) NOT NULL, \
                `password` varchar(25) NOT NULL, \
                `level` int(11) NOT NULL, \
                `bank` int(11) NOT NULL, \
                `skin` int(11) NOT NULL, \
                `money` int(11) NOT NULL, \
                PRIMARY KEY(`id`)\
            )"
,false,"r@MySQL_Start","s","users");
    }
    return 1;
}

public r@MySQL_Start(text[])
    return printf("Tabela %s verificada com sucesso.",text);

public MySQL_CheckAccount(playerid){
    GetPlayerName(playerid,PlayerName,25);
    format(Query,sizeof(Query),"SELECT * FROM `users` WHERE name='%s'",PlayerName);
    mysql_function_query(MysqlC,Query,true,"r@MySQL_CheckAccount","d",playerid);
    return 1;
}

public r@MySQL_CheckAccount(playerid){
    new rows,fields;
    cache_get_data(rows,fields,MysqlC);
    if(rows){
        ShowPlayerDialog(playerid,D_LOGIN,3,"login","insira a sua password para logar","logar","sair");
    } else {
        ShowPlayerDialog(playerid,D_REGISTER,3,"registro","insira uma password para registrar","registrar","sair");
    }
    return 1;
}
Usei o phpMyAdmin.

Deu o seguinte erro no console ao abrir o gm:


Pelo que entendi do erro, eu verifiquei se estava em gamemodes mesmo e estava, lн ele novamente mas й a primeira vez que uso MySQL entгo identificar algo fica meio dificil..

Obrigado desde jб!!
Reply
#2

Actualize a sua INC e Plugin do MySQL.
Reply
#3

Baixei ontem do tуpico e e baixei agora novamente.

O Erro continuar, mas Obrigado por postar
Reply
#4

coloco no server.cfg

plugins MySql
Reply
#5

Vish, nubisse extrema agora...

Coloquei sу que agora ele estб falando que nгo tem a LIBMYSQL.dll no meu computador,
Jб intalei o MySQL.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)