[HELP]Car System!!!
#1

So,I had an old topic,but I really modified many things about it,so I decided to make a new topic,but still a few errors,here's the code:

pawn Код:
#define MAX_CARS 200

new CarInfo[MAX_CARS][carinfo];
new CarCount = -1;

stock AddBuyableVehicle(Name[],Cost,Float:vx,Float:vy,Float:vz,CarModel)
{
    new playerid;
    new string[64];
    if(!dini_Exists("Owners.ini"))
    {
        dini_Create("Owners.ini");
    }
    CarCount ++;
    new ID = CarCount;
    CarInfo[ID][CarPrice] = Cost;
    CarInfo[ID][vX] = vx;
    CarInfo[ID][vY] = vy;
    CarInfo[ID][vZ] = vz;
    CarInfo[ID][Model] = CarModel;
    format(Name,strlen(Name) + 10,Name[GetVehicleModel(GetPlayerVehicleID(playerid))-400],Name);
    if(strlen(dini_Get("Owners.ini", string)))
    {
    format(string,sizeof(string),"/Accounts/Owners.ini",CarInfo[ID][CarOwner]);
    CarInfo[ID][Owned] = 1;
    }
    dini_Create(string);
    dini_Set(string,"Info:CarInfo[ID][CarOwner]-CarInfo[ID][Model]-Name",CarInfo[ID][CarOwner]);
    CarInfo[ID][ForSell] = 1;
    CreateVehicle(CarModel,vx,vy,vz,45,0,0,0);
}

stock GetCarID(vehicleid)
{
    for(new i=0;i < sizeof(CarInfo);i++)
    {
        if(CarInfo[i][Model] == vehicleid)
        {
            return i;
        }
    }
    return 0;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
        new vehicleid=GetPlayerVehicleID(playerid);
    new ID = GetCarID(vehicleid);
    new string[120];
    format(string,sizeof(string),"/Accounts/Owners.ini",CarInfo[ID][CarOwner]);
    format(Name,strlen(Name) + 10,Name[GetVehicleModel(GetPlayerVehicleID(playerid))-400],Name); //615(Error Line)
    for(new i;i<MAX_CARS;i++)
    {
      new cstring[120];
      format(cstring,sizeof(cstring),"This car is for sell.Price:%d$",CarInfo[ID][CarPrice]);
      if(newstate == PLAYER_STATE_DRIVER && CarInfo[ID][ForSell] == 1) return ShowPlayerDialog(playerid,DIALOG_CFS,DIALOG_STYLE_MSGBOX,"CarInfo",cstring,"Accept","Cancel") && TogglePlayerControllable(playerid,true);
    }
    if(!strcmp(CarInfo[ID][CarOwner],dini_Get(string,"Info:CarInfo[ID][CarOwner]-CarInfo[ID][Model]-Name"),false))
    {
        new ystring[120];
        format(ystring,sizeof(ystring),"Welcome to your own '%s'",Name);
        GameTextForPlayer(playerid,ystring,2500,4);
        return 1;
    }
    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;
    }
    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 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,1);
         CarInfo[ID][Owned] = 1;
         GivePlayerMoney(playerid,-CarInfo[ID][CarPrice]);
         return 1;
       }
    }
  return 1;
}
Here are the errors:

Код:
D:\Jocuri\GTA\GTA San Andreas\SAMP\samp03csvr_R2-2_win32\gamemodes\sfcnr.pwn(615) : error 017: undefined symbol "Name"
D:\Jocuri\GTA\GTA San Andreas\SAMP\samp03csvr_R2-2_win32\gamemodes\sfcnr.pwn(615) : warning 215: expression has no effect
D:\Jocuri\GTA\GTA San Andreas\SAMP\samp03csvr_R2-2_win32\gamemodes\sfcnr.pwn(615) : error 001: expected token: ";", but found "]"
D:\Jocuri\GTA\GTA San Andreas\SAMP\samp03csvr_R2-2_win32\gamemodes\sfcnr.pwn(615) : error 029: invalid expression, assumed zero
D:\Jocuri\GTA\GTA San Andreas\SAMP\samp03csvr_R2-2_win32\gamemodes\sfcnr.pwn(615) : fatal error 107: too many error messages on one line
But,to be considered it's my first car systeem ever,so please post helpful replies.
Reply
#2

You haven't defined the variable "Name"
Reply
#3

