Remove Admin Cars
#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


Messages In This Thread
Remove Admin Cars - by Blademaster680 - 07.10.2014, 10:34
Re: Remove Admin Cars - by MasonSFW - 07.10.2014, 12:26
Re: Remove Admin Cars - by Blademaster680 - 07.10.2014, 13:47
Re: Remove Admin Cars - by rodrijose2009 - 07.10.2014, 15:14
Re: Remove Admin Cars - by Blademaster680 - 07.10.2014, 19:53
Re: Remove Admin Cars - by Threshold - 08.10.2014, 01:24
Re: Remove Admin Cars - by Blademaster680 - 08.10.2014, 21:14
Re: Remove Admin Cars - by Threshold - 08.10.2014, 22:35
Re: Remove Admin Cars - by Blademaster680 - 13.10.2014, 19:45
Re: Remove Admin Cars - by Threshold - 13.10.2014, 22:43

Forum Jump:


Users browsing this thread: 1 Guest(s)