[Ajuda] Salvar armas mysql
#1

Estou tentando salvar as armas dos jogadores no banco de dados " jogadores " , na tabela " characters " mas nгo consegui , alguйm ajuda?

Eu tenho uma gm base de salvamento mysql , entгo sу fiz isso:

PHP Code:
SaveArmas(playerid)
{
  new 
Nome[MAX_PLAYER_NAME];
  
GetPlayerName(playeridNomesizeof(Nome));
  new 
weaponid[13], ammo[13], query[999];
  for(new 
i13i++)
    {
        
GetPlayerWeaponData(playeridiweaponid[i], ammo[i]);
        if(
cache_num_rows() >= 0)
        {
        
mysql_format(ConexaoSQLquerysizeof(query), "UPDATE characters SET weapon%d = '%d', ammo%d = '%d' WHERE char_name = '%s'"iweaponid[i], iammo[i], Player[playerid][pCharacterName]);
        
mysql_query(ConexaoSQLquery);
        }
        else
        {
          
mysql_format(ConexaoSQLquerysizeof(query), "INSERT INTO characters (weapon1, ammo1, weapon2, ammo2, weapon3, ammo3, weapon4, ammo4, weapon5, ammo5, weapon6, ammo6, weapon7, ammo7, weapon8, ammo8, weapon9, ammo9, weapon10, ammo10, weapon11, ammo11, weapon12, ammo12) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d') WHERE char_name = '%s'",
          
weaponid[1], ammo[1], weaponid[2], ammo[2], weaponid[3], ammo[3], weaponid[4], ammo[4], weaponid[5], ammo[5], weaponid[6], ammo[6], weaponid[7], ammo[7], weaponid[8], ammo[8], weaponid[9], ammo[9], weaponid[10], ammo[10], weaponid[11], ammo[11], weaponid[12], ammo[12], Nome);
          
mysql_query(ConexaoSQLquery);
        }
    }
  return 
1;

E coloquei em:

PHP Code:
public OnPlayerDisconnect(playeridreason)
{
   
SaveArmas(playerid);



Reply
#2

Olб, responda as minhas perguntas:

Nгo consigo visualizar bem as imagens.

As armas estгo salvando?
Vocк estб tendo problema na hora de carregar as armas ou salva-las na db?
Reply
#3

Use como modelo.

pawn Code:
callback SalvarArmas(playerid) {
    new user_weapons[30], user_weaponsdata[60], Armas[13][2];
    for(new i = 0; i < 13; i++) {
        GetPlayerWeaponData(playerid, i, Armas[i][0], Armas[i][1]);
    }
    format(user_weapons, 30, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", Armas[0][0], Armas[1][0], Armas[2][0], Armas[3][0], Armas[4][0],
        Armas[5][0], Armas[6][0], Armas[7][0], Armas[8][0], Armas[9][0], Armas[10][0], Armas[11][0], Armas[12][0]);
    format(user_weaponsdata, 60, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", Armas[0][1], Armas[1][1], Armas[2][1], Armas[3][1], Armas[4][1],
        Armas[5][1], Armas[6][1], Armas[7][1], Armas[8][1], Armas[9][1], Armas[10][1], Armas[11][1], Armas[12][1]);
    mysql_format(MySQL, gs_Buffer_2, sizeof(gs_Buffer_2), "UPDATE `users` SET `user_weapons`='%e',`user_weaponsdata`='%e' WHERE `user_nome`='%e';",
        user_weapons, user_weaponsdata, UserInfo[playerid][user_nome]);
    mysql_tquery(MySQL, gs_Buffer_2);
    return 1;
}
pawn Code:
callback CarregarArmas(playerid)
{
    if(!IsPlayerConnected(playerid))
        return 1;

    if(CarregouArmas[playerid])
        return SendClientMessage(playerid, COLOR_ERRO, "| ERRO | Voce so pode carregar as armas apenas uma vez.");

    mysql_format(MySQL, gs_Buffer, sizeof gs_Buffer, "SELECT user_weapons, user_weaponsdata FROM `users` WHERE `user_nome` = '%e';", UserInfo[playerid][user_nome]);
    mysql_query(MySQL, gs_Buffer);

    if(cache_num_rows())
    {
        new Armas[13][2];
        ResetPlayerWeapons(playerid);

        cache_get_value(0, "user_weapons", gs_Buffer, sizeof gs_Buffer);
        sscanf(gs_Buffer, "p<,>ddddddddddddd", Armas[0][0], Armas[1][0], Armas[2][0], Armas[3][0], Armas[4][0],
            Armas[5][0], Armas[6][0], Armas[7][0], Armas[8][0], Armas[9][0], Armas[10][0], Armas[11][0], Armas[12][0]);

        cache_get_value(0, "user_weaponsdata", gs_Buffer, sizeof gs_Buffer);
        sscanf(gs_Buffer, "p<,>ddddddddddddd", Armas[0][1], Armas[1][1], Armas[2][1], Armas[3][1], Armas[4][1],
            Armas[5][1], Armas[6][1], Armas[7][1], Armas[8][1], Armas[9][1], Armas[10][1], Armas[11][1], Armas[12][1]);

        for(new i = 0; i < 13; i++)
        GivePlayerWeapon(playerid, Armas[i][0], Armas[i][1]);

        CarregouArmas[playerid] = true;
    }

    return 1;
}
Reply
#4

Quote:
Originally Posted by Gguiz
View Post
Olб, responda as minhas perguntas:

Nгo consigo visualizar bem as imagens.

As armas estгo salvando?
Vocк estб tendo problema na hora de carregar as armas ou salva-las na db?
As armas nгo estгo salvando. As imagens, estou tentando arrumar , estou com uma internet bem lenta no momento kkk
Reply
#5

Quote:
Originally Posted by ipsLuan
View Post
Use como modelo.

pawn Code:
callback SalvarArmas(playerid) {
    new user_weapons[30], user_weaponsdata[60], Armas[13][2];
    for(new i = 0; i < 13; i++) {
        GetPlayerWeaponData(playerid, i, Armas[i][0], Armas[i][1]);
    }
    format(user_weapons, 30, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", Armas[0][0], Armas[1][0], Armas[2][0], Armas[3][0], Armas[4][0],
        Armas[5][0], Armas[6][0], Armas[7][0], Armas[8][0], Armas[9][0], Armas[10][0], Armas[11][0], Armas[12][0]);
    format(user_weaponsdata, 60, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", Armas[0][1], Armas[1][1], Armas[2][1], Armas[3][1], Armas[4][1],
        Armas[5][1], Armas[6][1], Armas[7][1], Armas[8][1], Armas[9][1], Armas[10][1], Armas[11][1], Armas[12][1]);
    mysql_format(MySQL, gs_Buffer_2, sizeof(gs_Buffer_2), "UPDATE `users` SET `user_weapons`='%e',`user_weaponsdata`='%e' WHERE `user_nome`='%e';",
        user_weapons, user_weaponsdata, UserInfo[playerid][user_nome]);
    mysql_tquery(MySQL, gs_Buffer_2);
    return 1;
}
pawn Code:
callback CarregarArmas(playerid)
{
    if(!IsPlayerConnected(playerid))
        return 1;

    if(CarregouArmas[playerid])
        return SendClientMessage(playerid, COLOR_ERRO, "| ERRO | Voce so pode carregar as armas apenas uma vez.");

    mysql_format(MySQL, gs_Buffer, sizeof gs_Buffer, "SELECT user_weapons, user_weaponsdata FROM `users` WHERE `user_nome` = '%e';", UserInfo[playerid][user_nome]);
    mysql_query(MySQL, gs_Buffer);

    if(cache_num_rows())
    {
        new Armas[13][2];
        ResetPlayerWeapons(playerid);

        cache_get_value(0, "user_weapons", gs_Buffer, sizeof gs_Buffer);
        sscanf(gs_Buffer, "p<,>ddddddddddddd", Armas[0][0], Armas[1][0], Armas[2][0], Armas[3][0], Armas[4][0],
            Armas[5][0], Armas[6][0], Armas[7][0], Armas[8][0], Armas[9][0], Armas[10][0], Armas[11][0], Armas[12][0]);

        cache_get_value(0, "user_weaponsdata", gs_Buffer, sizeof gs_Buffer);
        sscanf(gs_Buffer, "p<,>ddddddddddddd", Armas[0][1], Armas[1][1], Armas[2][1], Armas[3][1], Armas[4][1],
            Armas[5][1], Armas[6][1], Armas[7][1], Armas[8][1], Armas[9][1], Armas[10][1], Armas[11][1], Armas[12][1]);

        for(new i = 0; i < 13; i++)
        GivePlayerWeapon(playerid, Armas[i][0], Armas[i][1]);

        CarregouArmas[playerid] = true;
    }

    return 1;
}
Nгo entendi muito bem esse aн
Reply
#6

Alguem ajuda
Reply
#7

Quote:
Originally Posted by JacksonWhite
View Post
Nгo entendi muito bem esse aн
Nгo entendeu oq? Vocк sabe utilizar o MySQL?

Й sу vocк pegar e mudar de acordo com a sua tabela e Salvar/Carregar.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)