29.11.2013, 16:15
/save is by default a client command for SA-MP so it wouldn't work. You also don't need to use SELECT clause when it's about to save (update) something to the database.
It's better to use 4 global variables that are assigned how many rows for each exist and then just run a loop and you'll be fine. For example:
When you load those (on server startup), in the public function you'll get the rows so:
So you now know how many rows loaded. When you create a new one (if it's dynamic and you can create them from in-game), then just add + 1 to the variable stores the rows of it.
Remove the forward stuff from those 4.
Something like that:
It's better to use 4 global variables that are assigned how many rows for each exist and then just run a loop and you'll be fine. For example:
pawn Код:
// global:
new
empresas_rows,
sempresas_rows,
veiculos_rows,
casas_rows
;
pawn Код:
// You load Bizz:
cache_get_data(rows, fields);
empresas_rows = rows;
pawn Код:
// Let's say you load Bizz:
cache_get_data(rows, fields);
empresas_rows = rows;
pawn Код:
// You load SBizz:
cache_get_data(rows, fields);
sempresas_rows = rows;
pawn Код:
// You load Cars:
cache_get_data(rows, fields);
veiculos_rows = rows;
pawn Код:
// You load Houses:
cache_get_data(rows, fields);
casas_rows = rows;
Remove the forward stuff from those 4.
Something like that:
pawn Код:
// OnPlayerCommandText:
if(strcmp(cmd, "/saveall", true) == 0)
{
if(PlayerInfo[playerid][pAdmin] <= 1342) SendClientMessage(playerid, COLOR_GRAD1, "insufficient Permission!");
{
if(admtrampando[playerid] < 1 && PlayerInfo[playerid][pAdmin] != 1343) return SendClientMessage(playerid, COLOR_GRAD1, "You dont workink! (/work)");
SaveBizz();
SaveSBizz();
SaveCars();
SaveHouses();
SendClientMessage(playerid, -1,"Starting save of, Bizz, Sbizz, Cars and Houses");
}
return 1;
}
pawn Код:
stock SaveBizz()
{
new Str[315];
for(new TotalBusinesses; TotalBusinesses != empresas_rows; TotalBusinesses++)
{
format(Str,156,"UPDATE `empresas` SET `Vendida`='%i',`Dono`='%s',`Mensagem`='%s',`Extorcao`='%s',",BizzInfo[TotalBusinesses][bOwned],BizzInfo[TotalBusinesses][bOwner],BizzInfo[TotalBusinesses][bMessage],BizzInfo[TotalBusinesses][bExtortion]);
format(Str,315,"%s`LevelNecessario`='%i',`PrecoCompra`='%i',`EntradaCusto`='%i',`Till`='%i',`Trancada`='%i' WHERE `ID`='%i'",Str,BizzInfo[TotalBusinesses][bLevelNeeded],BizzInfo[TotalBusinesses][bBuyPrice],BizzInfo[TotalBusinesses][bEntranceCost],BizzInfo[TotalBusinesses][bTill],BizzInfo[TotalBusinesses][bLocked],TotalBusinesses);
mysql_function_query(Connect, Str, false, "","");
//print("");
//print(Str);
}
printf("[BVS]: %d Bizz Save", empresas_rows);
}
stock SaveSBizz()
{
new Str[317];
for(new TotalSBusinesses; TotalSBusinesses != sempresas_rows; TotalSBusinesses++)
{
format(Str,133,"UPDATE `sempresas` SET `Dono`='%s',`Mensagen`='%s',`Extorcao`='%s',",SBizzInfo[TotalSBusinesses][sbOwner], SBizzInfo[TotalSBusinesses][sbMessage], SBizzInfo[TotalSBusinesses][sbExtortion]);
format(Str,317,"%s`LevelNecessario`='%i',`PrecoCompra`='%i',`EntradaCusto`='%i',`Till`='%i',`Trancada`='%i',`Comprada`='%i' WHERE `ID`='%i'",Str,SBizzInfo[TotalSBusinesses][sbLevelNeeded],SBizzInfo[TotalSBusinesses][sbBuyPrice]
,SBizzInfo[TotalSBusinesses][sbEntranceCost],SBizzInfo[TotalSBusinesses][sbTill],SBizzInfo[TotalSBusinesses][sbLocked],SBizzInfo[TotalSBusinesses][sbOwned],TotalSBusinesses);
mysql_function_query(Connect, Str, false, "","");
//print("");
//print(Str);
}
printf("[BVS]: %d SBizz save", sempresas_rows);
}
stock SaveCars()
{
new Str[435];
for(new TotalCars; TotalCars != veiculos_rows; TotalCars++)
{
format(Str,185,"UPDATE `veiculos` SET `Modelo`='%i',`Cor1`='%i',`Cor2`='%i',`Dono`='%s',`Descricao`='%s',`Valor`='%i',",CarInfo[TotalCars][cModel],CarInfo[TotalCars][cColorOne],
CarInfo[TotalCars][cColorTwo],CarInfo[TotalCars][cOwner],CarInfo[TotalCars][cDescription],CarInfo[TotalCars][cValue]);
format(Str,310,"%s`Vendido`='%i',`Trancado`='%i',`LX`='%f',`LY`='%f',`LZ`='%f',`LA`='%f',",Str,CarInfo[TotalCars][cOwned],CarInfo[TotalCars][cLock],
CarInfo[TotalCars][lx],CarInfo[TotalCars][ly],CarInfo[TotalCars][lz],CarInfo[TotalCars][langle]);
format(Str,435,"%s`Grana`='%i',`IPVATime`='%i',`IPVA`='%i',`Plate`='%s' WHERE `cID`='%i'",Str,CarInfo[TotalCars][cGrana],CarInfo[TotalCars][cIPVATime],CarInfo[TotalCars][cIPVA],
CarInfo[TotalCars][cPlate],CarInfo[TotalCars][cID]);
mysql_function_query(Connect, Str, false, "","");
//print("");
//print(Str);
}
printf("[BVS]: %d Carros Salvos", veiculos_rows);
}
stock SaveHouses()
{
new Str[603];
for(new TotalCasas; TotalCasas != casas_rows; TotalCasas++)
{
format(Str,163,"UPDATE `casas` SET `HealthX`='%i',`HealthY`='%i',`HealthZ`='%i',`ArmorrX`='%i',`ArmorrY`='%i',`ArmorrZ`='%i',",HouseInfo[TotalCasas][hHealthx],
HouseInfo[TotalCasas][hHealthy],HouseInfo[TotalCasas][hHealthz],HouseInfo[TotalCasas][hArmorrx],HouseInfo[TotalCasas][hArmorry],HouseInfo[TotalCasas][hArmorrz]);
format(Str,380,"%s`Dono`='%s',`Descricao`='%s',`Valor`='%i',`Saude`='%i',`Colete`='%i',`Interior`='%i',`Trancado`='%i',`Vendido`='%i',",Str,HouseInfo[TotalCasas][hOwner],
HouseInfo[TotalCasas][hDiscription],HouseInfo[TotalCasas][hValue],HouseInfo[TotalCasas][hHel],HouseInfo[TotalCasas][hArm],HouseInfo[TotalCasas][hInt],HouseInfo[TotalCasas][hLock],HouseInfo[TotalCasas][hOwned]);
format(Str,557,"%s`Rooms`='%i',`Rent`='%i',`Rentabil`='%i',`Takings`='%i',`Vec`='%i',`Vcol1`='%i',`Vcol2`='%i',`Data`='%i',",Str,HouseInfo[TotalCasas][hRooms],HouseInfo[TotalCasas][hRent],
HouseInfo[TotalCasas][hRentabil],HouseInfo[TotalCasas][hTakings],HouseInfo[TotalCasas][hVec],HouseInfo[TotalCasas][hVcol1],HouseInfo[TotalCasas][hVcol2],HouseInfo[TotalCasas][hDate]);
format(Str,603,"%s`Level`='%i' WHERE `ID`='%i'",Str,HouseInfo[TotalCasas][hLevel],TotalCasas);
mysql_function_query(Connect, Str, false, "","");
//print("");
//print(Str);
}
printf("[BVS]: %d Houses Save",casas_rows);
}