What's wrong here? -
Cjgogo - 21.07.2011
I made this function and as compiled is working,but the caar is not added
pawn Код:
stock AddBuyableVehicle(FileName[],Cost,Float:vx,Float:vy,Float:vz,CarModel)
{
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(CarInfo[ID][CarOwner], 24, "CarOwnerName");
if(strlen(dini_Get("Owners.ini", FileName)))
{
format(CarInfo[ID][CarOwner], 24, "%s", dini_Get("Owners.ini", FileName));
CarInfo[ID][Owned] = 1;
}
CarInfo[ID][ForSell] = 1;
}
Of course this is not all the code,but why is not working?ok so here's enum CarInfo
pawn Код:
enum carinfo
{
CarNames[60],
CarOwner[24],
CarPrice,
Owned,
Float:vX,
Float:vY,
Float:vZ,
ForSell,
Model
}
so what's wor ng?
Re: What's wrong here? -
JaTochNietDan - 21.07.2011
Well for one thing, there's no CreateVehicle function!
And if you're asking why there is simply no line written into Owners.ini, then that would be because you're never using a function to write a line into it, you're only using dini_Get, rather than dini_Set!
I also suggest you read the dini documentation, because your code really makes no sense
Re: What's wrong here? -
Shockey HD - 21.07.2011
Tell me when the Vehicle is being created?
Re: What's wrong here? -
CJ101 - 21.07.2011
pawn Код:
stock AddBuyableVehicle(FileName[],Cost,Float:vx,Float:vy,Float:vz,CarModel)
{
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(CarInfo[ID][CarOwner], 24, "CarOwnerName");
if(strlen(dini_Get("Owners.ini", FileName)))
{
format(CarInfo[ID][CarOwner], 24, "%s", dini_Get("Owners.ini", FileName));
CarInfo[ID][Owned] = 1;
}
CarInfo[ID][ForSell] = 1;
CreateVehicle(CarInfo[ID][Model],CarInfo[ID][vX],CarInfo[ID][vY],CarInfo[ID][vZ],0,0,0,0);
}
That should create the vehicle for you.
Re: What's wrong here? -
Cjgogo - 22.07.2011
OK,but I'll post entire code,because when I enter the car created,it's not buyable.
pawn Код:
#define MAX_CARS 100
new CarInfo[MAX_CARS][carinfo];
new CarCount = -1;
enum carinfo
{
CarNames[60],
CarOwner[24],
CarPrice,
Owned,
Float:vX,
Float:vY,
Float:vZ,
ForSell,
Model
}
stock AddBuyableVehicle(FileName[],Cost,Float:vx,Float:vy,Float:vz,CarModel)
{
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(CarInfo[ID][CarOwner], 24, "CarOwnerName");
if(strlen(dini_Get("Owners.ini", FileName)))
{
format(CarInfo[ID][CarOwner], 24, "%s", dini_Get("Owners.ini", FileName));
CarInfo[ID][Owned] = 1;
}
CarInfo[ID][ForSell] = 1;
CreateVehicle(CarModel,vx,vy,vz,0,0,0,0);
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
CarCount ++;
new ID = CarCount;
new cstring[120];
new ostring[120];
format(cstring,sizeof(cstring),"This car is for sell.Price:%d",CarInfo[ID][CarPrice]);
format(ostring,sizeof(ostring),"This car is owned by:%s",CarInfo[ID][CarOwner]);
if(newstate == PLAYER_STATE_DRIVER)
{
if(CarInfo[ID][ForSell] == 1 && CarInfo[ID][Owned] == 0) return ShowPlayerDialog(playerid,DIALOG_CFS,DIALOG_STYLE_MSGBOX,"CarInfo",cstring,"Accept","Cancel") && TogglePlayerControllable(playerid,true);
if(CarInfo[ID][ForSell] == 0 && CarInfo[ID][Owned] == 1) return SendClientMessage(playerid,COLOR_RED,ostring);
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
CarCount ++;
new ID = CarCount;
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");
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;
}
The only problem is that when i enter the created car is not buyable,nothing happens.Please post nice replies,it's my first ever car system,so help me.
Re: What's wrong here? -
TouR - 22.07.2011
The ID supposed to be the player's CarID try this
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
CarCount ++;
new ID = GetPlayerVehicleID(playerid);
new cstring[120];
new ostring[120];
format(cstring,sizeof(cstring),"This car is for sell.Price:%d",CarInfo[ID][CarPrice]);
format(ostring,sizeof(ostring),"This car is owned by:%s",CarInfo[ID][CarOwner]);
if(newstate == PLAYER_STATE_DRIVER)
{
if(CarInfo[ID][ForSell] == 1 && CarInfo[ID][Owned] == 0) return ShowPlayerDialog(playerid,DIALOG_CFS,DIALOG_STYLE_MSGBOX,"CarInfo",cstring,"Accept","Cancel") && TogglePlayerControllable(playerid,true);
if(CarInfo[ID][ForSell] == 0 && CarInfo[ID][Owned] == 1) return SendClientMessage(playerid,COLOR_RED,ostring);
}
return 1;
}
Re: What's wrong here? -
Cjgogo - 22.07.2011
Not working,more sugesstion pls?
Re: What's wrong here? -
MadeMan - 22.07.2011
pawn Код:
#define MAX_CARS 100
enum carinfo
{
CarID,
CarNames[60],
CarOwner[24],
CarPrice,
Owned,
Float:vX,
Float:vY,
Float:vZ,
ForSell,
Model
}
new CarInfo[MAX_CARS][carinfo];
new CarCount = -1;
stock AddBuyableVehicle(FileName[],Cost,Float:vx,Float:vy,Float:vz,CarModel)
{
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(CarInfo[ID][CarOwner], 24, "CarOwnerName");
if(strlen(dini_Get("Owners.ini", FileName)))
{
format(CarInfo[ID][CarOwner], 24, "%s", dini_Get("Owners.ini", FileName));
CarInfo[ID][Owned] = 1;
}
CarInfo[ID][ForSell] = 1;
CarInfo[ID][CarID] = CreateVehicle(CarModel,vx,vy,vz,0,0,0,0);
}
stock GetCarID(vehicleid)
{
for(new i=0; i < sizeof(CarInfo); i++)
{
if(CarInfo[i][CarID] == vehicleid)
{
return i;
}
}
return 0;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
{
new vehicleid = GetPlayerVehicleID(playerid);
new ID = GetCarID(vehicleid);
new string[128];
if(CarInfo[ID][ForSell] == 1 && CarInfo[ID][Owned] == 0)
{
format(string,sizeof(string),"This car is for sell.Price:%d",CarInfo[ID][CarPrice]);
ShowPlayerDialog(playerid,DIALOG_CFS,DIALOG_STYLE_MSGBOX,"CarInfo",string,"Accept","Cancel");
TogglePlayerControllable(playerid,true);
return 1;
}
if(CarInfo[ID][ForSell] == 0 && CarInfo[ID][Owned] == 1)
{
format(string,sizeof(string),"This car is owned by:%s",CarInfo[ID][CarOwner]);
SendClientMessage(playerid,COLOR_RED,string);
return 1;
}
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid==DIALOG_CFS)
{
if(response==1)
{
new vehicleid = GetPlayerVehicleID(playerid);
new ID = GetCarID(vehicleid);
if(GetPlayerMoney(playerid) < CarInfo[ID][CarPrice]) return SendClientMessage(playerid,COLOR_RED,"You don't have enough money to buy this car");
CarInfo[ID][Owned] = 1;
GivePlayerMoney(playerid,-CarInfo[ID][CarPrice]);
SendClientMessage(playerid,COLOR_RED,"You have bought this car");
}
return 1;
}
return 1;
}
Re: What's wrong here? -
crossx7 - 22.07.2011
its always good to learn it ure self!
may watch on wiki.samp
Re: What's wrong here? -
TouR - 22.07.2011
Quote:
Originally Posted by Cjgogo
Not working,more sugesstion pls?
|
Then your carids are fucked

Check id the vehicle's id is the ones you wanted to be..