please, help me
#1

Код:
public OnGameModeExit()
{
  for(new k = 0; k < MAX_PLAYERS; k++)
  {
  new string[128];
	new Float:X, Float:Z, Float:Y;
	new currentveh;
	currentveh = GetPlayerVehicleID(k);
	GetVehiclePos(currentveh, X, Y, Z);
	new File:pos=fopen("vehicles.txt", io_write);
	format(string, 256, "GetVehiclePos(0, %f, %f, %f);", X, Y, Z);
	fwrite(pos, string);
	fclose(pos);
	}
	return 1;
}
I'm trying to do that after server restart cars would stay in the same place like before restart. I've made script but it's doesn't creates and saves positions. What I do wrong and how to solve this problem?
Reply
#2

You keep fopen the file as io_write, that means it'll start the output at the start of the file, meaning it'd erase any data already in that file, so this function would at best just store one cars position, the last saved one.

You should do io_write on first player it's saving and io_append on the rest, by the way you do no checks if the player is actually in a vehicle, if he's out of a vehicle, in vehicle 0, you still proceed by getting position of vehicle 0 and storing that, which makes no sense.

So two tips, validate that he's actually in a vehicle before you save, and only use io_write on the first player/vehicle to save, and io_append on the rest.
Reply
#3

Loading the values from the file is going to be even more fun.
Reply
#4

Quote:
Originally Posted by ledzep
Loading the values from the file is going to be even more fun.
Not hard and ineffective if you know how
But thats offtopic and not important
Reply
#5

I do not understand very well, but I have to say that file creates in scriptfiles folder. When I open it, there is only one line GetVehiclePos and nothing else. I really need this script, because when I restart my server, players says me that they have to buy cars again and spend it's money.
Reply
#6

Quote:
Originally Posted by lakierka
I do not understand very well, but I have to say that file creates in scriptfiles folder. When I open it, there is only one line GetVehiclePos and nothing else. I really need this script, because when I restart my server, players says me that they have to buy cars again and spend it's money.
I just explained it to you, please read my post, it's because io_write will wipe the file then print its result, you should just use io_write once and io_append on the rest!
Reply
#7

Quote:
Originally Posted by krisk
Quote:
Originally Posted by lakierka
I do not understand very well, but I have to say that file creates in scriptfiles folder. When I open it, there is only one line GetVehiclePos and nothing else. I really need this script, because when I restart my server, players says me that they have to buy cars again and spend it's money.
I just explained it to you, please read my post, it's because io_write will wipe the file then print its result, you should just use io_write once and io_append on the rest!
What do you mean on the rest? How write code to me? I need write twice this--> new Fileos=fopen("vehicles.txt", io_write); ? But in rest I have to write io_append?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)