21.05.2011, 10:35
Hey there !
Im trying to make a vehicle system for my GM
Everything I done :
Forwards
Publics
Under OnGameModeInIt
I tried to make a command (for testing) that will create a vehicle near me ...
Like this
and a park command (for testing)
Now, I got 3 vehicles total that I added ongamemodeinit
Now , When im getting into the game ... im getting into 1 of these cars .... I try to /park them , and it wont let me , it returns me You cannot park this car! , Like it should , cuz its not my car.
But when I use ncar and creating a vehicle that I will own, and im trying to /park it it still says I cannot park this car .
+ , When I enter ANY VEHICLE NOW , it allways says its my vehicle.
Im trying to make a vehicle system for my GM
Everything I done :
Forwards
pawn Код:
forward GetVehicleSlot();
forward VehicleCreate(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawntime, ownername[21]);
forward SaveVehicleData(vehicle,fName[37]);
forward LoadVehicleData(fName[37]);
forward LoadAllVehiclesData();
pawn Код:
public GetVehicleSlot()
{
for(new v = 0; v < sizeof(valid); v++)
{
if(!valid[v]) return v;
}
return -1;
}
public VehicleCreate(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawntime, ownername[21])
{
new id = GetVehicleSlot();
CarData[id][model] = modelid;
CarData[id][posX] = x;
CarData[id][posY] = y;
CarData[id][posZ] = z;
CarData[id][fAngle] = angle;
CarData[id][cColor1] = color1;
CarData[id][cColor2] = color2;
CarData[id][respawn] = respawntime;
CarData[id][owner] = ownername;
valid[id] = true;
CreateVehicle(modelid, x, y, z, angle, color1, color2, respawntime);
return id;
}
public SaveVehicleData(vehicle,fName[37])
{
if(!dini_Exists(fName))
{
dini_Create(fName);
}
dini_IntSet(fName,"Model",CarData[vehicle][model]);
dini_FloatSet(fName,"PosX",CarData[vehicle][posX]);
dini_FloatSet(fName,"PosY",CarData[vehicle][posY]);
dini_FloatSet(fName,"PosZ",CarData[vehicle][posZ]);
dini_FloatSet(fName,"Angle",CarData[vehicle][fAngle]);
dini_IntSet(fName,"Color1",CarData[vehicle][cColor1]);
dini_IntSet(fName,"Color2",CarData[vehicle][cColor2]);
dini_IntSet(fName,"RespawnTime",CarData[vehicle][respawn]);
dini_Set(fName,"Owner",CarData[vehicle][owner]);
}
public LoadVehicleData(fName[37])
{
CreateVehicle(dini_Int(fName,"Model"),dini_Float(fName,"PosX"),dini_Float(fName,"PosY"),dini_Float(fName,"PosZ"),dini_Float(fName,"Angle"),dini_Int(fName,"Color1"),dini_Int(fName,"Color2"),dini_Int(fName,"RespawnTime"));
}
public LoadAllVehiclesData()
{
new vName[37],index = 0;
format(vName,sizeof(vName),"%d.ini",index);
while(dini_Exists(vName))
{
LoadVehicleData(vName);
index++;
format(vName, sizeof(vName), "%d.ini", index);
}
}
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new OwnerName[37];
format(OwnerName,sizeof(OwnerName),CARSFILE,GetPlayerVehicleID(playerid));
new str[256];
if(dini_Exists(OwnerName))
{
if(strlen(dini_Get(OwnerName,"Owner")) >= 1)
{
format(str,sizeof(str),"This vehicle is owned by %s.",dini_Get(OwnerName,"Owner"));
SendClientMessage(playerid,COLOR_GRAYA,str);
}
}
return 1;
}
pawn Код:
LoadAllVehiclesData();
I tried to make a command (for testing) that will create a vehicle near me ...
Like this
pawn Код:
dcmd_ncar(playerid, params[])
{
new model2;
if(!sscanf(params,"i",model2))
{
new Float:pX,Float:pY,Float:pZ;
GetPlayerPos(playerid,pX,pY,pZ);
new str[21];
format(str,sizeof(str),"%s",GetName(playerid));
VehicleCreate(model2,pX+2.0,pY+2.0,pZ,360,16,16,300,str);
}else return 0;
return 1;
}
pawn Код:
if(strcmp(cmd,"/park",true) == 0)
{
if(IsPlayerInAnyVehicle(playerid))
{
new OwnerName[37];
format(OwnerName,sizeof(OwnerName),CARSFILE,GetPlayerVehicleID(playerid));
new strname[256];
format(strname,sizeof(strname),"%s",GetName(playerid));
new playercar[36];
format(playercar,sizeof(playercar),CARSFILE,GetPlayerVehicleID(playerid));
if(!dini_Exists(playercar)) return SendClientMessage(playerid,COLOR_RED,"You cannot park this car !");
if(strcmp(dini_Get(OwnerName,"Owner"),strname,true) == 0)
{
new vid = GetPlayerVehicleID(playerid);
new Float:vX,Float:vY,Float:vZ;
GetVehiclePos(vid,vX,vY,vZ);
new id = GetVehicleSlot();
CarData[id][posX] = vX;
CarData[id][posY] = vY;
CarData[id][posZ] = vZ;
new VehFile[37];
format(VehFile,sizeof(VehFile),CARSFILE,vid);
SaveVehicleData(GetPlayerVehicleID(playerid),VehFile);
SendClientMessage(playerid,COLOR_MEDIUMYELLOW,"Parked.");
}else return SendClientMessage(playerid,COLOR_RED,"You cannot park this car !");
}
return 1;
}
pawn Код:
AddStaticVehicleEx(405,2159.67456055,-1807.06066895,13.37259960,0.00000000,-1,-1,500);
AddStaticVehicleEx(436,1899.20117188,-1876.46215820,13.39540863,0.00000000,-1,-1,500);
AddStaticVehicleEx(587,1606.54626465,-1700.16735840,13.35687542,0.00000000,-1,-1,500);
But when I use ncar and creating a vehicle that I will own, and im trying to /park it it still says I cannot park this car .
+ , When I enter ANY VEHICLE NOW , it allways says its my vehicle.