Help me with this save file issue
#1

I gave players the possibility that they can own up to 3 vehicles, but when they buy a car the FileID doesnt save in the playerfile:

pawn Код:
new FileID = GetFreeVehicleSlot();
                        if(Player[playerid][Money] >= Player[playerid][DSCarPrice])
                        {
                            Player[playerid][Money] -= Player[playerid][DSCarPrice];
                            GivePlayerMoney(playerid, -Player[playerid][DSCarPrice]);

                            new string[36];
                            {
                               
                                format(string, sizeof(string), "Vehicles/Vehicle_%d.ini", FileID);
                            }

                            if(!fexist(string))
                            {
                                Player[playerid][Money] -= Player[playerid][DSCarPrice];
                                GivePlayerMoney(playerid, -Player[playerid][DSCarPrice]);

                                SpawnedVehicles++;
                                new VehPlate[255];
                                format(VehPlate, 255, "%s", GetFreeVehiclePlate());

                                dini_Create(string);
                                dini_IntSet(string, "CarID", SpawnedVehicles);
                                dini_IntSet(string, "FactionCar", 0);
                                dini_IntSet(string, "Model", Player[playerid][DSCarID]);
                                dini_FloatSet(string, "XSpawn", 1080.5363);
                                dini_FloatSet(string, "YSpawn", -1738.8501);
                                dini_FloatSet(string, "ZSpawn", 13.3230);
                                dini_FloatSet(string, "AngleSpawn", 267.1113);
                                dini_IntSet(string, "VirtualWorld", 0);
                                dini_IntSet(string, "InteriorID", 0);
                                dini_IntSet(string, "Color1", 1);
                                dini_IntSet(string, "Color2", 1);
                                dini_IntSet(string, "CarGroup", 0);
                                dini_IntSet(string, "RentalCar", -1);
                                dini_Set(string, "vOwner", GetName(playerid));
                                dini_Set(string, "Plate", VehPlate);

                                new NewCar = AddStaticVehicleEx(dini_Int(string, "Model"), dini_Float(string, "XSpawn"), dini_Float(string, "YSpawn"), dini_Float(string, "ZSpawn"), dini_Float(string, "AngleSpawn"), dini_Int(string, "Color1"), dini_Int(string, "Color2"), -1);
                                dini_IntSet(string, "CarID", NewCar);
                                SetVehicleNumberPlate(NewCar, VehPlate);

                                Player[playerid][DSCarPrice] = 0;
                                Player[playerid][DSCarCoins] = 0;
                                Player[playerid][DSCarID] = 0;

                                if(Player[playerid][Car1File] == -1)//starts here the saving part
                                {
                                    Player[playerid][Car1File] = FileID;
                                }
                                else if(Player[playerid][Car2File] == -1 && Player[playerid][Car1File] >= 0)
                                {
                                    Player[playerid][Car2File] = FileID;
                                }
                                else if(Player[playerid][Car3File] == -1 && Player[playerid][Car2File] >= 0 && Player[playerid][Car1File] >= 0)
                                {
                                    Player[playerid][Car3File] = FileID;
                                }
                                else if(Player[playerid][Car3File] >= -1 && Player[playerid][Car2File] >= 0 && Player[playerid][Car1File] >= 0)
                                {
                                    SCM(playerid, RED, "You don't have any free vehicle slot.");
                                }
                            }
                            else
                            {
                                SendClientMessage(playerid, WHITE, "This car File already exist");
                            }
                        }
                        else
                        {
                            SCM(playerid, RED, "You don't have enough money with you!");
                        }
-1 means they dont have a car issued on that slot
Reply
#2

*bump*
Reply
#3

*bump*
Reply
#4

Try it:
PHP код:
new FileID GetFreeVehicleSlot();
                        if(
Player[playerid][Money] >= Player[playerid][DSCarPrice])
                        {
                            
Player[playerid][Money] -= Player[playerid][DSCarPrice];
                            
GivePlayerMoney(playerid, -Player[playerid][DSCarPrice]);
                          }
                            new 
string[36];
                            
format(stringsizeof(string), "Vehicles/Vehicle_%d.ini"FileID);
                            if(!
fexist(string))
                            {
                                
Player[playerid][Money] -= Player[playerid][DSCarPrice];
                                
GivePlayerMoney(playerid, -Player[playerid][DSCarPrice]);
                                
SpawnedVehicles++;
                                new 
VehPlate[255];
                                
format(VehPlate255"%s"GetFreeVehiclePlate());
                                
dini_Create(string);
                                
dini_IntSet(string"CarID"SpawnedVehicles);
                                
dini_IntSet(string"FactionCar"0);
                                
dini_IntSet(string"Model"Player[playerid][DSCarID]);
                                
dini_FloatSet(string"XSpawn"1080.5363);
                                
dini_FloatSet(string"YSpawn", -1738.8501);
                                
dini_FloatSet(string"ZSpawn"13.3230);
                                
dini_FloatSet(string"AngleSpawn"267.1113);
                                
dini_IntSet(string"VirtualWorld"0);
                                
dini_IntSet(string"InteriorID"0);
                                
dini_IntSet(string"Color1"1);
                                
dini_IntSet(string"Color2"1);
                                
dini_IntSet(string"CarGroup"0);
                                
dini_IntSet(string"RentalCar", -1);
                                
dini_Set(string"vOwner"GetName(playerid));
                                
dini_Set(string"Plate"VehPlate);
                                new 
NewCar AddStaticVehicleEx(dini_Int(string"Model"), dini_Float(string"XSpawn"), dini_Float(string"YSpawn"), dini_Float(string"ZSpawn"), dini_Float(string"AngleSpawn"), dini_Int(string"Color1"), dini_Int(string"Color2"), -1);
                                
dini_IntSet(string"CarID"NewCar);
                                
SetVehicleNumberPlate(NewCarVehPlate);
                                
Player[playerid][DSCarPrice] = 0;
                                
Player[playerid][DSCarCoins] = 0;
                                
Player[playerid][DSCarID] = 0;
                                if(
Player[playerid][Car1File] == -1)//starts here the saving part
                                
{
                                    
Player[playerid][Car1File] = FileID;
                                }
                                else if(
Player[playerid][Car2File] == -&& Player[playerid][Car1File] >= 0)
                                {
                                    
Player[playerid][Car2File] = FileID;
                                }
                                else if(
Player[playerid][Car3File] == -&& Player[playerid][Car2File] >= && Player[playerid][Car1File] >= 0)
                                {
                                    
Player[playerid][Car3File] = FileID;
                                }
                                else if(
Player[playerid][Car3File] >= -&& Player[playerid][Car2File] >= && Player[playerid][Car1File] >= 0)
                                {
                                    
SCM(playeridRED"You don't have any free vehicle slot.");
                                }
                            }
                            else
                            {
                                
SendClientMessage(playeridWHITE"This car File already exist");
                            }
                        }
                        else
                        {
                            
SCM(playeridRED"You don't have enough money with you!");
                        } 
