[Need Help] Saving cars to a server.
#1

So, ive made a server, running on a "Group" system, i am using this group system to run my gangs and vehicles which is totally fine, but i currently have 0 cars on my server, and i wanted to add some LSPD cars, setting the car group is fine, but saving the car is the problem, it always disappears,

Heres the /savecar command script:

Код:
command(savecar, playerid, params[])
{
	#pragma unused params
	if(Player[playerid][AdminLevel] >= 5)
	{
		if(UnconfirmedSave[playerid] == 0)
		{
		    SendClientMessage(playerid, WHITE, "Are you sure you want to save this vehicle? Please re-type this command to confirm this action.");
		    UnconfirmedSave[playerid] = 1;
		}
		else
		{
		    UnconfirmedSave[playerid] = 0;
		    if(IsPlayerInAnyVehicle(playerid))
		    {
			    new id, Vehicle[16], vehicleid = GetPlayerVehicleID(playerid);

			    id = findAvailableVehicleID();

				format(Vehicle, sizeof(Vehicle), "V_%d", id);
			    if(!djIsSet(VEHICLES_FILE, Vehicle)) // Fail-safe to prevent overwriting any current values
			    {
			        GetVehiclePos(vehicleid, Vehicles[id][CarPosX], Vehicles[id][CarPosY], Vehicles[id][CarPosZ]);
			        GetVehicleZAngle(vehicleid, Vehicles[id][CarZAngle]);

			        Vehicles[id][CarModel] = GetVehicleModel(vehicleid);
			        Vehicles[id][CarGroup] = 0;

			        Vehicles[id][CarColour1] = -1;
			        Vehicles[id][CarColour2] = -1;

			        djAutocommit(false);
				    format(Vehicle, sizeof(Vehicle), "V_%d/PosX", id);
				    djSetFloat(VEHICLES_FILE, Vehicle, Vehicles[id][CarPosX], true);
				    format(Vehicle, sizeof(Vehicle), "V_%d/PosY", id);
				    djSetFloat(VEHICLES_FILE, Vehicle, Vehicles[id][CarPosY], true);
				    format(Vehicle, sizeof(Vehicle), "V_%d/PosZ", id);
				    djSetFloat(VEHICLES_FILE, Vehicle, Vehicles[id][CarPosZ], true);
				    format(Vehicle, sizeof(Vehicle), "V_%d/ZAngle", id);
				    djSetFloat(VEHICLES_FILE, Vehicle, Vehicles[id][CarZAngle], true);
				    format(Vehicle, sizeof(Vehicle), "V_%d/Model", id);
				    djSetInt(VEHICLES_FILE, Vehicle, Vehicles[id][CarModel], true);
				    format(Vehicle, sizeof(Vehicle), "V_%d/Col1", id);
				    djSetInt(VEHICLES_FILE, Vehicle, Vehicles[id][CarColour1], true);
				    format(Vehicle, sizeof(Vehicle), "V_%d/Col2", id);
				    djSetInt(VEHICLES_FILE, Vehicle, Vehicles[id][CarColour2], true);
				    format(Vehicle, sizeof(Vehicle), "V_%d/Group", id);
			    	djSetInt(VEHICLES_FILE, Vehicle, Vehicles[id][CarGroup], true);
					djCommit(VEHICLES_FILE);
					djAutocommit(true);
					CarCount++;

					printf("[system] Vehicle %d has been saved to %s.", id, VEHICLES_FILE);
					SendClientMessage(playerid, WHITE, "Vehicle saved!");
					
					DestroyVehicle(vehicleid);
					Vehicles[id][GameID] = CreateVehicle(Vehicles[id][CarModel], Vehicles[id][CarPosX], Vehicles[id][CarPosY], Vehicles[id][CarPosZ], Vehicles[id][CarZAngle], Vehicles[id][CarColour1], Vehicles[id][CarColour2], 3600);
                    PutPlayerInVehicle(playerid, Vehicles[id][GameID], 0);
                    
                    SendClientMessage(playerid, WHITE, "Do NOT despawn this vehicle.");
                    
			        for(new i = 0; i < SpawnedVehicles; i++)
					{
					    if(AdminSpawned[i] == GetPlayerVehicleID(playerid))
					    {
					        AdminSpawned[i] = 0;
					    }
					}
				}
			    else {
			        new
			            msgDiagnoseError[104];

					format(msgDiagnoseError, sizeof(msgDiagnoseError), "[savecar] %s failed to insert in Vehicles.json. %s appears to already be set.", Vehicle, Vehicle);
			        logError(msgDiagnoseError);
			        
			        SendClientMessage(playerid, WHITE, "There was an error attempting to save this vehicle, details of the error have been logged to 'scriptfiles/errors.txt'");
			    }
		    }
		}
This is the car file directory:

Код:
#define 				VEHICLES_FILE 						"Vehicles.txt"
But weirdly, the cars do save to Vehciles.txt, it just doesnt load them

PS: I use /setcargroup to set the car group which also saves to .txt

Bit of Vehicles.txt (One Car Only):

Код:
{"V_0":{"Col1":-1,"Col2":-1,"Group":0,"Model":596,"PosY":-1709.802124,"PosZ":5.610952,"ZAngle":359.229736},
Reply
#2

Well, you're saying that it is not loading from the file?
It seems to be saving ok.
Although, your method of saving is a bit weird, using classical fread or Y_INI might improve it.

From what you said, I did not really understand what was the problem, please clarify it.

P.S. Do you even load cars?
Reply
#3

Well, it all saves fine, but when i reload the server, no cars seem to show up, BUT, it saves to the Vehicles.txt file...
Reply
#4

Load cars? i ment the cars dont spawn...
Reply
#5

Quote:
Originally Posted by MeowZ
Посмотреть сообщение
Load cars? i ment the cars dont spawn...
Well obviously, You save to file, and then, they must be loaded, in order for them to be spawned.

There must be a script that converts information from the .txt to server functions for creating vehicles.

If you do not load vehicles, then it will just stay there as an empty / full .txt file without any effect to game.

I suggest you educating yourself on file writing and reading using this guide:
https://sampwiki.blast.hk/wiki/File_Functions
Reply
#6

So is there a way to load it?
Because i thought it would load on startup..
Reply
#7

Quote:
Originally Posted by MeowZ
Посмотреть сообщение
So is there a way to load it?
Because i thought it would load on startup..
No, Only files that read on startup are: server.cfg, gamemode.amx ( your might differ ), filterscripts (.amx) and both .exe's ( different name on linux)

and also, I gave you a link, I suggest you changing it to Y_INI tho....
https://sampforum.blast.hk/showthread.php?tid=273088
(that's a login and register system, but it uses Y_INI, look at those parts.... )
I sent you that post just for you to look how others use Y_INI, and think how you'd use it.

Link to ******'s post for Y_INI:

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

And a bank system using Y_INI:
https://sampforum.blast.hk/showthread.php?tid=372240

Oh yea, vehicles.txt is used in GrandLarc(*I think*) script.
Reply
#8

Quote:
Originally Posted by [WSF]ThA_Devil
Посмотреть сообщение
No, Only files that read on startup are: server.cfg, gamemode.amx ( your might differ ), filterscripts (.amx) and both .exe's ( different name on linux)

and also, I gave you a link, I suggest you changing it to Y_INI tho....
https://sampforum.blast.hk/showthread.php?tid=273088
(that's a login and register system, but it uses Y_INI, look at those parts.... )
I sent you that post just for you to look how others use Y_INI, and think how you'd use it.

Link to ******'s post for Y_INI:

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

And a bank system using Y_INI:
https://sampforum.blast.hk/showthread.php?tid=372240

Oh yea, vehicles.txt is used in GrandLarc(*I think*) script.
Right, I know how it, now what do i do from here?
Reply
#9

Oh and by the way, i use this script: https://sampforum.blast.hk/showthread.php?tid=162379
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)