Need help ASAP!
#1

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.

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;
}
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:

pawn Код:
stock GetCarID(vehicleid)
{
    for(new i = 0;i < sizeof(CarInfo);i++)
    {
        if(CarInfo[i][Model] == vehicleid)
        {
            return i;
        }
    }
    return 0;
}
Код:
ID = GetCarID
Another player told me on another topic to define ID like that,but maybe there's another define for ID,so please help.
Reply
#2

hm I guess the Model in CarInfo[i][Model] is the actual vehicle model..
the vehicle ID and the vehicle model are 2 different things..
the ID is server based. On each server there can only be 1 vehicle with the same ID... however many vehicles with the same model..
if you have the ID anyways you don't need to check for it
Reply
#3

so how to actually fix it sascha
Reply
#4

pawn Код:
new ID = GetCarID(bv);
try placing this under CreateVehicle, because you are trying to get vehicle id before vehicle is created
and delete
pawn Код:
new ID = GetCarID(vehicleid);
new vehicleid=GetPlayerVehicleID(vehicleid);
edit: i was talking about the code in OnDialogResponse
Reply
#5

pawn Код:
CarInfo[ID][CarPrice]
instead of this just use
pawn Код:
CarInfo[vehicleid][CarPrice]
vehicleid is already defined at your "AddBuyableVehicle" (or w/e) part
Reply
#6

ok savcha i delted the ID and replaced it with "vehicleid",but now the CarName can't be written in the databse therefore there is no welcome message,and if someone else enters an owned car I don't know what happens,but how to fix that?
Reply
#7

'cause you need to change the ID to vehicleid also at OnPlayerStateChange and whereever else
Reply
#8

well when I said I deleted ID and replaced it with vehcileid I mean i replaced it evrywhere I am not that dumb FFS who would replace only CarPrice,so how to fix?
Reply
#9

hm I also talked about the CarInfos at the other callbacks...
in case you also did so, you have a vehicle list somewhere from which it reads the name actually?
Reply
#10

i dont have a list i guess i must do 1
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)