[Ajuda] Salvar armas mysql
#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


Messages In This Thread
Salvar armas mysql(AINDA PRECISO DE AJUDA) - by JacksonWhite - 30.05.2020, 16:03
Re: Salvar armas mysql - by Gguiz - 30.05.2020, 18:35
Re: Salvar armas mysql - by ipsLuan - 30.05.2020, 18:43
Re: Salvar armas mysql - by JacksonWhite - 30.05.2020, 23:48
Re: Salvar armas mysql - by JacksonWhite - 31.05.2020, 00:34
Re: Salvar armas mysql - by JacksonWhite - 02.06.2020, 13:03
Re: Salvar armas mysql - by ipsLuan - 02.06.2020, 17:18

Forum Jump:


Users browsing this thread: 1 Guest(s)