Despawn a car by ID.
#1

I'm trying to make a command so when you do /vrespawn [car id] it despawns the admin car.
To spawn an admin car you use /spawncar. For some reason it only stocks one car in to the
variable and I can only despawn the first car I spawned with that command. I want to make it
so when you type /vrespawn it respawns what ever admin car you spawned by ID.

/spawncar command
Код:
CMD:spawncar(playerid, params[]) 
{
    if(playerVariables[playerid][pAdminLevel] >= 1) 
    {
        if(!isnull(params)) 
        {

			new
				carid = strval(params),
				Float: carSpawnPos[4], // 3 for the usual dimensions, +1 for the rotation/angle.
				messageString[64];
				
			new message2[64];

			if(carid < 400 || carid > 611)
				return SendClientMessage(playerid, COLOR_WHITE, "Valid car IDs start at 400, and end at 611.");

			if(systemVariables[vehicleCounts][0] + systemVariables[vehicleCounts][1] + systemVariables[vehicleCounts][2] < MAX_VEHICLES) {
				GetPlayerPos(playerid, carSpawnPos[0], carSpawnPos[1], carSpawnPos[2]);
				GetPlayerFacingAngle(playerid, carSpawnPos[3]);

				AdminSpawnedVehicles[vehCount] = CreateVehicle(carid, carSpawnPos[0], carSpawnPos[1], carSpawnPos[2], carSpawnPos[3], -1, -1, -1);
				systemVariables[vehicleCounts][2]++;
				SetVehicleNumberPlate(AdminSpawnedVehicles[vehCount], "ADMCAR");

				LinkVehicleToInterior(AdminSpawnedVehicles[vehCount], GetPlayerInterior(playerid));
				SetVehicleVirtualWorld(AdminSpawnedVehicles[vehCount], GetPlayerVirtualWorld(playerid));

				PutPlayerInVehicle(playerid, AdminSpawnedVehicles[vehCount], 0);

				switch(carid) {
					case 427, 428, 432, 601, 528: SetVehicleHealth(AdminSpawnedVehicles[vehCount], 5000.0);
				}

				format(messageString, sizeof(messageString), "You have spawned a %s (vehicle ID %d).", VehicleNames[carid - 400], AdminSpawnedVehicles[vehCount]);
				SendClientMessage(playerid, COLOR_WHITE, messageString);				
				
				format(message2, sizeof(message2), "AdmCmd: %s has used /spawncar.",GetName(playerid));
				
				submitToHelpersAndAdmins(message2, COLOR_HOTORANGE);


				vehCount++;
			}
			else 
			{
				SendClientMessage(playerid, COLOR_GREY, "(error) 01x08");
				printf("ERROR: Vehicle limit reached (MODEL %d, MAXIMUM %d, TYPE ADMIN) [01x08]", carid, MAX_VEHICLES);
			}
        }
        else {
            return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/spawncar [vehicleid]");
        }
    }
	else return SendClientMessage(playerid, COLOR_WHITE, AdminOnly);
	return 1;
}
/vrespawn command
Код:
CMD:vrespawn(playerid, params[]) {
	new carid2, deez22[64];
	if(sscanf(params, "d", carid2)) return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/vrespawn [car id]");
    if(playerVariables[playerid][pAdminLevel] >= 1) 
	{
        for(new i = 0; i < MAX_VEHICLES; i++)
        {
			new carid3 = AdminSpawnedVehicles[i];
			if(carid2 == carid3)
			{
				format(szMessage, sizeof(szMessage), "You have successfully despawned vehicle %d.", AdminSpawnedVehicles[i]);
				SendClientMessage(playerid, COLOR_WHITE, szMessage);
				DestroyVehicle(carid2);
				AdminSpawnedVehicles[i]--;
				systemVariables[vehicleCounts][2]--;
				
				format(deez22, sizeof(deez22), "AdmCmd: %s has used /spawncar.",GetName(playerid));
				
				submitToHelpersAndAdmins(deez22, COLOR_HOTORANGE);
				return 1;
			}
			else return SendClientMessage(playerid, COLOR_GREY, "The car ID you have entered is invalid.");
		}
    }
	else return SendClientMessage(playerid, COLOR_WHITE, AdminOnly);
	return 1;
}
Reply
#2

Use y_iterate.
https://sampforum.blast.hk/showthread.php?tid=571159

You basically can make a list with it where you can add or remove stuff to it.
Reply
#3

Quote:
Originally Posted by Ahmad45123
Посмотреть сообщение
Use y_iterate.
https://sampforum.blast.hk/showthread.php?tid=571159

You basically can make a list with it where you can add or remove stuff to it.
Would you mind explaining how? I have no idea how this works.
Reply
#4

Quote:
Originally Posted by danielpalade
Посмотреть сообщение
Would you mind explaining how? I have no idea how this works.
Am on mobile do that's hard..

First do this to create the iterator:
PHP код:
new
    