Reply
#5

Does it never save, or does it save when you only have 1 or 2 cars?
BTW: The if-statement can be changed into:

pawn Код:
if(Player[playerid][Car1File] == -1)//starts here the saving part
{
    Player[playerid][Car1File] = FileID;
}
else if(Player[playerid][Car2File] == -1)
{
    Player[playerid][Car2File] = FileID;
}
else if(Player[playerid][Car3File] == -1)
{
    Player[playerid][Car3File] = FileID;
}
else
{
    SCM(playerid, RED, "You don't have any free vehicle slot.");
}
If you check carfile1 the first time and it isn't -1, why would you check it 3 more times?
Reply
#6

The other ones are for CarFile 2 and 3, people can own up to 3 cars.
And it never saved... it stays -1
Reply
#7

Just try it..
After that, Try to improve the code:

PHP код:
new FileID GetFreeVehicleSlot();
                        if(
Player[playerid][Money] >= Player[playerid][DSCarPrice])
                        {
                            
Player[playerid][Money] -= Player[playerid][DSCarPrice];
                            
GivePlayerMoney(playerid, -Player[playerid][DSCarPrice]);
                          }
                            new 
string[36];
                            
format(stringsizeof(string), "Vehicles/Vehicle_%d.ini"FileID);
                            if(!
fexist(string))
                            {
                                
Player[playerid][Money] -= Player[playerid][DSCarPrice];
                                
GivePlayerMoney(playerid, -Player[playerid][DSCarPrice]);
                                
SpawnedVehicles++;
                                new 
VehPlate[255];
                                
format(VehPlate255"%s"GetFreeVehiclePlate());
                                
dini_Create(string);
                                
dini_IntSet(string"CarID"SpawnedVehicles);
                                
dini_IntSet(string"FactionCar"0);
                                
dini_IntSet(string"Model"Player[playerid][DSCarID]);
                                
dini_FloatSet(string"XSpawn"1080.5363);
                                
dini_FloatSet(string"YSpawn", -1738.8501);
                                
dini_FloatSet(string"ZSpawn"13.3230);
                                
dini_FloatSet(string"AngleSpawn"267.1113);
                                
dini_IntSet(string"VirtualWorld"0);
                                
dini_IntSet(string"InteriorID"0);
                                
dini_IntSet(string"Color1"1);
                                
dini_IntSet(string"Color2"1);
                                
dini_IntSet(string"CarGroup"0);
                                
dini_IntSet(string"RentalCar", -1);
                                
dini_Set(string"vOwner"GetName(playerid));
                                
dini_Set(string"Plate"VehPlate);
                                new 
NewCar AddStaticVehicleEx(dini_Int(string"Model"), dini_Float(string"XSpawn"), dini_Float(string"YSpawn"), dini_Float(string"ZSpawn"), dini_Float(string"AngleSpawn"), dini_Int(string"Color1"), dini_Int(string"Color2"), -1);
                                
dini_IntSet(string"CarID"NewCar);
                                
SetVehicleNumberPlate(NewCarVehPlate);
                                
Player[playerid][DSCarPrice] = 0;
                                
Player[playerid][DSCarCoins] = 0;
                                
Player[playerid][DSCarID] = 0;
                                if(
Player[playerid][Car1File] == -1)//starts here the saving part
                                
{
                                    
Player[playerid][Car1File] = FileID;
                                }
                                else if(
Player[playerid][Car2File] == -&& Player[playerid][Car1File] >= 0)
                                {
                                    
Player[playerid][Car2File] = FileID;
                                }
                                else if(
Player[playerid][Car3File] == -&& Player[playerid][Car2File] >= && Player[playerid][Car1File] >= 0)
                                {
                                    
Player[playerid][Car3File] = FileID;
                                }
                                else if(
Player[playerid][Car3File] >= -&& Player[playerid][Car2File] >= && Player[playerid][Car1File] >= 0)
                                {
                                    
SCM(playeridRED"You don't have any free vehicle slot.");
                                }
                            }
                            else
                            {
                                
SendClientMessage(playeridWHITE"This car File already exist");
                            }
                        }
                        else
                        {
                            
SCM(playeridRED"You don't have enough money with you!");
                        } 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)