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;
}
for(new i = 0; i < MAX_VEHICLES; i++) { vehicleid = INVALID_VEHICLE_ID; GetVehiclePos(i, hX, hY, hZ); if(IsPlayerInRangeOfPoint(playerid, 4, hX, hY, hZ)) { vehicleid = i; //carcount++; (God knows what this was doing) return vehicleid; } return vehicleid; }
Wouldn't be better to use a function that detects the nearest car?
|
stock CheckPlayerDistanceToVehicle(Float:radi, playerid, vehicleid) { if(IsPlayerConnected(playerid)) { new Float:PX1,Float:PY1,Float:PZ1,Float:X1,Float:Y1,Float:Z1; GetPlayerPos(playerid,PX1,PY1,PZ1); GetVehiclePos(vehicleid, X1,Y1,Z1); new Float:Distance = (X1-PX1)*(X1-PX1)+(Y1-PY1)*(Y1-PY1)+(Z1-PZ1)*(Z1-PZ1); if(Distance <= radi*radi) { return 1; } } return 0; }