Car system has 1 bug
#1

Here's my OnPlayerEnterVehicle

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new string[128];
  if(Cars[GetPlayerVehicleID(playerid)][cOwned] == 0)
  {
  format(string,sizeof(string),"[ ! ] ID : %d ' %s ' Price : %d RCASH",GetPlayerVehicleID(playerid),Cars[GetPlayerVehicleID(playerid)][cDescription],Cars[GetPlayerVehicleID(playerid)][cPrice]);
  SendClientMessage(playerid,COLOR_GREY,string);
  return 0;
  }
  if(Cars[GetPlayerVehicleID(playerid)][cOwned] == 1)
  {
  format(string,sizeof(string),"[ ! ] ID : %d ' %s ' Bought by : %s",GetPlayerVehicleID(playerid),Cars[GetPlayerVehicleID(playerid)][cDescription],Cars[GetPlayerVehicleID(playerid)][cOwner]);
  SendClientMessage(playerid,COLOR_GREY,string);
  return 0;
  }
    return 1;
}
When i enter a vehicle it just says Turismo Price: 100

This happens for ALL vehicles including the Cheetah and Infernus in my scriptfiles..

And when i buy a vehicle i buy the infernus inside the turismo, then i try to sell the infernus it says i dont even own a vehicle? heres my /buy and /sell command:

pawn Код:
if(strcmp(cmd, "/buy", true) == 0)
    {
      if(IsPlayerConnected(playerid))
      {
            new playername[MAX_PLAYER_NAME];
            GetPlayerName(playerid, playername, sizeof(playername));
            for(new c=0;c<sizeof(Cars);c++)
            {
  if(IsPlayerInAnyVehicle(playerid))
                {
                 if(Cars[GetPlayerVehicleID(playerid)][cOwned] == 1)
                 {
                SendClientMessage(playerid,c_r,"[ ! ] This car is bought !");
                return 1;
                }
                if(Cars[GetPlayerVehicleID(playerid)][cPrice] == 0)
                {
                     SendClientMessage(playerid, c_r, "[ ! ] A price isn't set for this car, it is not meant to be bought!");
                        return 1;
                 }
                    if(PlayerInfo[playerid][pCarKey] != 255 && strcmp(playername, Cars[GetPlayerVehicleID(playerid)][cOwner], true) == 0)
                    {
                        SendClientMessage(playerid, c_r, "[ ! ] You can only own one car, sell your original car first before buying this one!");
                        return 1;
                    }
                    if(GetPlayerRcash(playerid) >= Cars[GetPlayerVehicleID(playerid)][cPrice])
   {
                    PlayerInfo[playerid][pCarKey] = c;
                        Cars[GetPlayerVehicleID(playerid)][cOwned] = 1;
                        strmid(Cars[GetPlayerVehicleID(playerid)][cOwner], playername, 0, strlen(playername), 255);
                        GivePlayerRcash(playerid,-Cars[GetPlayerVehicleID(playerid)][cPrice]);
                        SendClientMessage(playerid, COLOR_GREEN, "[ ! ] You have successfully purchased this car!");
                        SaveCars();
                        OnPlayerDataSave(playerid);
                        return 1;
                    }
                    else
                    {
                        SendClientMessage(playerid, c_r, "[ ! ] You don't have enough rcash!");
                        return 1;
                    }
                }
            }
        }
        return 1;
    }
    if(strcmp(cmd, "/sell", true) == 0)
    {
      if(IsPlayerConnected(playerid))
        {
            new playername[MAX_PLAYER_NAME];
            new car = PlayerInfo[playerid][pCarKey];
            GetPlayerName(playerid, playername, sizeof(playername));
            if(PlayerInfo[playerid][pCarKey] != 255 && strcmp(playername, Cars[PlayerInfo[playerid][pCarKey]][cOwner], true) == 0)
            {
                if(IsPlayerInAnyVehicle(playerid))
                {
                    if(Cars[car][cOwned] == 0)
                  {
                  SendClientMessage(playerid,c_r,"[ ! ] This car is not owned by you !");
                  return 1;
                  }
                    Cars[car][cOwned] = 0;
                    strmid(Cars[car][cOwner], "None", 0, strlen("None"), 255);
                    GivePlayerRcash(playerid,Cars[car][cPrice]);
                    PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
                    format(string, sizeof(string), "[ ! ] You have sold your Car for %i rcash!",Cars[car][cPrice]);
                    SendClientMessage(playerid, COLOR_GREEN, string);
                PlayerInfo[playerid][pCarKey] = 255;
                    OnPlayerDataSave(playerid);
                    SaveCars();
                    return 1;
                }
                else
                {
                  SendClientMessage(playerid,c_r,"[ ! ] You must be inside your car to sell it!");
                }
            }
            else
            {
            SendClientMessage(playerid,c_r,"[ ! ] You don't even own a car!");
            }
        }
        return 1;
    }
