[HELP]Car Dealership system!!!
#1

OK,so I scripted a car dealership system but,there are a few bugs.Here's the code(bugs at bottom explained):

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;
}
USAGE of AddBuyableVehicle:

Код:
AddBuyableVehicle("Turismo",10000,-1976.7314,301.9694,34.9724,451);
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!!!
Reply
#2

pawn Код:
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);
At 2)
You have a format(); but you have nothing to insert into "string"

pawn Код:
format(string,sizeof(string),"/Accounts/Owners/%s.txt",CarInfo[ID][CarOwner]);
         dini_Create(string);                //^^added
         dini_Set(string,"Info:Owner",CarInfo[ID][CarOwner]);
         dini_Set(string,"Info:CarName",Name);
Reply
#3

thanks and please help me about first problem too some1
Reply
#4

any1?(1st problem only pls)
Reply
#5

I see you have the "owned" at your enumaration but you dont use it at OnPlayerStateChange
It should be like:


pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
   new ID = GetPlayerVehicleID(playerid);
   if( CarInfo[ID][Owned] == 0 )
   {
        //...Cars for Sale code
   }
   else
   {
      //... Owned Cars code
   }
return 1;
}
Reply
#6

ok and in the end the problem of evry car being for ssell?how to solve that?(i know the problem is at onplayerstatechange but what to do i think the problem is at "for new")
Reply
#7

pls help me is the only problem that i have more(that evry car is for sell),the rest of the code works fucking well,the database also works,BUT EVRY car is for sell pls help
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)