Doesn't save vehicle name
#1

I've been working a bit on a car dealer system but my vehicle name doesn't save.

This is the script:

Код:
enum carinfo
{
   VehicleNames[60],
   CarOwner[MAX_PLAYER_NAME],
   CarPrice,
   Owned,
   Float:vX,
   Float:vY,
   Float:vZ,
   Float:vR,
   Model
}

new CarInfo[7][carinfo];
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    new ID = GetCarID(vehicleid);
    new cardata[120];
    GetPlayerName(playerid,pname,sizeof(pname));
    format(cardata,sizeof(cardata),"/Accounts/Vehicle_%s.txt",pname);
    for(new i = 0;i<sizeof(CarInfo);i++)
    {
     	if(newstate == PLAYER_STATE_DRIVER)
     	{
      	    if(CarInfo[ID][Owned] == 0)
      	    {
     		new cstring[120];
     		format(cstring,sizeof(cstring),"{FFFFFF}Price: {00FF00}$%d",CarInfo[ID][CarPrice]);
		ShowPlayerDialog(playerid,DIALOG_CARDEALERSHIP,DIALOG_STYLE_MSGBOX,"{00FF00}CAR DEALERSHIP",cstring,"Buy","Cancel");
      	    }
    	}
   }
   return 1;
}
Код:
    
    new Float:x,Float:y,Float:z;
    new vehicleid = GetPlayerVehicleID(playerid);
    new ID = GetCarID(vehicleid);
    if(dialogid==DIALOG_CARDEALERSHIP)
    {
       	if(response==1)
       	{
	    if(GetPlayerMoney(playerid) < CarInfo[ID][CarPrice])
	    {
		GetPlayerPos(playerid,x,y,z);
		SendClientMessage(playerid,RED,"Insufficient funds");
		SetPlayerPos(playerid,x,y,z+3);
	    }
       	    if(GetPlayerMoney(playerid) >= CarInfo[ID][CarPrice])
       	    {
       		new VehName[60];
         	CarInfo[ID][Owned] = 1;
     		CarInfo[ID][VehicleNames] = VehName;
         	GivePlayerMoney(playerid,-CarInfo[ID][CarPrice]);
         	new cardata[64];
 		GetPlayerName(playerid,pname,sizeof(pname));
         	format(cardata,sizeof(cardata),"/Accounts/Vehicle_%s.txt",pname);
         	dini_Create(cardata);
         	dini_Set(cardata,"CarOwner",pname);
         	dini_Set(cardata,"CarName",VehName);
         	return 1;
	    }
       	}
    }
    return 1;
}
Код:
stock GetCarID(vehicleid)
{
    for(new i=0;i < sizeof(CarInfo);i++)
    {
        if(CarInfo[i][Model] == vehicleid)
        {
            return i;
        }
    }
    return 0;
}

stock AddBuyableVehicle(VehName[60],Cost,Float:vx,Float:vy,Float:vz,Float:vr,CarModel)
{
    new playerid;
    new pName[MAX_PLAYER_NAME];
    new vehicleid;
    new ID = GetCarID(vehicleid);
    CarInfo[ID][VehicleNames] = VehName;
    CarInfo[ID][CarPrice] = Cost;
    CarInfo[ID][CarOwner] = GetPlayerName(playerid,pName,sizeof(pName));
    CarInfo[ID][vX] = vx;
    CarInfo[ID][vY] = vy;
    CarInfo[ID][vZ] = vz;
    CarInfo[ID][vR] = vr;
    CarInfo[ID][Model] = CarModel;
    CreateVehicle(CarModel,vx,vy,vz,vr,1,1,0);
    return 1;
}
And here's this is what I get in the file:

CarOwner=MasterMJ
CarName=

The vehicle name doesn't appear behind CarName=
Reply
#2

Well no wonder, look at your second snippet, you create an arrray called "VehName" and then assign the enumerated CarName variable the value of the empty array "VehName", what else do you expect to happen?

pawn Код:
new VehName[60];
            CarInfo[ID][Owned] = 1;
            CarInfo[ID][VehicleNames] = VehName;
See? Of course that array is going to be empty, you're never storing anything into it in that context! Where are you trying to get the value of the array from?
Reply
#3

Quote:

Well no wonder, look at your second snippet, you create an arrray called "VehName" and then assign the enumerated CarName variable the value of the empty array "VehName", what else do you expect to happen?

Код:
new VehName[60];
            CarInfo[ID][Owned] = 1;
            CarInfo[ID][VehicleNames] = VehName;
See? Of course that array is going to be empty, you're never storing anything into it in that context! Where are you trying to get the value of the array from?

Код:
public OnGameModeInit()
{
    AddBuyableVehicle("Wrecked Glendale 1",10000,2135.4155,-1147.4376,24.2748,55.0182,604);
                             ^^= This value I'm trying to get.
    return 1;
}
Reply
#4

Fixed it myself...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)