Problem with the car system -
Ro[X]y - 02.07.2009
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
Re: Problem with the car system -
yezizhu - 03.07.2009
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.
Re: Problem with the car system -
Ro[X]y - 03.07.2009
How I can to add more cars from the game?
maybe I don't write it good
Re: Problem with the car system -
yezizhu - 03.07.2009
Don't sorry about your english, because you can speak your mother language well, and most of others can not^^
Re: Problem with the car system -
Ro[X]y - 03.07.2009
Man now it's ok but the car don't spawn
Re: Problem with the car system -
yezizhu - 03.07.2009
forget a ')'
sorry : p
edit to
while(fread(file, strFromFile2)){
Re: Problem with the car system -
Ro[X]y - 03.07.2009
I fixed it but new problem

The car not spawning
Re: Problem with the car system -
yezizhu - 03.07.2009
add
printf("ocar amount:%d",OCarAmount);
below
LoadCars();
in OnGameModeInit()
and show us the output
Re: Problem with the car system -
Ro[X]y - 03.07.2009
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]
Re: Problem with the car system -
yezizhu - 03.07.2009
now show ur new LoadCars(),OnGameModeInit(), and OwnCars.cfg
I wanna know the major problem.
About the command, DO IT YOURSELF.