29.08.2015, 16:31
Quote:
when i do /car the previous car i spawned should be destroyed and the new one is spawned but the previous car doesnt disappear , any help ?
Код:
CMD:car(playerid,params[]) { if(!IsPlayerInAnyVehicle(playerid)) { new tmp[128], tmp2[128], tmp3[128], Index; tmp = strtok(params,Index), tmp2 = strtok(params,Index); tmp3 = strtok(params,Index); if(isnull(tmp)) return SendClientMessage(playerid, -1, "USAGE: /car [Modelid/Name] [colour1] [colour2]"); new car, colour1, colour2, string[128]; if(!IsNumeric(tmp)) car = GetVehicleModelIDFromName(tmp); else car = strval(tmp); if(car < 400 || car > 611) return SendClientMessage(playerid, -1, "ERROR: Invalid Vehicle Model"); if(isnull(tmp2)) colour1 = random(126); else colour1 = strval(tmp2); if(isnull(tmp3)) colour2 = random(126); else colour2 = strval(tmp3); new LVehicleID,Float:X,Float:Y,Float:Z, Float:Angle,int1; GetPlayerPos(playerid, X,Y,Z); GetPlayerFacingAngle(playerid,Angle); int1 = GetPlayerInterior(playerid); DestroyVehicle(LVehicleID); LVehicleID = CreateVehicle(car, X,Y,Z, Angle, colour1, colour2, -1); LinkVehicleToInterior(LVehicleID,int1); format(string, sizeof(string), "You have spawned a \"%s\" (Model:%d) colour (%d, %d)", VehicleName[car-400], car, colour1, colour2); PutPlayerInVehicle(playerid, LVehicleID, 0); VehicleInfo[LVehicleID][Temp] = 1; return SendClientMessage(playerid,-1, string); } else { SendClientMessage(playerid,-1,"You are already in a vehicle!"); } return 1; } |
Create an array, and keep it by vehicles for each player, and before you create a new delete it
Example:
PHP код:
static p_vehicles[MAX_PLAYERS] = {INVALID_VEHICLE_ID, ...};
CMD:car(playerid,params[])
{
if(!IsPlayerInAnyVehicle(playerid))
{
new tmp[128], tmp2[128], tmp3[128], Index; tmp = strtok(params,Index), tmp2 = strtok(params,Index); tmp3 = strtok(params,Index);
if(isnull(tmp)) return SendClientMessage(playerid, -1, "USAGE: /car [Modelid/Name] [colour1] [colour2]");
new car, colour1, colour2, string[128];
if(!IsNumeric(tmp)) car = GetVehicleModelIDFromName(tmp); else car = strval(tmp);
if(car < 400 || car > 611) return SendClientMessage(playerid, -1, "ERROR: Invalid Vehicle Model");
if(isnull(tmp2)) colour1 = random(126); else colour1 = strval(tmp2);
if(isnull(tmp3)) colour2 = random(126); else colour2 = strval(tmp3);
new LVehicleID,Float:X,Float:Y,Float:Z, Float:Angle,int1; GetPlayerPos(playerid, X,Y,Z); GetPlayerFacingAngle(playerid,Angle); int1 = GetPlayerInterior(playerid);
if (p_vehicles[playerid] != INVALID_VEHICLE_ID) {
DestroyVehicle(p_vehicles[playerid]);
p_vehicles[playerid] = INVALID_VEHICLE_ID;
}
LVehicleID = CreateVehicle(car, X,Y,Z, Angle, colour1, colour2, -1); LinkVehicleToInterior(LVehicleID,int1);
if (!LVehicleID) return 0;
p_vehicles[playerid] = LVehicleID;
format(string, sizeof(string), "You have spawned a \"%s\" (Model:%d) colour (%d, %d)", VehicleName[car-400], car, colour1, colour2);
PutPlayerInVehicle(playerid, LVehicleID, 0);
VehicleInfo[LVehicleID][Temp] = 1;
return SendClientMessage(playerid,-1, string);
}
else
{
SendClientMessage(playerid,-1,"You are already in a vehicle!");
}
return 1;
}