/car [MODEL NAME/ID] is not working :/ +REP
#1

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;
}
Reply
#2

Quote:
Originally Posted by YoussefHammad
Посмотреть сообщение
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;
}
You do not keep records to create a car you want to destroy it by thought.

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], Indextmp 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 
carcolour1colour2string[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:ZFloat:Angle,int1;    GetPlayerPos(playeridX,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(carX,Y,ZAnglecolour1colour2, -1); LinkVehicleToInterior(LVehicleID,int1);
        if (!
LVehicleID) return 0;
        
p_vehicles[playerid] = LVehicleID;
       
format(stringsizeof(string), "You have spawned a \"%s\" (Model:%d) colour (%d, %d)"VehicleName[car-400], carcolour1colour2);
        
PutPlayerInVehicle(playeridLVehicleID0);
        
VehicleInfo[LVehicleID][Temp] = 1;
        return 
SendClientMessage(playerid,-1string);
    }
    else
    {
          
SendClientMessage(playerid,-1,"You are already in a vehicle!");
    }
    return 
1;

Reply
#3

thanks very much it works now , +REPPED
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)