30.04.2012, 05:35
I'm trying to make a trunk and hood command, that works with the closest vehicle, but if a player is in a certain range of two vehicles then it sends a message saying so, to prevent confusion between close vehicles.
Here's the code:
The problem is, even if I'm only close to one vehicle, it still says I'm to close to two vehicles.
Here's the code:
pawn Код:
if(strcmp(cmd, "/trunk", true) == 0)
{
new Float:hX, Float:hY, Float:hZ, vehicleid = INVALID_VEHICLE_ID, carcount = 0;
for(new i = 0; i < MAX_VEHICLES; i++)
{
GetVehiclePos(i, hX, hY, hZ);
if(IsPlayerInRangeOfPoint(playerid, 4, hX, hY, hZ))
{
vehicleid = i;
carcount++;
}
}
if(IsABike(vehicleid) || IsABoat(vehicleid) || IsAPlane(vehicleid) || IsAHelicopter(vehicleid) || IsATrain(vehicleid)) return 1;
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT && vehicleid != INVALID_VEHICLE_ID && carcount == 1)
{
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet , boot, objective);
if(doors) return SendClientMessage(playerid, COLOR_GRAD1, " This vehicle is locked.");
if(boot != 1)
{
boot = 1;
format(string, sizeof(string), "* %s opens the vehicles trunk.", PlayerName(playerid));
SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, 1, objective);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}
else
{
boot = 0;
format(string, sizeof(string), "* %s closes the vehicles trunk.", PlayerName(playerid));
SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, 0, objective);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_GRAD2, " You are not near a vehilce with a trunk, or you are to close to two vehicles.");
}
return 1;
}