Reply
#2

Somebody help please ?? ?
Reply
#3

Quote:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new string[128];
  if(Cars[GetPlayerVehicleID(playerid)][cOwned] == 0)
  {
  format(string,sizeof(string),"[ ! ] ID : %d ' %s ' Price : %d RCASH",GetPlayerVehicleID(playerid),Cars[GetPlayerVehicleID(playerid)][cDescription],Cars[GetPlayerVehicleID(playerid)][cPrice]);
  SendClientMessage(playerid,COLOR_GREY,string);
  return 0;
  }
  if(Cars[GetPlayerVehicleID(playerid)][cOwned] == 1)
  {
  format(string,sizeof(string),"[ ! ] ID : %d ' %s ' Bought by : %s",GetPlayerVehicleID(playerid),Cars[GetPlayerVehicleID(playerid)][cDescription],Cars[GetPlayerVehicleID(playerid)][cOwner]);
  SendClientMessage(playerid,COLOR_GREY,string);
  return 0;
  }
    return 1;
}
Edit all GetPlayerVehicleID(playerid) to vehicleid.
Or again, code in OnPlayerStateChange(PLAYER_STATE_DRIVER) is better, cuz OnPlayerEnterVehicle doesn't get called when using PutPlayerInVehicle or hack in vehicle.
Reply
#4

Here's the problems i had and still have with your code and my old code.. When i enter a turismo it says infernus PRice 100 and i buy it. i own infernus now ! then i do /sell it says i dont have car ! I enter infernus or cheetah it doesnt say anything..
Reply
#5

Stupid me, I think I know what's the major bug.
You need to store vehicleid in enumeration

Example
pawn Код:
#define INVALID_CAR_ID (-1)
enum CarsInfo{
  //your old stuff
  Cars_Vecid
};
new Cars[...][CarsInfo];

stock Car_getVecCarID(vehicleid){
  for(new i,j = sizeof(Cars);i < j;i++)
    if(Cars[i][Car_VecID] == vehicleid) return i;
  return INVALID_CAR_ID;
}

//OnGameModeInit
Loop{
  Cars[i][Cars_VecID] = INVALID_CAR_ID
}
Cars[id][Cars_Vecid] = CreateVehicle//must use createvehicle


//OnPlayerEnterVehicle
new vecCarid = Car_getVecCarID(vehicleid);
if(vecCarID != INVALID_CAR_ID){
    //use Cars[vecCarID][...]
Same as buy/sell cars.
Reply
#6

DP
Reply
#7

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new string[128];
    new vecCarid = Car_getVecCarID(vehicleid);
    if(vecCarID != INVALID_CAR_ID)// (6105) : error 017: undefined symbol "vecCarID"
    {
  if(Cars[vecCarid][cOwned] == 0)
  {
  format(string,sizeof(string),"[ ! ] ID : %d ' %s ' Price : %d RCASH",vecCarid,Cars[vecCarid][cDescription],Cars[vecCarid][cPrice]);
  SendClientMessage(playerid,COLOR_GREY,string);
  }
  }
  if(Cars[vecCarid][cOwned] == 1)
  {
  format(string,sizeof(string),"[ ! ] ID : %d ' %s ' Bought by : %s",vecCarid,Cars[vecCarid][cDescription],Cars[vecCarid][cOwner]);
  SendClientMessage(playerid,COLOR_GREY,string);
  return 0;
  }
    return 1;
}
1 error now. It is inside the pawno code.

EDIT: Okay got it compiling.

EDIT #2 : I tried to add new vecCarid = Car_getVecCarID(vehicleid); to OnPlayerCommandText it says vehicleid is undefined lol. do i just make it playerid instead ?
Reply
#8

please don't doublepost and please don't bump!
Reply
#9

Weird ! I enter a cheetah it says no messages i /buy it says I have purchased this Turismo.... WTF?

Then i /sell You have successfully sold your Turismo...
Reply
#10

I think I need your whole script.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)