07.02.2014, 11:46
Eae galera eu to precisando de ajuda, to tentando converter um sistema de vip para mysql, mas ta dando alguns bugs
qual bug?
ele salva direitinho mas se o player jб estiver no banco de dados, ele adiciona outra coluna em vez de renomeia-la
Code que estou convertendo
Minha conversao para mysql
Imagem:
qual bug?
ele salva direitinho mas se o player jб estiver no banco de dados, ele adiciona outra coluna em vez de renomeia-la
Code que estou convertendo
pawn Код:
#include a_samp
#include zcmd
#define MAX_VIPS 10+1
enum vinfo
{
vNick [MAX_PLAYER_NAME],
vTipo
};
new VipInfo[MAX_VIPS][vinfo];
new VagaSobrando;
forward split(const strsrc[], strdest[][], delimiter);
forward VipCheck(playerid);
forward VipVaga();
forward SaveVip();
forward LoadVip();
stock Nome(playerid)
{
new pNome[MAX_PLAYER_NAME];
GetPlayerName(playerid, pNome, MAX_PLAYER_NAME);
return pNome;
}
public split(const strsrc[], strdest[][], delimiter) {
new i, li;
new aNum;
new len;
while (i <= strlen(strsrc)) {
if (strsrc[i] == delimiter || i == strlen(strsrc)) {
len = strmid(strdest[aNum], strsrc, li, i, 128);
strdest[aNum][len] = 0;
li = i + 1;
aNum++;
}
i++;
}
return true;
}
public VipCheck(playerid)
{
new idx = 0;
while (idx < sizeof(VipInfo))
{
if (strcmp(VipInfo[idx][vNick], Nome(playerid), true) == 0) {
return true;
}
idx++;
}
return 0;
}
public VipVaga() {
for (new idx = 0; idx < sizeof(VipInfo); idx++) {
if (strcmp(VipInfo[idx][vNick], "Ninguem", true) == 0) {
VagaSobrando = 1;
return true;
}
}
VagaSobrando = 0;
return 0;
}
public SaveVip() {
new idx;
new File: file2;
while (idx < sizeof(VipInfo)) {
new coordsstring[128];
format(coordsstring, 128, "%s,%d\n", VipInfo[idx][vNick], VipInfo[idx][vTipo]);
if (idx == 0) {
file2 = fopen("Configuracoes/Vips.ini", io_write);
} else {
file2 = fopen("Configuracoes/Vips.ini", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
return true;
}
public LoadVip() {
new arrCoords[2][64];
new strFromFile2[128];
new File: file = fopen("Configuracoes/Vips.ini", io_read);
if (file) {
new idx = 0;
while (idx < sizeof(VipInfo)) {
fread(file, strFromFile2);
split(strFromFile2, arrCoords, ',');
strmid(VipInfo[idx][vNick], arrCoords[0], 0, strlen(arrCoords[0]), 255);
VipInfo[idx][vTipo] = strval(arrCoords[1]);
idx++;
}
}
fclose(file);
return true;
}
CMD:pegarvip(playerid, params[]) {
if (isnull(params)) return SendClientMessage(playerid, -1, "Digite /pegarvip [Tipo]");
new var03 = 0;
for (new x = 0; x < sizeof(VipInfo); x++) {
if (strcmp(Nome(playerid), VipInfo[x][vNick], true) == 0) {
VipInfo[x][vTipo] = strval(params);
SaveVip();
var03 = 1;
break;
}
}
if (var03 == 0) {
for (new x = 0; x < sizeof(VipInfo); x++) {
if (strcmp("Ninguem", VipInfo[x][vNick], true) == 0) {
strmid(VipInfo[x][vNick], Nome(playerid), 0, strlen(Nome(playerid)), 255);
VipInfo[x][vTipo] = strval(params);
SaveVip();
break;
}
}
}
return 1;
}
Minha conversao para mysql
pawn Код:
#include a_samp
#include a_mysql
#include zcmd
#define MAX_VIPS 10
#define HOST "127.0.0.1"
#define USER "root"
#define DATA "MeuRPG"
#define PASS ""
enum E_VIP {
vNick[MAX_PLAYER_NAME],
vTipo
};
enum E_PLAYER {
EN_VIP
};
new PlayerVIP[MAX_VIPS][E_VIP];
new PlayerINFO[MAX_PLAYERS][E_PLAYER];
new ConexaoMySQL;
new VagaVIP;
forward SalvarVIPS();
forward ChecarVIP(playerid);
forward VagaVIPP(playerid);
forward CarregarVIPs();
forward CarregarVIP();
stock NomeP(playerid)
{
new nomee[MAX_PLAYER_NAME];
GetPlayerName(playerid, nomee, MAX_PLAYER_NAME);
return nomee;
}
public SalvarVIPS() {
new id, Query[200];
while(id < sizeof(PlayerVIP)) {
format(Query, 200, "UPDATE vips SET Nick='%s', Tipo='%i' WHERE ID='%i'", PlayerVIP[id][vNick], PlayerVIP[id][vTipo], id);
mysql_function_query(ConexaoMySQL, Query, true, "", "");
}
return 1;
}
public ChecarVIP(playerid) {
new id = 0;
while(id < sizeof(PlayerVIP))
{
if(strcmp(PlayerVIP[id][vNick], NomeP(playerid), true) == 0)
{
return 1;
}
id ++;
}
return false;
}
public VagaVIPP(playerid) {
for( new x = 0; x < MAX_VIPS; x++)
{
if(strcmp(PlayerVIP[x][vNick], "Ninguem", true) == 0)
{
VagaVIP = 1;
}
}
VagaVIP = 0;
return 1;
}
public CarregarVIPs ()
return mysql_function_query(ConexaoMySQL, "SELECT * FROM `vips`", true, "CarregarVIP", "");
public CarregarVIP()
{
new Row, Field, Valores[40], Ind = -1, ID;
cache_get_data(Row, Field, ConexaoMySQL);
while (++Ind < Row)
{
cache_get_field_content(Ind, "ID", Valores);
ID = strval(Valores);
if((ID) >= MAX_VIPS)
continue;
cache_get_field_content(Ind, "Tipo", Valores);
PlayerVIP[ID][vTipo] = strval(Valores);
cache_get_field_content(Ind, "Nick", Valores);
strmid(PlayerVIP[ID][vNick], Valores, 0, strlen(Valores), 21);
}
return 1;
}
public OnGameModeInit ()
{
ConexaoMySQL = mysql_connect (HOST, USER, DATA, PASS);
if(mysql_ping() >= 1)
{
printf("MYSQL Conectado");
}
else
{
printf("MYSQL nгo conectado");
}
return 1;
}
CMD:pegarvip(playerid, params[])
{
if(isnull(params)) return SendClientMessage(playerid, -1, "Digite /pegarvip [Tipo]");
new var = 0 ;
for( new x = 0 ; x < sizeof(PlayerVIP); x++)
{
if(strcmp(NomeP(playerid), PlayerVIP[x][vNick], true) == 0)
{
PlayerVIP[x][vTipo] = 1;
SalvarVIPS();
var = 0;
break;
}
}
if(var == 0)
{
for( new x = 0 ; x < sizeof(PlayerVIP); x++)
{
if(strcmp("Ninguem", PlayerVIP[x][vNick], true) == 0)
{
strmid(PlayerVIP[x][vNick], NomeP(playerid), 0, strlen(NomeP(playerid)), 21);
PlayerVIP[x][vTipo] = 1;
SalvarVIPS();
break;
}
}
}
return 1;
}