Thread: [Ajuda] Salvar armas mysql
View Single Post
Old 30/05/2020, 06:43 PM   #3
ipsLuan
High-roller
 
ipsLuan's Avatar
 
Join Date: Feb 2013
Location: Ilhéus, BA
Posts: 4,556
Reputation: 332
Default Re: Salvar armas mysql

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;
}
__________________

Precisando de algum sistema? Chame!

ipsLuan is offline   Reply With Quote