03.07.2015, 22:17
I have a problem, so, when someone buys a vehicle, it should insert the ID without enabling Ai in mysql, and set the PlayerInfo variable to the same id, but it doesn't work, all IDs are 0, and idk why...
Buying vehicle:
Loading
Thread
OnPlayerLogin
Buying vehicle:
pawn Code:
if(response)
{
for(new i; i < sizeof(VInfo); i++)
{
new query[1204], str[128];
if(PI[playerid][Auto] != -1) return SCM(playerid, TOMATO, "[RPF] {FFFFFF}Vec imate auto.");
new poz = random(sizeof(PozicijeAutomobila));
VInfo[i][Model] = AutoBiraModel[playerid];
VInfo[i][PozX] = PozicijeAutomobila[poz][0];
VInfo[i][PozY] = PozicijeAutomobila[poz][1];
VInfo[i][PozZ] = PozicijeAutomobila[poz][2];
VInfo[i][PozA] = PozicijeAutomobila[poz][3];
VInfo[i][VW] = 0;
VInfo[i][Int] = 0;
VInfo[i][Boja1] = 0;
VInfo[i][Boja2] = 0;
strmid(VInfo[i][Vlasnik], ImeIgraca(playerid), 0, strlen(ImeIgraca(playerid)), 255);
VInfo[i][Cena] = AutomobilCena[playerid];
VInfo[i][Zakljucan] = 0;
VInfo[i][Droga] = 0;
VInfo[i][Mats] = 0;
VInfo[i][Oruzje1] = -1;
VInfo[i][Oruzje2] = -1;
VInfo[i][Oruzje3] = -1;
VInfo[i][Municija1] = -1;
VInfo[i][Municija2] = -1;
VInfo[i][Municija3] = -1;
AutoBiraModel[playerid] = 0;
AutomobilCena[playerid] = -1;
PI[playerid][Auto] = i;
format(str, sizeof(str), ""COL_YELLOW"[SERVER]: "COL_WHITE"Cestitamo, kupili ste vozilo "COL_YELLOW"%s "COL_WHITE"po ceni od "COL_YELLOW"$%d.", ImenaVozila[VInfo[i][Model] - 400], VInfo[i][Cena]);
SCM(playerid, WHITE, str);
SCM(playerid, WHITE, ""COL_YELLOW"[SERVER]: "COL_WHITE"Dostupne komande vaseg auta mozete videti na "COL_YELLOW"/v.");
VInfo[i][ownedvehicle] = CreateVehicle_H(VInfo[i][Model], VInfo[i][PozX], VInfo[i][PozY], VInfo[i][PozZ], VInfo[i][PozA], VInfo[i][Boja1], VInfo[i][Boja2], 300000);
SetVehicleToRespawn(VInfo[i][ownedvehicle]);
SetPlayerCheckpoint(playerid, VInfo[i][PozX], VInfo[i][PozY], VInfo[i][PozZ], 10.0);
format(query, sizeof(query), "UPDATE `Igraci` SET `Auto` = '%d' WHERE `Ime` = '%s'", PI[playerid][Auto], ImeIgraca(playerid));
mysql_function_query(konekt, query, true, "OnQueryFinish", "ii", THREAD_OSTALO, playerid);
format(query, sizeof(query), "INSERT INTO `Automobili` (`ID`, `Model`, `PozX`, `PozY`, `PozZ`, `PozA`, `VW`, `Int`, `Zakljucan`, `Boja1`, `Boja2`, \
`Vlasnik`, `Cena`, `ImaVlasnika`, `Droga`, `Oruzje1`, `Oruzje2`, `Oruzje3`, `Municija1`, `Municija2`, `Municija3`) VALUES");
format(query, sizeof(query), "%s ('%d', '%d', '%f', '%f', '%f', '%f', '0', '0', '0', '0', '0', '%s', '%d', '1', '0', '-1', '-1', '-1', '-1', '-1', '-1')",
query, i, VInfo[i][Model], VInfo[i][PozX], VInfo[i][PozY], VInfo[i][PozZ], VInfo[i][PozA], VInfo[i][Vlasnik], VInfo[i][Cena]);
mysql_function_query(konekt, query, true, "OnQueryFinish", "i", THREAD_OSTALO);
break;
}
}
pawn Code:
stock CreateVehicle_H(vehicletype, Float:x, Float:y, Float:z, Float:rotation, color1, color2, respawn_delay)
{
new o;
o = CreateVehicle(vehicletype, x, y, z, rotation, color1, color2, respawn_delay);
SetVehicleHealth_H(o, 999.0);
return o;
}
pawn Code:
stock UcitajAutomobile()
{
new szQuery[2048];
new id = cache_get_row_count() + 1;
for(new i; i < id; i++)
{
format(szQuery, sizeof(szQuery), "SELECT * FROM `Automobili` WHERE `ID` = '%d'", i);
mysql_function_query(konekt, szQuery, true, "OnQueryFinish", "ii", THREAD_UCITAJAUTA, i);
print("Loading 1: Passed");
}
return 1;
}
pawn Code:
case THREAD_UCITAJAUTA:
{
if(szRows)
{
new temp[130];
for(new i = 0; i < szRows; i++)
{
cache_get_field_content(0, "Vlasnik", temp);
format(VInfo[extraid][Vlasnik], 50, "%s", temp);
VInfo[extraid][PozX] = cache_get_field_content_int(0, "PozX");
VInfo[extraid][PozY] = cache_get_field_content_int(0, "PozY");
VInfo[extraid][PozZ] = cache_get_field_content_int(0, "PozZ");
VInfo[extraid][PozA] = cache_get_field_content_int(0, "PozA");
VInfo[extraid][Model] = cache_get_field_content_int(0, "Model");
VInfo[extraid][VW] = cache_get_field_content_int(0, "VW");
VInfo[extraid][Int] = cache_get_field_content_int(0, "Int");
VInfo[extraid][Zakljucan] = cache_get_field_content_int(0, "Zakljucan");
VInfo[extraid][Boja1] = cache_get_field_content_int(0, "Boja1");
VInfo[extraid][Boja2] = cache_get_field_content_int(0, "Boja2");
VInfo[extraid][ImaVlasnika] = cache_get_field_content_int(0, "ImaVlasnika");
VInfo[extraid][Droga] = cache_get_field_content_int(0, "Droga");
VInfo[extraid][Mats] = cache_get_field_content_int(0, "Mats");
VInfo[extraid][Oruzje1] = cache_get_field_content_int(0, "Oruzje1");
VInfo[extraid][Oruzje2] = cache_get_field_content_int(0, "Oruzje2");
VInfo[extraid][Oruzje3] = cache_get_field_content_int(0, "Oruzje3");
VInfo[extraid][Municija1] = cache_get_field_content_int(0, "Municija1");
VInfo[extraid][Municija2] = cache_get_field_content_int(0, "Municija2");
VInfo[extraid][Municija3] = cache_get_field_content_int(0, "Municija3");
VInfo[extraid][ownedvehicle] = CreateVehicle_H(VInfo[extraid][Model], 11999.0+random(10000), 11999.0+random(10000), 0.0, 0.0, 0, 0, 1000);
}
}
}
pawn Code:
if(PI[playerid][Auto] != -1)
{
new i = PI[playerid][Auto];
DestroyVehicle(VInfo[i][ownedvehicle]);
VInfo[i][ownedvehicle] = CreateVehicle_H(VInfo[i][Model], VInfo[i][PozX], VInfo[i][PozY], VInfo[i][PozZ], VInfo[i][PozA], VInfo[i][Boja1], VInfo[i][Boja2], 1000);
LinkVehicleToInterior(VInfo[i][ownedvehicle], VInfo[i][Int]);
SetVehicleVirtualWorld(VInfo[i][ownedvehicle], VInfo[i][VW]);
SetVehicleToRespawn(VInfo[i][ownedvehicle]);
IgracevAuto1[playerid] = i;
print("Loading 3: Passed");
}