20.01.2015, 17:49
Hello.
I am trying to make the Gas Pump load/save system but It just don`t want to work.
I have 2 scripts:
First one doesn`t save well and second one doesn`t load well;
defined:
First one:
Second one:
First saves like:
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.
I am trying to make the Gas Pump load/save system but It just don`t want to work.
I have 2 scripts:
First one doesn`t save well and second one doesn`t load well;
defined:
Код:
Float: GasPumpPosX[MAX_BUSINESS_GAS_PUMPS], Float: GasPumpPosY[MAX_BUSINESS_GAS_PUMPS], Float: GasPumpPosZ[MAX_BUSINESS_GAS_PUMPS], Float: GasPumpAngle[MAX_BUSINESS_GAS_PUMPS], Float: GasPumpCapacity[MAX_BUSINESS_GAS_PUMPS], Float: GasPumpGallons[MAX_BUSINESS_GAS_PUMPS], GasPumpObjectID[MAX_BUSINESS_GAS_PUMPS], Text3D: GasPumpInfoTextID[MAX_BUSINESS_GAS_PUMPS], Text3D: GasPumpSaleTextID[MAX_BUSINESS_GAS_PUMPS], Float: GasPumpSaleGallons[MAX_BUSINESS_GAS_PUMPS], Float: GasPumpSalePrice[MAX_BUSINESS_GAS_PUMPS], GasPumpTimer[MAX_BUSINESS_GAS_PUMPS], GasPumpVehicleID[MAX_BUSINESS_GAS_PUMPS],
Код:
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); }
Код:
GasPumpPosX=0.0 GasPumpPosY=0.0 GasPumpPosZ=0.0 GasPumpAngle=0.0 GasPumpCapacity=0.0 GasPumpGallons=0.0 GasPumpModel=0 GasPumpObjectID=0 GasPumpTimer=0 GasPumpVehicleID=0 GasPumpSaleGallons=0.0 GasPumpSalePrice=0.0
DO NOT TELL ME ABOUT MYSQL OR ANY OTHER SAVING SYSTEMS.
IF YOU DON`T KNOW DON`T REPLY. THANK YOU.