13.10.2014, 22:43
(
Последний раз редактировалось Threshold; 15.10.2014 в 22:36.
)
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;
}
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.");
EDIT: If you want to be able to spawn any more than 10 cars, you will need to change the 'MAX_ADMIN_CARS' macro.