Help me with this vehicle saving
#1

Hey guys. I am having a problem with when I delete my vehicle.
I log off and let the statistics update.
I type in my command for spawning vehicles.
I have scripted that non-existing vehicles can't be spawned. (if the model id is 0)
When I pick the first item (listitem is 0) it says non existing vehicles can't be spawned.
When I pick the second item (listitem 1, which my valid vehicle has been saved & loaded into) it spawns the first vehicle on the list because only valid vehicles show on the list.
My question is, how do I save the vehicles in empty slots when they are getting saved?
For example: I deleted the first vehicle (ID 0) and I want the second (ID 1) to be stored as ID 0.
Thank you!

PHP код:
for(new 0MAX_PLAYERVEHICLESi++)
{
    
format(string,sizeof(string),"Vehicle%d_pvModel",i);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvModel]);
    
format(string,sizeof(string),"Vehicle%d_pvX",i);
    
INI_WriteFloat(Filestring,PlayerVehicleInfo[playerid][i][pvX]);
    
format(string,sizeof(string),"Vehicle%d_pvY",i);
    
INI_WriteFloat(Filestring,PlayerVehicleInfo[playerid][i][pvY]);
    
format(string,sizeof(string),"Vehicle%d_pvZ",i);
    
INI_WriteFloat(Filestring,PlayerVehicleInfo[playerid][i][pvZ]);
    
format(string,sizeof(string),"Vehicle%d_pvAngle",i);
    
INI_WriteFloat(Filestring,PlayerVehicleInfo[playerid][i][pvAngle]);
    
format(string,sizeof(string),"Vehicle%d_pvColor1",i);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvColor1]);
    
format(string,sizeof(string),"Vehicle%d_pvColor2",i);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvColor2]);
    
format(string,sizeof(string),"Vehicle%d_pvPaintjob",i);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvPaintjob]);
    
format(string,sizeof(string),"Vehicle%d_pvLocked",i);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvLocked]);
    
format(string,sizeof(string),"Vehicle%d_pvVW",i);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvVW]);
    
format(string,sizeof(string),"Vehicle%d_pvInt",i);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvInt]);
    
format(string,sizeof(string),"Vehicle%d_pvPlates",i);
    
INI_WriteString(Filestring,PlayerVehicleInfo[playerid][i][pvPlates]);
    for(new 
0MAX_MODSm++)
    {
        
format(string,sizeof(string),"Vehicle%d_pvMods%d",i,m);
        
INI_WriteInt(File,string,PlayerVehicleInfo[playerid][i][pvMods][m]);
    }

Reply
#2

I do not understand, do you want to store the vehicles in any id, that is, in which you choose?
Reply
#3

Quote:
Originally Posted by Speedpro
Посмотреть сообщение
I do not understand, do you want to store the vehicles in any id, that is, in which you choose?
Yeah I undestand that this is a bit complicated.
Any ID.
For example: I delete my vehicle that is in slot 0: PlayerVehicleInfo[playerid][0][...]
And when I log off, I want the 1 vehicle: PlayerVehicleInfo[playerid][1][...] to be stored into Vehicle0 in the file.
I hope you undestand, it's complicated haha
Reply
#4

I can not, you can only while you are online, put it to detect slot 0, if it is empty to save the vehicle 1 in slot 0.
Reply
#5

That would take up a lot of space, it's near mission impossible.
Reply
#6

Anyone
Reply
#7

Just add an if statment

PHP код:
for(new 0idx = -1MAX_PLAYERVEHICLESi++)
{
    if(
PlayerVehicleInfo[playerid][i][pvModel] == 0) {
        continue;
    }
    
idx++;
    
format(string,sizeof(string),"Vehicle%d_pvModel",idx);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvModel]);
    
format(string,sizeof(string),"Vehicle%d_pvX"idx);
    
INI_WriteFloat(Filestring,PlayerVehicleInfo[playerid][i][pvX]);
    
format(string,sizeof(string),"Vehicle%d_pvY",idx);
    
INI_WriteFloat(Filestring,PlayerVehicleInfo[playerid][i][pvY]);
    
format(string,sizeof(string),"Vehicle%d_pvZ",idx);
    
INI_WriteFloat(Filestring,PlayerVehicleInfo[playerid][i][pvZ]);
    
format(string,sizeof(string),"Vehicle%d_pvAngle",idx);
    
