SA-MP Forums Archive
Saving car mods using yini - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Saving car mods using yini (/showthread.php?tid=607089)



Saving car mods using yini - SalmaN97 - 14.05.2016

Hello everyone i am trying to save my vehicle mods when i mod it in modshop but the problem is in ini file it shows the mod value to 0

here is my code:

PHP код:
public OnVehicleMod(playeridvehicleidcomponentid)
{
    
SaveVehMods(vehicleidcomponentid);
    return 
1;

PHP код:
stock SaveVehMods(vehicleidcomponentid)
{
    for(new 
s=0s<20s++)
    {
        if(
componentid == spoiler[s][0])
        {
            
VehicleInfo[vehicleid][vMods][0] = componentid;
        }
    }
            for(new 
s=0s<4s++) {
                 if(
componentid == bscoop[s][0]) {
                       
VehicleInfo[vehicleid][vMods][1] = componentid;
                }
            }
            for(new 
s=0s<17s++) {
                 if(
componentid == rscoop[s][0]) {
                       
VehicleInfo[vehicleid][vMods][2] = componentid;
                }
            }
            for(new 
s=0s<21s++) {
                 if(
componentid == rskirt[s][0]) {
                       
VehicleInfo[vehicleid][vMods][3] = componentid;
                }
            }
            for(new 
s=0s<21s++) {
                 if(
componentid == lskirt[s][0]) {
                       
VehicleInfo[vehicleid][vMods][16] = componentid;
                }
            }
            for(new 
s=0s<2s++) {
                 if(
componentid == light[s][0]) {
                       
VehicleInfo[vehicleid][vMods][4] = componentid;
                }
            }
            for(new 
s=0s<3s++) {
                 if(
componentid == nitro[s][0]) {
                       
VehicleInfo[vehicleid][vMods][5] = componentid;
                }
            }
            for(new 
s=0s<28s++) {
                 if(
componentid == exhaust[s][0]) {
                       
VehicleInfo[vehicleid][vMods][6] = componentid;
                }
            }
            for(new 
s=0s<17s++) {
                 if(
componentid == wheels[s][0]) {
                       
VehicleInfo[vehicleid][vMods][7] = componentid;
                }
            }
            for(new 
s=0s<1s++) {
                 if(
componentid == bas[s][0]) {
                       
VehicleInfo[vehicleid][vMods][8] = componentid;
                }
            }
            for(new 
s=0s<1s++) {
                 if(
componentid == hydraulics[s][0]) {
                       
VehicleInfo[vehicleid][vMods][9] = componentid;
                }
            }
            for(new 
s=0s<23s++) {
                 if(
componentid == fbumper[s][0]) {
                       
VehicleInfo[vehicleid][vMods][10] = componentid;
                }
            }
            for(new 
s=0s<22s++) {
                 if(
componentid == rbumper[s][0]) {
                       
VehicleInfo[vehicleid][vMods][11] = componentid;
                }
            }
            for(new 
s=0s<2s++) {
                 if(
componentid == bventr[s][0]) {
                       
VehicleInfo[vehicleid][vMods][12] = componentid;
                }
            }
            for(new 
s=0s<2s++) {
                 if(
componentid == bventl[s][0]) {
                       
VehicleInfo[vehicleid][vMods][13] = componentid;
                }
            }
            for(new 
s=0s<2s++) {
                 if(
componentid == fbbars[s][0]) {
                       
VehicleInfo[vehicleid][vMods][15] = componentid;
                }
            }
            for(new 
s=0s<4s++) {
                 if(
componentid == rbbars[s][0]) {
                       
VehicleInfo[vehicleid][vMods][14] = componentid;
                }
            }

when server shuts down under "FilterscriptExit"

PHP код:
stock SaveVehicles(id)
{
    new 
file[64];
    
format(filesizeof(file), "Vehicles/%d.ini"id);
    new 
INI:Handle INI_Open(file);
    if(
Handle != INI_NO_FILE)
    {        
        
INI_WriteInt(Handle"VehMod1"VehicleInfo[id][vMods][0]);
        
INI_WriteInt(Handle"VehMod2"VehicleInfo[id][vMods][1]);
        
INI_WriteInt(Handle"VehMod3"VehicleInfo[id][vMods][2]);
        
INI_WriteInt(Handle"VehMod4"VehicleInfo[id][vMods][3]);
        
INI_WriteInt(Handle"VehMod5"VehicleInfo[id][vMods][4]);
        
INI_WriteInt(Handle"VehMod6"VehicleInfo[id][vMods][5]);
        
INI_WriteInt(Handle"VehMod7"VehicleInfo[id][vMods][6]);
        
INI_WriteInt(Handle"VehMod8"VehicleInfo[id][vMods][7]);
        
INI_WriteInt(Handle"VehMod9"VehicleInfo[id][vMods][8]);
        
INI_WriteInt(Handle"VehMod10"VehicleInfo[id][vMods][9]);
        
INI_WriteInt(Handle"VehMod11"VehicleInfo[id][vMods][10]);
        
INI_WriteInt(Handle"VehMod12"VehicleInfo[id][vMods][11]);
        
INI_WriteInt(Handle"VehMod13"VehicleInfo[id][vMods][12]);
        
INI_WriteInt(Handle"VehMod14"VehicleInfo[id][vMods][13]);
        
INI_WriteInt(Handle"VehMod15"VehicleInfo[id][vMods][14]);
        
INI_WriteInt(Handle"VehMod16"VehicleInfo[id][vMods][15]);
        
INI_WriteInt(Handle"VehMod17"VehicleInfo[id][vMods][16]);
        
INI_Close(Handle);
    }

but this is what i get in ini file after closing the server:
Код:
VehMod1 = 0
VehMod2 = 0
VehMod3 = 0
VehMod4 = 0
VehMod5 = 0
VehMod6 = 0
VehMod7 = 0
VehMod8 = 0
VehMod9 = 0
VehMod10 = 0
VehMod11 = 0
VehMod12 = 0
VehMod13 = 0
VehMod14 = 0
VehMod15 = 0
VehMod16 = 0
VehMod17 = 0



Re: Saving car mods using yini - Skimmer - 14.05.2016

Are you using AddVehicleComponent to add mods?

Because OnVehicleMod is not called by AddVehicleComponent.

Check this https://sampwiki.blast.hk/wiki/OnVehicleMod

EDIT: If so you can create your custom function to add mods.

pawn Код:
AddVehicleComponentEx(vehicleid, componentid)
{
    AddVehicleComponent(vehicleid, componentid);
    SaveVehMods(vehicleid, componentid);
}
Then replace all AddVehicleComponent with AddVehicleComponentEx.


Re: Saving car mods using yini - SalmaN97 - 14.05.2016

Quote:
Originally Posted by Skimmer
Посмотреть сообщение
Are you using AddVehicleComponent to add mods?

Because OnVehicleMod is not called by AddVehicleComponent.

Check this https://sampwiki.blast.hk/wiki/OnVehicleMod

EDIT: If so you can create your custom function to add mods.

pawn Код:
AddVehicleComponentEx(vehicleid, componentid)
{
    AddVehicleComponent(vehicleid, componentid);
    SaveVehMods(vehicleid, componentid);
}
Then replace all AddVehicleComponent with AddVehicleComponentEx.
i am modding my vehicle in modshop so adding component is not a problem but saving is i am trying to save component id unde onvehiclemod but its not saved check my code


Re: Saving car mods using yini - Skimmer - 14.05.2016

I know that adding component is not the problem, but what mean you with modshop.

Are you adding your mods here http://*******/8T6PPu or do you have your own modshop?


Re: Saving car mods using yini - SalmaN97 - 14.05.2016

yes i am adding it from the original modshop you posted a picture


Re: Saving car mods using yini - Skimmer - 14.05.2016

Add this to your function so I can see what components id your variable contains.

pawn Код:
for(new i=0; i<sizeof(VehicleInfo[vehicleid][vMods]); i++) {
        printf("componentid: %i",VehicleInfo[vehicleid][vMods][i])
    }
So it should look like this.

pawn Код:
stock SaveVehMods(vehicleid, componentid)
{
    for(new s=0; s<20; s++) {
        if(componentid == spoiler[s][0]) {
            VehicleInfo[vehicleid][vMods][0] = componentid;
        }
    }
    for(new s=0; s<4; s++) {
         if(componentid == bscoop[s][0]) {
               VehicleInfo[vehicleid][vMods][1] = componentid;
        }
    }
    for(new s=0; s<17; s++) {
         if(componentid == rscoop[s][0]) {
               VehicleInfo[vehicleid][vMods][2] = componentid;
        }
    }
    for(new s=0; s<21; s++) {
         if(componentid == rskirt[s][0]) {
               VehicleInfo[vehicleid][vMods][3] = componentid;
        }
    }
    for(new s=0; s<21; s++) {
         if(componentid == lskirt[s][0]) {
               VehicleInfo[vehicleid][vMods][16] = componentid;
        }
    }
    for(new s=0; s<2; s++) {
         if(componentid == light[s][0]) {
               VehicleInfo[vehicleid][vMods][4] = componentid;
        }
    }
    for(new s=0; s<3; s++) {
         if(componentid == nitro[s][0]) {
               VehicleInfo[vehicleid][vMods][5] = componentid;
        }
    }
    for(new s=0; s<28; s++) {
         if(componentid == exhaust[s][0]) {
               VehicleInfo[vehicleid][vMods][6] = componentid;
        }
    }
    for(new s=0; s<17; s++) {
         if(componentid == wheels[s][0]) {
               VehicleInfo[vehicleid][vMods][7] = componentid;
        }
    }
    for(new s=0; s<1; s++) {
         if(componentid == bas[s][0]) {
               VehicleInfo[vehicleid][vMods][8] = componentid;
        }
    }
    for(new s=0; s<1; s++) {
         if(componentid == hydraulics[s][0]) {
               VehicleInfo[vehicleid][vMods][9] = componentid;
        }
    }
    for(new s=0; s<23; s++) {
         if(componentid == fbumper[s][0]) {
               VehicleInfo[vehicleid][vMods][10] = componentid;
        }
    }
    for(new s=0; s<22; s++) {
         if(componentid == rbumper[s][0]) {
               VehicleInfo[vehicleid][vMods][11] = componentid;
        }
    }
    for(new s=0; s<2; s++) {
         if(componentid == bventr[s][0]) {
               VehicleInfo[vehicleid][vMods][12] = componentid;
        }
    }
    for(new s=0; s<2; s++) {
         if(componentid == bventl[s][0]) {
               VehicleInfo[vehicleid][vMods][13] = componentid;
        }
    }
    for(new s=0; s<2; s++) {
         if(componentid == fbbars[s][0]) {
               VehicleInfo[vehicleid][vMods][15] = componentid;
        }
    }
    for(new s=0; s<4; s++) {
         if(componentid == rbbars[s][0]) {
               VehicleInfo[vehicleid][vMods][14] = componentid;
        }
    }

    for(new i=0; i<sizeof(VehicleInfo[vehicleid][vMods]); i++) {
        printf("componentid: %i",VehicleInfo[vehicleid][vMods][i])
    }
}
Then show me the output with screenshots or copy them from server log and post here.


Re: Saving car mods using yini - SalmaN97 - 14.05.2016

getting this error

Quote:

error 001: expected token: "]", but found "-identifier-"

this is the line:
PHP код:
 for(new i=0i<sizeof(VehicleInfo[vehicleid][vMods]); i++) 



Re: Saving car mods using yini - oMa37 - 14.05.2016

PHP код:
 for(new i=0i<sizeof(VehicleInfo[vehicleid][vMods]) i++) 



Re: Saving car mods using yini - SalmaN97 - 14.05.2016

Quote:
Originally Posted by oMa37
Посмотреть сообщение
PHP код:
 for(new i=0i<sizeof(VehicleInfo[vehicleid][vMods]) i++) 
same error


Re: Saving car mods using yini - Sew_Sumi - 14.05.2016

https://sampforum.blast.hk/showthread.php?tid=606234

Apparently you cannot use this in that manner.

How are you calling it under OnFilterscriptExit, and I'd highly suggest you go back to what you had prior to this "help", and diagnose why it's not writing the file properly.

I'd say you need to make it go through the 16 slots by specifying the max slots of 16. As well as having a MAX_CARS var in the server tracking how many vehicles on your server are indeed spawned.


Even check if the mod is being picked up by OnVehicleMod by putting a SendClientMessage in saying what got modded, so you can track that it is doing it, then doing the same with a "save" function that simply prints to the screen so you can see that it is picking up what you want it to ingame without having to open the file after jumping out.