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


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)