INI_WriteFloat(Filestring,PlayerVehicleInfo[playerid][i][pvAngle]);
    
format(string,sizeof(string),"Vehicle%d_pvColor1",idx);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvColor1]);
    
format(string,sizeof(string),"Vehicle%d_pvColor2",idx);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvColor2]);
    
format(string,sizeof(string),"Vehicle%d_pvPaintjob",idx);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvPaintjob]);
    
format(string,sizeof(string),"Vehicle%d_pvLocked",idx);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvLocked]);
    
format(string,sizeof(string),"Vehicle%d_pvVW",idx);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvVW]);
    
format(string,sizeof(string),"Vehicle%d_pvInt",idx);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvInt]);
    
format(string,sizeof(string),"Vehicle%d_pvPlates",idx);
    
INI_WriteString(Filestring,PlayerVehicleInfo[playerid][i][pvPlates]);
    for(new 
0MAX_MODSm++)
    {
        
format(string,sizeof(string),"Vehicle%d_pvMods%d",idx,m);
        
INI_WriteInt(File,string,PlayerVehicleInfo[playerid][i][pvMods][m]);
    }

But I recommend to switch to sqlite for something like that, its faster and easier to use
Reply
#8

Using foreach iterator functions this can made possible very easily and faster.
Add your list as foreach iterator.

Iter_Free function returns the smallest value that is not in iterator can be used specifically for your purpose

Below links can be handy if you dont know how to use them
https://sampforum.blast.hk/showthread.php?tid=588526
https://sampforum.blast.hk/showthread.php?tid=570937
https://sampforum.blast.hk/showthread.php?tid=571159
Reply
#9

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Just add an if statment

PHP код:
for(new 0idx = -1MAX_PLAYERVEHICLESi++)
{
    if(
PlayerVehicleInfo[playerid][i][pvModel] == 0) {
        continue;
    }
    
idx++;
    
format(string,sizeof(string),"Vehicle%d_pvModel",idx);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvModel]);
    
format(string,sizeof(string),"Vehicle%d_pvX"idx);
    
INI_WriteFloat(Filestring,PlayerVehicleInfo[playerid][i][pvX]);
    
format(string,sizeof(string),"Vehicle%d_pvY",idx);
    
INI_WriteFloat(Filestring,PlayerVehicleInfo[playerid][i][pvY]);
    
format(string,sizeof(string),"Vehicle%d_pvZ",idx);
    
INI_WriteFloat(Filestring,PlayerVehicleInfo[playerid][i][pvZ]);
    
format(string,sizeof(string),"Vehicle%d_pvAngle",idx);
    
INI_WriteFloat(Filestring,PlayerVehicleInfo[playerid][i][pvAngle]);
    
format(string,sizeof(string),"Vehicle%d_pvColor1",idx);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvColor1]);
    
format(string,sizeof(string),"Vehicle%d_pvColor2",idx);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvColor2]);
    
format(string,sizeof(string),"Vehicle%d_pvPaintjob",idx);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvPaintjob]);
    
format(string,sizeof(string),"Vehicle%d_pvLocked",idx);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvLocked]);
    
format(string,sizeof(string),"Vehicle%d_pvVW",idx);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvVW]);
    
format(string,sizeof(string),"Vehicle%d_pvInt",idx);
    
INI_WriteInt(Filestring,PlayerVehicleInfo[playerid][i][pvInt]);
    
format(string,sizeof(string),"Vehicle%d_pvPlates",idx);
    
INI_WriteString(Filestring,PlayerVehicleInfo[playerid][i][pvPlates]);
    for(new 
0MAX_MODSm++)
    {
        
format(string,sizeof(string),"Vehicle%d_pvMods%d",idx,m);
        
INI_WriteInt(File,string,PlayerVehicleInfo[playerid][i][pvMods][m]);
    }

But I recommend to switch to sqlite for something like that, its faster and easier to use
I can't thank you enough man! I LOVE YOU!

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
Using foreach iterator functions this can made possible very easily and faster.
Add your list as foreach iterator.

Iter_Free function returns the smallest value that is not in iterator can be used specifically for your purpose

Below links can be handy if you dont know how to use them
https://sampforum.blast.hk/showthread.php?tid=588526
https://sampforum.blast.hk/showthread.php?tid=570937
https://sampforum.blast.hk/showthread.php?tid=571159
Alright man, I'll be sure to check it out for future use!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)