Hello.
I am trying to make the Gas Pump load/save system but It just don`t want to work.
Код:
SaveGasPumps()
{
new string3[32];
new gaspumpid[MAX_BUSINESS_GAS_PUMPS];
format(string3, sizeof(string3), "GasPumps.ini", gaspumpid);
new File: hFile = fopen(string3, io_write);
if (hFile)
{
for(new gas = 0; gas < MAX_BUSINESS_GAS_PUMPS; gas++)
{
new var[32];
format(var, 32, "GasPumpPosX=%.1f\n",gas, Businesses[gas][GasPumpPosX]); fwrite(hFile, var);
format(var, 32, "GasPumpPosY=%.1f\n",gas, Businesses[gas][GasPumpPosY]); fwrite(hFile, var);
format(var, 32, "GasPumpPosZ=%.1f\n",gas, Businesses[gas][GasPumpPosZ]); fwrite(hFile, var);
format(var, 32, "GasPumpAngle=%.1f\n",gas, Businesses[gas][GasPumpAngle]); fwrite(hFile, var);
format(var, 32, "GasPumpCapacity=%.1f\n",gas, Businesses[gas][GasPumpCapacity]); fwrite(hFile, var);
format(var, 32, "GasPumpGallons=%.1f\n",gas, Businesses[gas][GasPumpGallons]); fwrite(hFile, var);
format(var, 32, "GasPumpModel=%d\n",gas, 1646); fwrite(hFile, var);
format(var, 32, "GasPumpObjectID=%d\n",gas, Businesses[gas][GasPumpObjectID]); fwrite(hFile, var);
//format(var, 32, "GasPumpInfoTextID=%s\n",gas, Businesses[gas][GasPumpInfoTextID]); fwrite(hFile, var);
//format(var, 32, "GasPumpSaleTextID=%s\n",gas, Businesses[gas][GasPumpSaleTextID]); fwrite(hFile, var);
format(var, 32, "GasPumpTimer=%d\n",gas, Businesses[gas][GasPumpTimer]); fwrite(hFile, var);
format(var, 32, "GasPumpVehicleID=%d\n",gas, Businesses[gas][GasPumpVehicleID]); fwrite(hFile, var);
format(var, 32, "GasPumpSaleGallons=%.1f\n",gas, Businesses[gas][GasPumpSaleGallons]); fwrite(hFile, var);
format(var, 32, "GasPumpSalePrice=%.1f\n",gas, Businesses[gas][GasPumpVehicleID]); fwrite(hFile, var);
fclose(hFile);
}
}
return 1;
}
LoadGasPumps()
{
new string2[128];
new gasid[MAX_BUSINESS_GAS_PUMPS];
format(string2, sizeof(string2), "GasPumps.ini", gasid);
new File: GasPumpsFile = fopen(string2, io_read);
if ( GasPumpsFile )
{
new key[ 256 ] , val[ 256 ];
new Data[ 256 ];
while ( fread( GasPumpsFile , Data , sizeof( Data ) ) )
{
new string[128];
for(new idx = 0; idx < MAX_BUSINESS_GAS_PUMPS; idx++)
{
key = ini_GetKey( Data );
format(string, 128, "GasPumpPosX", idx);
if( strcmp( key , string , true ) == 0 ) { val = ini_GetValue( Data ); Businesses[idx][GasPumpPosX] = floatstr( val ); }
format(string, 128, "GasPumpPosY", idx);
if( strcmp( key , string , true ) == 0 ) { val = ini_GetValue( Data ); Businesses[idx][GasPumpPosY] = floatstr( val ); }
format(string, 128, "GasPumpPosZ", idx);
if( strcmp( key , string , true ) == 0 ) { val = ini_GetValue( Data ); Businesses[idx][GasPumpPosZ] = floatstr( val ); }
format(string, 128, "GasPumpAngle", idx);
if( strcmp( key , string , true ) == 0 ) { val = ini_GetValue( Data ); Businesses[idx][GasPumpAngle] = floatstr( val ); }
format(string, 128, "GasPumpCapacity", idx);
if( strcmp( key , string , true ) == 0 ) { val = ini_GetValue( Data ); Businesses[idx][GasPumpCapacity] = floatstr( val ); }
format(string, 128, "GasPumpGallons", idx);
if( strcmp( key , string , true ) == 0 ) { val = ini_GetValue( Data ); Businesses[idx][GasPumpGallons] = floatstr( val ); }
format(string, 128, "GasPumpObjectID", idx);
if( strcmp( key , string , true ) == 0 ) { val = ini_GetValue( Data ); Businesses[idx][GasPumpObjectID] = strval( val ); }
format(string, 128, "GasPumpTimer", idx);
if( strcmp( key , string , true ) == 0 ) { val = ini_GetValue( Data ); Businesses[idx][GasPumpTimer] = strval( val ); }
format(string, 128, "GasPumpVehicleID", idx);
if( strcmp( key , string , true ) == 0 ) { val = ini_GetValue( Data ); Businesses[idx][GasPumpVehicleID] = strval( val ); }
format(string, 128, "GasPumpSaleGallons", idx);
if( strcmp( key , string , true ) == 0 ) { val = ini_GetValue( Data ); Businesses[idx][GasPumpSaleGallons] = floatstr( val ); }
format(string, 128, "GasPumpSalePrice", idx);
if( strcmp( key , string , true ) == 0 ) { val = ini_GetValue( Data ); Businesses[idx][GasPumpSalePrice] = floatstr( val ); }
new iPump = GetFreeGasPumpID(idx);
new iPlayerID = INVALID_PLAYER_ID;
CreateDynamicGasPump(iPlayerID, idx, iPump);
}
fclose(GasPumpsFile);
}
}
}
Код:
SaveGasPumps() {
new
szFileStr[512],
File: fHandle = fopen("GasPumps.cfg", io_write);
for(new iIndex; iIndex < MAX_BUSINESS_GAS_PUMPS; iIndex++) {
format(szFileStr, sizeof(szFileStr), "%f|%f|%f|%f|%f|%f|%d|%d|%d|%f|%f\r\n",
Businesses[iIndex][GasPumpPosX],
Businesses[iIndex][GasPumpPosY],
Businesses[iIndex][GasPumpPosZ],
Businesses[iIndex][GasPumpAngle],
Businesses[iIndex][GasPumpCapacity],
Businesses[iIndex][GasPumpGallons],
//Businesses[iIndex][GasPumpModel],
Businesses[iIndex][GasPumpObjectID],
Businesses[iIndex][GasPumpTimer],
Businesses[iIndex][GasPumpVehicleID],
Businesses[iIndex][GasPumpSaleGallons],
Businesses[iIndex][GasPumpVehicleID]
);
fwrite(fHandle, szFileStr);
}
return fclose(fHandle);
}
LoadGasPumps()
{
if(!fexist("GasPumps.cfg")) return 1;
print("Gas Pumps....Loaded");
new
szFileStr[512], // Accept all inputs!
File: fHandle = fopen("GasPumps.cfg", io_read);
for(new iArrayIndex; iArrayIndex < sizeof(Businesses); ++iArrayIndex) {
fread(fHandle, szFileStr);
sscanf(szFileStr, "p<|>ffffffdddff",
Businesses[iArrayIndex][GasPumpPosX],
Businesses[iArrayIndex][GasPumpPosY],
Businesses[iArrayIndex][GasPumpPosZ],
Businesses[iArrayIndex][GasPumpAngle],
Businesses[iArrayIndex][GasPumpCapacity],
Businesses[iArrayIndex][GasPumpGallons],
//Businesses[iArrayIndex][GasPumpModel],
Businesses[iArrayIndex][GasPumpObjectID],
Businesses[iArrayIndex][GasPumpTimer],
Businesses[iArrayIndex][GasPumpVehicleID],
Businesses[iArrayIndex][GasPumpSaleGallons],
Businesses[iArrayIndex][GasPumpVehicleID]
);
new iPump = GetFreeGasPumpID(iArrayIndex);
new iPlayerID = INVALID_PLAYER_ID;
CreateDynamicGasPump(iPlayerID, iArrayIndex, iPump);
}
return fclose(fHandle);
}
NOTE: HELP ME ON THE GIVEN SCRIPT.
DO NOT TELL ME ABOUT MYSQL OR ANY OTHER SAVING SYSTEMS.
IF YOU DON`T KNOW DON`T REPLY. THANK YOU.