02.08.2011, 15:30
OK,so I scripted a car dealership system but,there are a few bugs.Here's the code(bugs at bottom explained):
USAGE of AddBuyableVehicle:
Bugs:1)Every car is for sell not only the one created by AddBuyableVehicle,although only that one should be for sale,anyway after I buy it,it's still for sell.
2)The dini string is not created,but stores the information in the Owners.txt files,and it stores them wrongly like:
Owner:
Car Type:
I mean it doesn't show neither the name of the ownner,nor the name of the car.SO,is there another way to make a database?or what's worng in my script?
HELP ME ASAP!!!
pawn Код:
enum carinfo
{
CarNames[60],
CarOwner[24],
CarPrice,
Owned,
Float:vX,
Float:vY,
Float:vZ,
Model
}
new CarInfo[7][carinfo];
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 pName[MAX_PLAYER_NAME];
new vehicleid;
new ID = GetCarID(vehicleid);
CarInfo[ID][CarPrice] = Cost;
CarInfo[ID][CarNames] = Name;
CarInfo[ID][CarOwner] = GetPlayerName(playerid,pName,sizeof(pName));
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);
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
new ID = GetCarID(vehicleid);
new string[120];
format(string,sizeof(string),"/Accounts/Owners.ini",CarInfo[ID][CarOwner]);
for(new i = 0;i<sizeof(CarInfo);i++)
{
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;
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)
{
if(response==0) return 1;
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])
{
new Name[60];
CarInfo[ID][CarNames] = Name;
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];
format(string,sizeof(string),"/Accounts/Owners.txt",CarInfo[ID][CarOwner]);
dini_Create(string);
dini_Set(string,"Info:Owner",CarInfo[ID][CarOwner]);
dini_Set(string,"Info:CarName",Name);
return 1;
}
}
return 1;
}
Код:
AddBuyableVehicle("Turismo",10000,-1976.7314,301.9694,34.9724,451);
2)The dini string is not created,but stores the information in the Owners.txt files,and it stores them wrongly like:
Owner:
Car Type:
I mean it doesn't show neither the name of the ownner,nor the name of the car.SO,is there another way to make a database?or what's worng in my script?
HELP ME ASAP!!!