07.08.2011, 14:46
This is my new version of the car dealership,but there's only 1 problem,I'll list it in the end of the topic.
No compiling errors,the car that I added for test it's OK,the database works OK,but after I buy that car,evry car is for sell,and of course the problem is:
Another player told me on another topic to define ID like that,but maybe there's another define for ID,so please help.
pawn Код:
enum carinfo
{
CarNames[60],
CarOwner[MAX_PLAYER_NAME],
CarPrice,
Owned,
Float:vX,
Float:vY,
Float:vZ,
Model
}
new CarInfo[7][carinfo];
new Turismo;
stock GetCarID(vehicleid)
{
for(new i = 0;i < sizeof(CarInfo);i++)
{
if(CarInfo[i][Model] == vehicleid)
{
return i;
}
}
return 0;
}
stock AddBuyableVehicle(Name[60],Cost,Float:vx,Float:vy,Float:vz,CarModel)
{
new playerid;
new vehicleid=GetPlayerVehicleID(playerid);
new ID = GetCarID(vehicleid);
CarInfo[ID][CarPrice] = Cost;
CarInfo[ID][CarNames] = Name;
CarInfo[ID][vX] = vx;
CarInfo[ID][vY] = vy;
CarInfo[ID][vZ] = vz;
CarInfo[ID][Model] = CarModel;
CreateVehicle(CarModel,vx,vy,vz,45,0,0,0);
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
new ID = GetCarID(vehicleid);
new string[120];
format(string,sizeof(string),"/Accounts/Owners.ini",CarInfo[ID][CarOwner]);
if(vehicleid == Turismo)
{
new Owner[MAX_PLAYER_NAME];
GetPlayerName(playerid,Owner,sizeof(Owner));
CarInfo[ID][CarOwner] = Owner;
new cstring[120];
format(cstring,sizeof(cstring),"This car is for sell.Price:%d$",CarInfo[ID][CarPrice]);
if(newstate == PLAYER_STATE_DRIVER) return ShowPlayerDialog(playerid,DIALOG_CFS,DIALOG_STYLE_MSGBOX,"CarInfo",cstring,"Accept","Cancel") && TogglePlayerControllable(playerid,true);
}
if(newstate == PLAYER_STATE_DRIVER && CarInfo[ID][Owned] == 1)
{
if(!strcmp(CarInfo[ID][CarOwner],dini_Get(string,"Info:Owner"),false))
{
new ystring[120];
format(ystring,sizeof(ystring),"Welcome to your own car");
GameTextForPlayer(playerid,ystring,2500,4);
}
else
{
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
new ostring[120];
format(ostring,sizeof(ostring),"This car is owned by:%s",CarInfo[ID][CarOwner]);
GameTextForPlayer(playerid,ostring,2500,4);
SetPlayerPos(playerid,x,y,z + 3);
}
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
new Float:x,Float:y,Float:z;
new vehicleid=GetPlayerVehicleID(playerid);
new ID = GetCarID(vehicleid);
new bv;
if(dialogid==DIALOG_CFS)
{
new Owner[MAX_PLAYER_NAME];
GetPlayerName(playerid,Owner,sizeof(Owner));
CarInfo[ID][CarOwner] = Owner;
if(response==0) return GetPlayerPos(playerid,x,y,z) && SendClientMessage(playerid,COLOR_RED,"Operation aborted") && SetPlayerPos(playerid,x,y,z + 3);
if((response==1) && GetPlayerMoney(playerid) < CarInfo[ID][CarPrice]) return GetPlayerPos(playerid,x,y,z) && SendClientMessage(playerid,COLOR_RED,"You don't have enough money to buy this car") && SetPlayerPos(playerid,x,y,z + 3);
else if((response==1) && GetPlayerMoney(playerid) >= CarInfo[ID][CarPrice])
{
bv = CreateVehicle(GetVehicleModel(GetPlayerVehicleID(playerid)),-1997.3328,290.0271,34.0448,0,0,0,0);
PutPlayerInVehicle(playerid,bv,0);
CarInfo[ID][Owned] = 1;
GivePlayerMoney(playerid,-CarInfo[ID][CarPrice]);
new string[64];
if(!dini_Exists(string))
{
format(string,sizeof(string),"/CarDealership/%s.txt",CarInfo[ID][CarOwner]);
dini_Create(string);
dini_Set(string,"Info:CarName",CarInfo[ID][CarNames]);
return 1;
}
if(dini_Exists(string))
{
dini_Set(string,"Info:CarName",CarInfo[ID][CarNames]);
}
}
}
return 1;
}
pawn Код:
stock GetCarID(vehicleid)
{
for(new i = 0;i < sizeof(CarInfo);i++)
{
if(CarInfo[i][Model] == vehicleid)
{
return i;
}
}
return 0;
}
Код:
ID = GetCarID