Problem with the car system
#1

I built a Car Ownership System on my RP mode and while I compile the mode no error
but while I enter the game I got crash on the start

this is the system

Top of the mode
Код:
enum ocInfo
{
	ocOwner[64],
	ocVeh,
	Float:ocPosX,
	Float:ocPosY,
	Float:ocPosZ,
	Float:ocPosA,
	ocColor1,
	ocColor2,
	ocKey,
};
new OCarInfo[5][ocInfo];
new public
Код:
public LoadCars()
{
	new arrCoords[19][64];
	new strFromFile2[256];
	new File: file = fopen("OwnCars.cfg", io_read);
	if(file)
	{
		new idx;
		while (idx < sizeof(OCarInfo))
		{
			fread(file, strFromFile2);
			split(strFromFile2, arrCoords, '|');
			OCarInfo[idx][ocKey] = strval(arrCoords[0]);
			strmid(OCarInfo[idx][ocOwner], arrCoords[1], 0, strlen(arrCoords[1]), 255);
			OCarInfo[idx][ocVeh] = strval(arrCoords[2]);
			OCarInfo[idx][ocPosX] = floatstr(arrCoords[3]);
			OCarInfo[idx][ocPosY] = floatstr(arrCoords[4]);
			OCarInfo[idx][ocPosZ] = floatstr(arrCoords[5]);
			OCarInfo[idx][ocPosA] = floatstr(arrCoords[6]);
			OCarInfo[idx][ocColor1] = strval(arrCoords[7]);
			OCarInfo[idx][ocColor2] = strval(arrCoords[8]);
			idx++;
		}
		fclose(file);
	}
	return 1;
}
On the public "OnPlayerStateChange"
Код:
	if(newstate==PLAYER_STATE_DRIVER)
	{
		new PlayerName[100]; GetPlayerName(playerid,PlayerName,30);
		if(OCarInfo[vehicle][ocOwner] == 1)
		{
			format(string,sizeof(string),"[ Vehicle Owner: %s ]", OCarInfo[vehicle][ocOwner] );
 		 	SendClientMessage(playerid,0x7E5F2FFF,string);
		}
 	}
	if(newstate==PLAYER_STATE_PASSENGER)
	{
		if(OCarInfo[vehicle][ocOwner] == 1)
		{
		format(string,sizeof(string),"[ Vehicle Owner: %s ]", OCarInfo[vehicle][ocOwner] );
	  SendClientMessage(playerid,0x7E5F2FFF,string);
		}
	}
on "OnGameModeInit"
Код:
	for(new o =0; o<sizeof(OCarInfo); o++)
	{
		CreateVehicle(OCarInfo[o][ocVeh],OCarInfo[o][ocPosX],OCarInfo[o][ocPosY],OCarInfo[o][ocPosZ],OCarInfo[o][ocPosA],-1,-1,-1);
	}
Sorry about my English
Reply
#2

I bet this is the problem:
for(new o =0; o<sizeof(OCarInfo); o++)

It maybe create vehicle with invalid modelid.

So you need:
pawn Код:
//TOP
static stock
  OCarAmount;
//
//In LoadCars()
//edit
while (idx < sizeof(OCarInfo))
{ fread(file, strFromFile2);
//to
while(fread(file, strFromFile2){
// and add
OCarAmount = idx; //before
 fclose(file);
//
//OnGameModeInit()
//edit
for(new o =0; o<sizeof(OCarInfo); o++)
//to
for(new o;o < OCarAmount ;o++)
At last, make sure that the file is written with right syntax, no space line, no comment, etc.
Reply
#3

How I can to add more cars from the game?
maybe I don't write it good
Reply
#4

Don't sorry about your english, because you can speak your mother language well, and most of others can not^^
Reply
#5

Man now it's ok but the car don't spawn
Reply
#6

forget a ')'
sorry : p
edit to
while(fread(file, strFromFile2)){
Reply
#7

I fixed it but new problem
The car not spawning
Reply
#8

add
printf("ocar amount:%d",OCarAmount);
below
LoadCars();
in OnGameModeInit()
and show us the output
Reply
#9

it's write 0
but I have one car
man you car build for me a command to add car to OwnCars.cfg
I don't really know how to do this..[to build the command]
Reply
#10

now show ur new LoadCars(),OnGameModeInit(), and OwnCars.cfg
I wanna know the major problem.

About the command, DO IT YOURSELF.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)