How should I define it?(becauuse on the stock there's no need to define it but in OnPlayerStateChange yes)
Reply
#4

I gave you a working code and now you messed everything up. Why?
Reply
#5

I may still use your code MadeMan,but there was a problem,that evry car was buyable,and the new thing is actually I made the code so that it saves user and his car to a file.So again,in your code,absolutely evry car was buyable
Reply
#6

Show how you use AddBuyableVehicle.
Reply
#7

nvm I almost fixed it,and it works cool,just that when is supossedd to ejects me it teleports me somewhere else

so I call this momentanly FIXED(momentanly)

Now it shows only for the buyable car!

EDIT:Sorry looks like somehow,for the 1st car i entered it didn't show,but it did then again for evry car

EDIT:Now I actually discovered that for some vehicles it shows for other it doesn't because of Name i think there's a problem
Reply
#8

So,here's the last code I managed to write ,there are no errors when compiling,but there is a problem:

pawn Код:
#define MAX_CARS 200

new CarInfo[MAX_CARS][carinfo];
new CarCount = -1;

stock AddBuyableVehicle(Name[],Cost,Float:vx,Float:vy,Float:vz,CarModel)
{
    new playerid;
    new string[64];
    if(!dini_Exists("Owners.ini"))
    {
        dini_Create("Owners.ini");
    }
    CarCount ++;
    new ID = CarCount;
    CarInfo[ID][CarPrice] = Cost;
    CarInfo[ID][vX] = vx;
    CarInfo[ID][vY] = vy;
    CarInfo[ID][vZ] = vz;
    CarInfo[ID][Model] = CarModel;
    format(Name,strlen(Name) + 10,Name[GetVehicleModel(GetPlayerVehicleID(playerid))-400],Name);
    if(strlen(dini_Get("Owners.ini", string)))
    {
    format(string,sizeof(string),"/Accounts/Owners.ini",CarInfo[ID][CarOwner]);
    CarInfo[ID][Owned] = 1;
    }
    dini_Create(string);
    dini_Set(string,"Info:CarInfo[ID][CarOwner]-CarInfo[ID][Model]-Name",CarInfo[ID][CarOwner]);
    CarInfo[ID][ForSell] = 1;
    CreateVehicle(CarModel,vx,vy,vz,45,0,0,0);
}

stock GetCarID(vehicleid)
{
    for(new i=0;i < sizeof(CarInfo);i++)
    {
        if(CarInfo[i][Model] == vehicleid)
        {
            return i;
        }
    }
    return 0;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
        new vehicleid=GetPlayerVehicleID(playerid);
    new ID = GetCarID(vehicleid);
    new string[120];
    new Name[120];
    format(string,sizeof(string),"/Accounts/Owners.ini",CarInfo[ID][CarOwner]);
    format(Name,strlen(Name) + 10,Name[GetVehicleModel(GetPlayerVehicleID(playerid))-400],Name);
    for(new i;i<MAX_CARS;i++)
    {
      new cstring[120];
      format(cstring,sizeof(cstring),"This car is for sell.Price:%d$",CarInfo[ID][CarPrice]);
      if(newstate == PLAYER_STATE_DRIVER && CarInfo[ID][ForSell] == 1) return ShowPlayerDialog(playerid,DIALOG_CFS,DIALOG_STYLE_MSGBOX,"CarInfo",cstring,"Accept","Cancel") && TogglePlayerControllable(playerid,true);
    }
    if(!strcmp(CarInfo[ID][CarOwner],dini_Get(string,"Info:CarInfo[ID][CarOwner]-CarInfo[ID][Model]-Name"),false))
    {
        new ystring[120];
        format(ystring,sizeof(ystring),"Welcome to your own '%s'",Name);
        GameTextForPlayer(playerid,ystring,2500,4);
        return 1;
    }
    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;
    }
    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 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,1);
         CarInfo[ID][Owned] = 1;
         GivePlayerMoney(playerid,-CarInfo[ID][CarPrice]);
         return 1;
       }
    }
  return 1;
}
Now the problem is,that the buying dialog shows to some vehicles,but to others it doesn't,so I suposse the error is here:

pawn Код:
format(Name,strlen(Name) + 10,Name[GetVehicleModel(GetPlayerVehicleID(playerid))-400],Name);
better said it's at "-400" I think,and if I put "-611" then it doesn't show for any vehilce.

Please help me you don't know how I feel,it's like a step from finishing this system,but that last step I can't do it
Reply
#9

somebody pls?(tell me what's worng on last post)
Reply
#10

really nobody knows how to fix this?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)