Remove Admin Cars
#1

I am trying to make it so if you type, /destoryveh it will remove all the spawned admin cars on the server. Currently it is only destroying the last spawned admin car, if they are higher than level 8 admin...
Please help me.
Need all the admin cars to be removed from the server.

Thanks

Code:

Код:
new AdminCars[MAX_PLAYERS] = 0;
new AdminCars2[10], carid2;

CMD:veh(playerid, params[])
{
	if(pInfo[playerid][pAdminLevel] < 3) return SendClientMessage(playerid, COLOR_GREY, "You are not authorised to use that command.");
	if(GetPVarInt(playerid, "AdminDuty") == 1 || pInfo[playerid][pAdminLevel] == 8)
	{
		new carid, col1, col2;
		if(sscanf(params, "iii", carid, col1, col2)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /veh [ID] [COL1] [COL2]");
		if(carid2 > sizeof(AdminCars2)-1) return SendClientMessage(playerid, COLOR_GREY, "You must use /vehdestroy because is now maximum Admin cars");
		if(carid < 400 || carid > 611) return SendClientMessage(playerid, COLOR_GREY, "Vehicle number can't be below 400 or above 611!");
		if(col1 < 0 || col1 > 256) return SendClientMessage(playerid, COLOR_GREY, "Color number can't be below 0 or above 256!");
		if(pInfo[playerid][pAdminLevel] == 8)
		{
			new Float:X,Float:Y,Float:Z;
			GetPlayerPos(playerid, X,Y,Z);
			new vehicleid;
			vehicleid = AdminCars2[carid2] = AddStaticVehicleEx(carid, X+2,Y+2,Z+1, 0.0, col1, col2, 60000);
			gVehicleFuel[vehicleid] = 100;
			new string[128];
			format(string, sizeof(string), "Vehicle %d spawned.", AdminCars2[carid2]);
			SendClientMessage(playerid, COLOR_GREY, string);
			return 1;
		}
		else if(AdminCars[playerid] == 0)
		{
			new Float:X,Float:Y,Float:Z;
			GetPlayerPos(playerid, X,Y,Z);
			new vehicleid;
			vehicleid =	AdminCars[playerid]	= AddStaticVehicleEx(carid, X+2,Y+2,Z+1, 0.0, col1, col2, 60000);
			AdminCars2[carid2] = carid2+1;
			gVehicleFuel[vehicleid] = 100;
		}
		else return SendClientMessage(playerid, COLOR_GREY, "You already have a spawned vehicle.");
	}
	else return SendClientMessage(playerid, COLOR_GREY, "You need to be on admin duty to use the commands.");
	return 1;
}

CMD:vehdestroy(playerid, params[])
{
	if(pInfo[playerid][pAdminLevel] <= 4) return SendClientMessage(playerid, COLOR_GREY, "You are not authorised to use that command.");
	if(GetPVarInt(playerid, "AdminDuty") == 0 && pInfo[playerid][pAdminLevel] < 8) return SendClientMessage(playerid, COLOR_GREY, "You need to be on admin duty to use that command.");
    for(new i = 0; i < sizeof(AdminCars2); i++)
	{
        if(AdminCars2[i] > 0)
        {
            DestroyVehicle(AdminCars2[i]);
            AdminCars2[i] -= 1;
        }
	}
	for(new i = 0; i < sizeof(AdminCars); i++)
	{
		if(AdminCars[i] > 0)
        {
            DestroyVehicle(AdminCars2[i]);
            AdminCars[i] -= 1;
        }
	}
    carid2 = 0;
	SendClientMessage(playerid, COLOR_GREY, "All admin cars have been removed.");
    return 1;
}
Reply
#2

pawn Код:
CMD:vehdestroy(playerid, params[])
{
    if(pInfo[playerid][pAdminLevel] <= 4) return SendClientMessage(playerid, COLOR_GREY, "You are not authorised to use that command.");
    if(GetPVarInt(playerid, "AdminDuty") == 0 && pInfo[playerid][pAdminLevel] < 8) return SendClientMessage(playerid, COLOR_GREY, "You need to be on admin duty to use that command.");
    for(new i = 0; i < MAX_VEHICLES; ++i)
    {
        if(AdminCars2[i] > 0)
        {
            DestroyVehicle(AdminCars2[i]);
            AdminCars2[i] -= 1;
        }
    }
    for(new i = 0; i < MAX_VEHICLES; ++i)
    {
        if(AdminCars[i] > 0)
        {
            DestroyVehicle(AdminCars2[i]);
            AdminCars[i] -= 1;
        }
    }
    carid2 = 0;
    SendClientMessage(playerid, COLOR_GREY, "All admin cars have been removed.");
    return 1;
}
Reply
#3

Nope still only removing the last spawned vehicle... I dont understand this... Its almost like they replacing each other in the variable when I spawn them
Reply
#4

The red is the error
Wrong

Код:
CMD:vehdestroy(playerid, params[])
{
	if(pInfo[playerid][pAdminLevel] <= 4) return SendClientMessage(playerid, COLOR_GREY, "You are not authorised to use that command.");
	if(GetPVarInt(playerid, "AdminDuty") == 0 && pInfo[playerid][pAdminLevel] < 8) return SendClientMessage(playerid, COLOR_GREY, "You need to be on admin duty to use that command.");
    for(new i = 0; i < sizeof(AdminCars2); i++)
	{
        if(AdminCars2[i] > 0)
        {
            DestroyVehicle(AdminCars2[i]);
            AdminCars2[i] -= 1;
        }
	}
	for(new i = 0; i < sizeof(AdminCars); i++)
	{
		if(AdminCars[i] > 0)
        {
            DestroyVehicle(AdminCars2[i]);
            AdminCars[i] -= 1;
        }
	}
    carid2 = 0;
	SendClientMessage(playerid, COLOR_GREY, "All admin cars have been removed.");
    return 1;
}
Right

Код:
CMD:vehdestroy(playerid, params[])
{
	if(pInfo[playerid][pAdminLevel] <= 4) return SendClientMessage(playerid, COLOR_GREY, "You are not authorised to use that command.");
	if(GetPVarInt(playerid, "AdminDuty") == 0 && pInfo[playerid][pAdminLevel] < 8) return SendClientMessage(playerid, COLOR_GREY, "You need to be on admin duty to use that command.");
    for(new i = 0; i < sizeof(AdminCars2); i++)
	{
        if(AdminCars2[i] > 0)
        {
            DestroyVehicle(AdminCars2[i]);
            AdminCars2[i] -= 1;
        }
	}
	for(new i = 0; i < sizeof(AdminCars); i++)
	{
		if(AdminCars[i] > 0)
        {
            DestroyVehicle(AdminCars[i]);
            AdminCars[i] -= 1;
        }
	}
    carid2 = 0;
	SendClientMessage(playerid, COLOR_GREY, "All admin cars have been removed.");
    return 1;
}
Reply
#5

Ok well it is removing the cars, but for some reason I have to type the command for each vehicle...
Reply
#6

Okay, so I've modified the script a little bit.
At the top of your script, put this:
pawn Код:
#define MAX_ADMIN_CARS 10
new AdminCars[MAX_PLAYERS], carcount;
Under OnGameModeInit, add this:
pawn Код:
carcount = 0;
Under OnPlayerDisconnect:
pawn Код:
if(AdminCars[playerid] != INVALID_VEHICLE_ID)
    {
        DestroyVehicle(AdminCars[playerid]);
        AdminCars[playerid] = INVALID_VEHICLE_ID;
        carcount--;
    }
Then you have the two commands:
pawn Код:
CMD:veh(playerid, params[])
{
    if(pInfo[playerid][pAdminLevel] < 3) return SendClientMessage(playerid, COLOR_GREY, "You are not authorised to use that command.");
    if(!GetPVarInt(playerid, "AdminDuty") && pInfo[playerid][pAdminLevel] < 8) return SendClientMessage(playerid, COLOR_GREY, "You need to be on admin duty to use the commands.");
    new carid, col1, col2;
    if(sscanf(params, "iI(0)I(0)", carid, col1, col2)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /veh [ID] [COL1] [COL2]");
    if(carcount >= MAX_ADMIN_CARS) return SendClientMessage(playerid, COLOR_GREY, "You must use /vehdestroy because you have reached the maximum Admin cars");
    if(!(400 <= carid <= 611)) return SendClientMessage(playerid, COLOR_GREY, "Vehicle number can't be below 400 or above 611!");
    if(!((0 <= col1 <= 256) && (0 <= col2 <= 256))) return SendClientMessage(playerid, COLOR_GREY, "Color number can't be below 0 or above 256!");
    if(AdminCars[playerid] != INVALID_VEHICLE_ID && pInfo[playerid][pAdminLevel] < 8) return SendClientMessage(playerid, COLOR_GREY, "You already have a spawned vehicle.");
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    AdminCars[playerid] = CreateVehicle(carid, X + 2, Y + 2, Z + 1, 0.0, col1, col2, 60000);
    gVehicleFuel[AdminCars[playerid]] = 100;
    carcount++;
    new string[50];
    format(string, sizeof(string), "Vehicle %d spawned. Total of %d cars spawned.", AdminCars[playerid], carcount);
    SendClientMessage(playerid, COLOR_GREY, string);
    return 1;
}

CMD:vehdestroy(playerid, params[])
{
    if(pInfo[playerid][pAdminLevel] < 5) return SendClientMessage(playerid, COLOR_GREY, "You are not authorised to use that command.");
    if(!GetPVarInt(playerid, "AdminDuty") && pInfo[playerid][pAdminLevel] < 8) return SendClientMessage(playerid, COLOR_GREY, "You need to be on admin duty to use that command.");
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(AdminCars[i] == INVALID_VEHICLE_ID) continue;
        DestroyVehicle(AdminCars[i]);
        AdminCars[i] = INVALID_VEHICLE_ID;
        carcount--;
    }
    SendClientMessage(playerid, COLOR_GREY, "All admin cars have been removed.");
    return 1;
}
You've seem to got AdminCars2 and AdminCars confused, and you're not using them in the proper fashion. This fixes that. If this is quite confusing to you, here is the script as a whole:
pawn Код:
#define MAX_ADMIN_CARS 10
new AdminCars[MAX_PLAYERS], carcount;

public OnGameModeInit()
{
    carcount = 0;
    //Rest of the code
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(AdminCars[playerid] != INVALID_VEHICLE_ID)
    {
        DestroyVehicle(AdminCars[playerid]);
        AdminCars[playerid] = INVALID_VEHICLE_ID;
        carcount--;
    }
    //Rest of the code
    return 1;
}

CMD:veh(playerid, params[])
{
    if(pInfo[playerid][pAdminLevel] < 3) return SendClientMessage(playerid, COLOR_GREY, "You are not authorised to use that command.");
    if(!GetPVarInt(playerid, "AdminDuty") && pInfo[playerid][pAdminLevel] < 8) return SendClientMessage(playerid, COLOR_GREY, "You need to be on admin duty to use the commands.");
    new carid, col1, col2;
    if(sscanf(params, "iI(0)I(0)", carid, col1, col2)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /veh [ID] [COL1] [COL2]");
    if(carcount >= MAX_ADMIN_CARS) return SendClientMessage(playerid, COLOR_GREY, "You must use /vehdestroy because you have reached the maximum Admin cars");
    if(!(400 <= carid <= 611)) return SendClientMessage(playerid, COLOR_GREY, "Vehicle number can't be below 400 or above 611!");
    if(!((0 <= col1 <= 256) && (0 <= col2 <= 256))) return SendClientMessage(playerid, COLOR_GREY, "Color number can't be below 0 or above 256!");
    if(AdminCars[playerid] != INVALID_VEHICLE_ID && pInfo[playerid][pAdminLevel] < 8) return SendClientMessage(playerid, COLOR_GREY, "You already have a spawned vehicle.");
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    AdminCars[playerid] = CreateVehicle(carid, X + 2, Y + 2, Z + 1, 0.0, col1, col2, 60000);
    gVehicleFuel[AdminCars[playerid]] = 100;
    carcount++;
    new string[50];
    format(string, sizeof(string), "Vehicle %d spawned. Total of %d cars spawned.", AdminCars[playerid], carcount);
    SendClientMessage(playerid, COLOR_GREY, string);
    return 1;
}

CMD:vehdestroy(playerid, params[])
{
    if(pInfo[playerid][pAdminLevel] < 5) return SendClientMessage(playerid, COLOR_GREY, "You are not authorised to use that command.");
    if(!GetPVarInt(playerid, "AdminDuty") && pInfo[playerid][pAdminLevel] < 8) return SendClientMessage(playerid, COLOR_GREY, "You need to be on admin duty to use that command.");
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(AdminCars[i] == INVALID_VEHICLE_ID) continue;
        DestroyVehicle(AdminCars[i]);
        AdminCars[i] = INVALID_VEHICLE_ID;
        carcount--
    }
    SendClientMessage(playerid, COLOR_GREY, "All admin cars have been removed.");
    return 1;
}
EDIT: I decided that AdminCars2 is unnecessary and doesn't really hold any value in this code, so I removed it.
Reply
#7

Ok cool so that works. Thanks . But there is a problem I still have. If you admin level 8 you can spawn 10 cars, yet it only removes the last one... Almost like when you spawn a new car, it replaces the variable of the other one and sees it that there is still only one car...

Thanks
Reply
#8

That's exactly what it does. Do you want level 8 admins to be able to spawn 10 cars?
Reply
#9

Yeah they suppose to be able to spawn unlimited amount of cars, but lower than level 8 cant... and then it should loop though all the admin vehicles for everyone and then remove them all.
The reason I want this is because level 8 is the max level for the admins, and there will only be 2 level 8 admins...
But we want to host events and spawn vehicles for the participants in the event... Know what I mean?
Reply
#10

pawn Код:
#define MAX_ADMIN_CARS 10
new AdminCars[MAX_ADMIN_CARS][2], carcount;

public OnGameModeInit()
{
    carcount = 0;
    //Rest of the code
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    for(new i = 0; i < MAX_ADMIN_CARS; i++)
    {
        if(AdminCars[i][1] != playerid) continue;
        if(AdminCars[i][0] != INVALID_VEHICLE_ID) DestroyVehicle(AdminCars[i][0]);
        AdminCars[i][0] = INVALID_VEHICLE_ID;
        AdminCars[i][1] = INVALID_PLAYER_ID;
        carcount--;
    }
    //Rest of the code
    return 1;
}

CMD:veh(playerid, params[])
{
    if(pInfo[playerid][pAdminLevel] < 3) return SendClientMessage(playerid, COLOR_GREY, "You are not authorised to use that command.");
    if(!GetPVarInt(playerid, "AdminDuty") && pInfo[playerid][pAdminLevel] < 8) return SendClientMessage(playerid, COLOR_GREY, "You need to be on admin duty to use the commands.");
    new carid, col1, col2;
    if(sscanf(params, "iI(0)I(0)", carid, col1, col2)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /veh [ID] [COL1] [COL2]");
    if(!(400 <= carid <= 611)) return SendClientMessage(playerid, COLOR_GREY, "Vehicle number can't be below 400 or above 611!");
    if(!((0 <= col1 <= 256) && (0 <= col2 <= 256))) return SendClientMessage(playerid, COLOR_GREY, "Color number can't be below 0 or above 256!");
    new free = -1;
    for(new i = 0; i < MAX_ADMIN_CARS; i++)
    {
        if(AdminCars[i][0] != INVALID_VEHICLE_ID) continue;
        if((AdminCars[i][1] == playerid) && (pInfo[playerid][pAdminLevel] < 8))
        {
            free = -1;
            break;
        }
        free = i;
    }
    if(free == -1) return SendClientMessage(playerid, COLOR_GREY, "You must use /vehdestroy because you have reached the maximum Admin cars.");
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    AdminCars[free][0] = CreateVehicle(carid, X + 2, Y + 2, Z + 1, 0.0, col1, col2, 60000);
    AdminCars[free][1] = playerid;
    gVehicleFuel[AdminCars[free][0]] = 100;
    carcount++;
    new string[50];
    format(string, sizeof(string), "Vehicle %d spawned. Total of %d cars spawned.", AdminCars[free][0], carcount);
    SendClientMessage(playerid, COLOR_GREY, string);
    return 1;
}

CMD:vehdestroy(playerid, params[])
{
    if(pInfo[playerid][pAdminLevel] < 5) return SendClientMessage(playerid, COLOR_GREY, "You are not authorised to use that command.");
    if(!GetPVarInt(playerid, "AdminDuty") && pInfo[playerid][pAdminLevel] < 8) return SendClientMessage(playerid, COLOR_GREY, "You need to be on admin duty to use that command.");
    for(new i = 0; i < MAX_ADMIN_CARS; i++)
    {
        if(AdminCars[i][0] == INVALID_VEHICLE_ID) continue;
        DestroyVehicle(AdminCars[i][0]);
        AdminCars[i][0] = INVALID_VEHICLE_ID;
        AdminCars[i][1] = INVALID_PLAYER_ID;
        carcount--;
    }
    SendClientMessage(playerid, COLOR_GREY, "All admin cars have been removed.");
    return 1;
}
What I have done is turned AdminCars into a 3 dimensional array which now has '2'... elements if you will.
Element 0 stores the vehicle ID of the car created (AdminCars[vehiclenumber][0]), Element 1 stores the player ID of the player that spawned it (AdminCars[vehiclenumber][1]).

So if you want to send a message to the person that spawned vehicle number 5 for example, you would do:
pawn Код:
SendClientMessage(AdminCars[4][1], -1, "This is a message for you.");
You use '4' because arrays start at 0, not 1. So if you were to send a message to any number, you would have to use the number 1 less than that.

EDIT: If you want to be able to spawn any more than 10 cars, you will need to change the 'MAX_ADMIN_CARS' macro.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)