18.11.2011, 21:11
(
Последний раз редактировалось HondaCBR; 18.11.2011 в 22:38.
)
Basically i have /park /unspawn and /spawn commands for vehicles you own.
And the thing is that when you /park and leave the server it's fine, when you come back the vehicle is where you parked it, but if you /park, /unspawn /spawn the vehicle is at the previous location when you parked it and left the server, it doesnt spawn in the new parked location, here is the code.
Below /park /spawn /unspawn (they are in GUI)
Below function for saving, spawning and unspawning
Thx
And the thing is that when you /park and leave the server it's fine, when you come back the vehicle is where you parked it, but if you /park, /unspawn /spawn the vehicle is at the previous location when you parked it and left the server, it doesnt spawn in the new parked location, here is the code.
Below /park /spawn /unspawn (they are in GUI)
pawn Код:
if(listitem == 0)// park
{//
SendClientMessage(playerid, 0xFFFFFFAA, "Car parked.");
Save(playerid);
HidePlayerDialog(playerid);
return 1;
}
if(listitem == 3)//spawn
{//
if(Zespalnowane[playerid] == 1)
{
SendClientMessage(playerid, 0xAFAFAFAA, "You need to unspawn the car first.");
HidePlayerDialog(playerid);
return 1;
}
else
{
Load(playerid);
Zespalnowane[playerid] = 1;
HidePlayerDialog(playerid);
}
}
if(listitem == 4)// unspawn
{//
if(Zespalnowane[playerid] == 0)
{
SendClientMessage(playerid, 0xAFAFAFAA, "You need to spawn the car first.");
HidePlayerDialog(playerid);
return 1;
}
else
{
Save2(playerid);
Zespalnowane[playerid] = 0;
HidePlayerDialog(playerid);
return 1;
}
}
pawn Код:
public Load(playerid)
{
new file[256], name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(file,sizeof(file),"Cars/%s.ini",name);
if(dini_Exists(file))
{
VehicleInfo[playerid][Model] = dini_Int(file, "Model");
VehicleInfo[playerid][Price] = dini_Int(file, "Price");
VehicleInfo[playerid][CarX] = dini_Float(file, "X");
VehicleInfo[playerid][CarY] = dini_Float(file, "Y");
VehicleInfo[playerid][CarZ] = dini_Float(file, "Z");
VehicleInfo[playerid][CarRot] = dini_Float(file, "Rot");
VehicleInfo[playerid][Locked] = dini_Int(file, "Locked");
VehicleInfo[playerid][mod1] = dini_Int(file, "mod1");
VehicleInfo[playerid][mod2] = dini_Int(file, "mod2");
VehicleInfo[playerid][mod3] = dini_Int(file, "mod3");
VehicleInfo[playerid][mod4] = dini_Int(file, "mod4");
VehicleInfo[playerid][mod5] = dini_Int(file, "mod5");
VehicleInfo[playerid][mod6] = dini_Int(file, "mod6");
VehicleInfo[playerid][mod7] = dini_Int(file, "mod7");
VehicleInfo[playerid][mod8] = dini_Int(file, "mod8");
VehicleInfo[playerid][mod9] = dini_Int(file, "mod9");
VehicleInfo[playerid][mod10] = dini_Int(file, "mod10");
VehicleInfo[playerid][mod11] = dini_Int(file, "mod11");
VehicleInfo[playerid][mod12] = dini_Int(file, "mod12");
VehicleInfo[playerid][mod13] = dini_Int(file, "mod13");
VehicleInfo[playerid][mod14] = dini_Int(file, "mod14");
VehicleInfo[playerid][mod15] = dini_Int(file, "mod15");
VehicleInfo[playerid][mod16] = dini_Int(file, "mod16");
VehicleInfo[playerid][mod17] = dini_Int(file, "mod17");
VehicleInfo[playerid][paintjob] = dini_Int(file, "paintjob");
VehicleInfo[playerid][colora] = dini_Int(file, "color1");
VehicleInfo[playerid][colorb] = dini_Int(file, "color2");
Vehicle[playerid] = CreateVehicle(VehicleInfo[playerid][Model], VehicleInfo[playerid][CarX], VehicleInfo[playerid][CarY], VehicleInfo[playerid][CarZ], VehicleInfo[playerid][CarRot], VehicleInfo[OwnerID[playerid]][colora], VehicleInfo[OwnerID[playerid]][colorb], -1);
if(VehicleInfo[playerid][mod1]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod1]); }
if(VehicleInfo[playerid][mod2]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod2]); }
if(VehicleInfo[playerid][mod3]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod3]); }
if(VehicleInfo[playerid][mod4]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod4]); }
if(VehicleInfo[playerid][mod5]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod5]); }
if(VehicleInfo[playerid][mod6]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod6]); }
if(VehicleInfo[playerid][mod7]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod7]); }
if(VehicleInfo[playerid][mod8]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod8]); }
if(VehicleInfo[playerid][mod9]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod9]); }
if(VehicleInfo[playerid][mod10]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod10]); }
if(VehicleInfo[playerid][mod11]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod11]); }
if(VehicleInfo[playerid][mod12]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod12]); }
if(VehicleInfo[playerid][mod13]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod13]); }
if(VehicleInfo[playerid][mod14]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod14]); }
if(VehicleInfo[playerid][mod15]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod15]); }
if(VehicleInfo[playerid][mod16]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod16]); }
if(VehicleInfo[playerid][mod17]!=0) { AddVehicleComponent(Vehicle[playerid],VehicleInfo[playerid][mod17]); }
if(VehicleInfo[playerid][colora]!=0 || VehicleInfo[playerid][colorb]!=0)
{
ChangeVehicleColor(Vehicle[playerid],VehicleInfo[playerid][colora],VehicleInfo[playerid][colorb]);
}
if(VehicleInfo[playerid][paintjob]!=0)
{
ChangeVehiclePaintjob(Vehicle[playerid],VehicleInfo[playerid][paintjob]);
}
new tmp[256]; tmp = dini_Get(file, "Plate");
Zespalnowane[playerid] = 1;
gPlayerHasCar[playerid] = 1;
VehOwned[Vehicle[playerid]] = 1;
OwnerID[Vehicle[playerid]] = playerid;
SetVehicleParamsForPlayer(Vehicle[playerid], playerid, 0, VehicleInfo[playerid][Locked]);
gVehLocked[Vehicle[playerid]] = VehicleInfo[playerid][Locked];
SetVehicleNumberPlate(Vehicle[playerid], tmp);
VehPlate[Vehicle[playerid]] = tmp;
LoadTrunk(playerid);
}
return 1;
}
public Save(playerid)
{
new file[256], name[24];
GetPlayerName(playerid, name, 24);
format(file,sizeof(file),"Cars/%s.ini",name);
if(dini_Exists(file))
{
dini_IntSet(file, "Model", GetVehicleModel(Vehicle[playerid]));
dini_IntSet(file, "Price", VehicleInfo[playerid][Price]);
dini_FloatSet(file, "X", VehicleInfo[playerid][CarX]);
dini_FloatSet(file, "Y", VehicleInfo[playerid][CarY]);
dini_FloatSet(file, "Z", VehicleInfo[playerid][CarZ]);
dini_FloatSet(file, "Rot", VehicleInfo[playerid][CarRot]);
dini_IntSet(file, "Locked", VehicleInfo[playerid][Locked]);
dini_Set(file, "Plate", VehPlate[Vehicle[playerid]]);
dini_IntSet(file, "mod1", VehicleInfo[playerid][mod1]);
dini_IntSet(file, "mod2", VehicleInfo[playerid][mod2]);
dini_IntSet(file, "mod3", VehicleInfo[playerid][mod3]);
dini_IntSet(file, "mod4", VehicleInfo[playerid][mod4]);
dini_IntSet(file, "mod5", VehicleInfo[playerid][mod5]);
dini_IntSet(file, "mod6", VehicleInfo[playerid][mod6]);
dini_IntSet(file, "mod7", VehicleInfo[playerid][mod7]);
dini_IntSet(file, "mod8", VehicleInfo[playerid][mod8]);
dini_IntSet(file, "mod9", VehicleInfo[playerid][mod9]);
dini_IntSet(file, "mod10", VehicleInfo[playerid][mod10]);
dini_IntSet(file, "mod11", VehicleInfo[playerid][mod11]);
dini_IntSet(file, "mod12", VehicleInfo[playerid][mod12]);
dini_IntSet(file, "mod13", VehicleInfo[playerid][mod13]);
dini_IntSet(file, "mod14", VehicleInfo[playerid][mod14]);
dini_IntSet(file, "mod15", VehicleInfo[playerid][mod15]);
dini_IntSet(file, "mod16", VehicleInfo[playerid][mod16]);
dini_IntSet(file, "mod17", VehicleInfo[playerid][mod17]);
dini_IntSet(file, "paintjob", VehicleInfo[playerid][paintjob]);
dini_IntSet(file, "color1", VehicleInfo[playerid][colora]);
dini_IntSet(file, "color2", VehicleInfo[playerid][colorb]);
SaveTrunk(playerid);
}
return 1;
}
public Save2(playerid)
{
new file[256], name[24];
GetPlayerName(playerid, name, 24);
format(file,sizeof(file),"Cars/%s.ini",name);
if(dini_Exists(file))
{
dini_IntSet(file, "Model", GetVehicleModel(Vehicle[playerid]));
dini_IntSet(file, "Price", VehicleInfo[playerid][Price]);
dini_IntSet(file, "Locked", VehicleInfo[playerid][Locked]);
dini_Set(file, "Plate", VehPlate[Vehicle[playerid]]);
dini_IntSet(file, "mod1", VehicleInfo[playerid][mod1]);
dini_IntSet(file, "mod2", VehicleInfo[playerid][mod2]);
dini_IntSet(file, "mod3", VehicleInfo[playerid][mod3]);
dini_IntSet(file, "mod4", VehicleInfo[playerid][mod4]);
dini_IntSet(file, "mod5", VehicleInfo[playerid][mod5]);
dini_IntSet(file, "mod6", VehicleInfo[playerid][mod6]);
dini_IntSet(file, "mod7", VehicleInfo[playerid][mod7]);
dini_IntSet(file, "mod8", VehicleInfo[playerid][mod8]);
dini_IntSet(file, "mod9", VehicleInfo[playerid][mod9]);
dini_IntSet(file, "mod10", VehicleInfo[playerid][mod10]);
dini_IntSet(file, "mod11", VehicleInfo[playerid][mod11]);
dini_IntSet(file, "mod12", VehicleInfo[playerid][mod12]);
dini_IntSet(file, "mod13", VehicleInfo[playerid][mod13]);
dini_IntSet(file, "mod14", VehicleInfo[playerid][mod14]);
dini_IntSet(file, "mod15", VehicleInfo[playerid][mod15]);
dini_IntSet(file, "mod16", VehicleInfo[playerid][mod16]);
dini_IntSet(file, "mod17", VehicleInfo[playerid][mod17]);
dini_IntSet(file, "paintjob", VehicleInfo[playerid][paintjob]);
dini_IntSet(file, "color1", VehicleInfo[playerid][colora]);
dini_IntSet(file, "color2", VehicleInfo[playerid][colorb]);
DestroyVehicle(Vehicle[playerid]);
SaveTrunk(playerid);
}
return 1;
}