Iterator:SpawnedVehicles<MAX_VEHICLES>;
Iter_Init(SpawnedVehicles); //this in ongamemodeinit. 
After that.. Use Iter_Add to add and Iter_Remove to remove and Iter_Contains.

Again, i am on mobile so i can't provide a full working example.
Reply
#5

Quote:
Originally Posted by Ahmad45123
Посмотреть сообщение
Am on mobile do that's hard..

First do this to create the iterator:
PHP код:
new
    
Iterator:SpawnedVehicles<MAX_VEHICLES>;
Iter_Init(SpawnedVehicles); //this in ongamemodeinit. 
After that.. Use Iter_Add to add and Iter_Remove to remove and Iter_Contains.

Again, i am on mobile so i can't provide a full working example.
Its oke, just drop by and give me the full example once you get on your pc. Thanks.
Reply
#6

There you go:
PHP код:
#include <YSI_Data\y_iterate> //Include the library.

new Iterator:AdminSpawnedVehicles<MAX_VEHICLES>; //Create the iterator.

CMD:spawncar(playeridparams[]) 
{
    if(
playerVariables[playerid][pAdminLevel] >= 1
    {
        if(!
isnull(params)) 
        {
            new
                
carid strval(params),
                
FloatcarSpawnPos[4], // 3 for the usual dimensions, +1 for the rotation/angle.
                
messageString[64];
                
            new 
message2[64];

            if(
carid 400 || carid 611)
                return 
SendClientMessage(playeridCOLOR_WHITE"Valid car IDs start at 400, and end at 611.");

            if(
systemVariables[vehicleCounts][0] + systemVariables[vehicleCounts][1] + systemVariables[vehicleCounts][2] < MAX_VEHICLES) {
                
GetPlayerPos(playeridcarSpawnPos[0], carSpawnPos[1], carSpawnPos[2]);
                
GetPlayerFacingAngle(playeridcarSpawnPos[3]);

                new 
vehid CreateVehicle(caridcarSpawnPos[0], carSpawnPos[1], carSpawnPos[2], carSpawnPos[3], -1, -1, -1); //Create the car and save its ID.
                
Iter_Add(AdminSpawnedVehiclesvehid); //Store the ID in the iterator.
                
SetVehicleNumberPlate(vehid"ADMCAR");

                
LinkVehicleToInterior(vehidGetPlayerInterior(playerid));
                
SetVehicleVirtualWorld(vehidGetPlayerVirtualWorld(playerid));

                
PutPlayerInVehicle(playeridvehid0);

                switch(
carid) {
                    case 
427428432601528SetVehicleHealth(vehid5000.0);
                }

                
format(messageStringsizeof(messageString), "You have spawned a %s (vehicle ID %d)."VehicleNames[carid 400], AdminSpawnedVehicles[vehCount]);
                
SendClientMessage(playeridCOLOR_WHITEmessageString);                
                
                
format(message2sizeof(message2), "AdmCmd: %s has used /spawncar.",GetName(playerid));
                
                
submitToHelpersAndAdmins(message2COLOR_HOTORANGE);

                
vehCount++;
            }
            else 
            {
                
SendClientMessage(playeridCOLOR_GREY"(error) 01x08");
                
printf("ERROR: Vehicle limit reached (MODEL %d, MAXIMUM %d, TYPE ADMIN) [01x08]"caridMAX_VEHICLES);
            }
        }
        else {
            return 
SendClientMessage(playeridCOLOR_GREYSYNTAX_MESSAGE"/spawncar [vehicleid]");
        }
    }
    else return 
SendClientMessage(playeridCOLOR_WHITEAdminOnly);
    return 
1;
}

CMD:vrespawn(playeridparams[]) {
    new 
carid2deez22[64];
    if(
sscanf(params"d"carid2)) return SendClientMessage(playeridCOLOR_GREYSYNTAX_MESSAGE"/vrespawn [car id]");
    if(
playerVariables[playerid][pAdminLevel] >= 1
    {
        if(
Iter_Contains(AdminSpawnedVehiclescarid2)) //If the ID is in the list.
        
{
            
format(szMessagesizeof(szMessage), "You have successfully despawned vehicle %d."AdminSpawnedVehicles[i]);
            
SendClientMessage(playeridCOLOR_WHITEszMessage);
            
DestroyVehicle(carid2);
            
AdminSpawnedVehicles[i]--;
            
systemVariables[vehicleCounts][2]--;
            
            
format(deez22sizeof(deez22), "AdmCmd: %s has used /spawncar.",GetName(playerid));
            
            
submitToHelpersAndAdmins(deez22COLOR_HOTORANGE);
            
            
Iter_Remove(AdminSpawnedVehiclescarid2); //Remove the ID from list once the car is destroyed.
            
            
return 1;
        }
        else return 
SendClientMessage(playeridCOLOR_GREY"The car ID you have entered is invalid.");
    }
    else return 
SendClientMessage(playeridCOLOR_WHITEAdminOnly);
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)