12.09.2013, 04:26
How is it possible to make it so my /trunkdeposit command only works when a player is standing by a vehicles trunk?
if(IsPlayerInVehicle(playerid, caid))
{
SendClientMessage(playerid,0xFFFFFFFFF,"You're not in a trucker car!");
}
new
Float:X,
Float:Y,
Float:Z;
GetVehicleModelInfo(model, VEHICLE_MODEL_INFO_WHEELSREAR, X, Y, Z);
//IsPlayerInRangeOfPoint(playerid, 3.0, X, Y, Z)
stock GetPosBehindVehicle (vehicleid, &Float:x, &Float:y, &Float:z, Float:offset=0.5)
{
new Float:vehicleSize[3], Float:vehiclePos[3];
GetVehiclePos(vehicleid, vehiclePos[0], vehiclePos[1], vehiclePos[2]);
GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_SIZE,vehicleSize[0],vehicleSize[1], vehicleSize[2]);
GetXYBehindVehicle(vehicleid, vehiclePos[0], vehiclePos[1], (vehicleSize[1]/2)+offset);
x = vehiclePos[0];
y = vehiclePos[1];
z = vehiclePos[2];
return 1;
}
GetXYBehindVehicle(vehicleid, &Float:q, &Float:w, Float:distance)
{
new Float:a;
GetVehiclePos(vehicleid, q, w, a);
GetVehicleZAngle(vehicleid, a);
q += (distance * -floatsin(-a, degrees));
w += (distance * -floatcos(-a, degrees));
}
stock GetPosBehindVehicle (vehicleid, &Float:x, &Float:y, &Float:z, Float:offset=0.5)
{
new Float:vehicleSize[3], Float:vehiclePos[3];
GetVehiclePos(vehicleid, vehiclePos[0], vehiclePos[1], vehiclePos[2]);
GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_SIZE,vehicleSize[0],vehicleSize[1], vehicleSize[2]);
GetXYBehindVehicle(vehicleid, vehiclePos[0], vehiclePos[1], (vehicleSize[1]/2)+offset);
x = vehiclePos[0];
y = vehiclePos[1];
z = vehiclePos[2];
return 1;
}
GetXYBehindVehicle(vehicleid, &Float:q, &Float:w, Float:distance)
{
new Float:a;
GetVehiclePos(vehicleid, q, w, a);
GetVehicleZAngle(vehicleid, a);
q += (distance * -floatsin(-a, degrees));
w += (distance * -floatcos(-a, degrees));
}
stock GetNearestVehicle(playerid, Float:dis) // some stock i have found around the forums
{
new Float:X, Float:Y, Float:Z;
if(GetPlayerPos(playerid, X, Y, Z))
{
new vehicleid = INVALID_VEHICLE_ID;
for(new v, Float:temp, Float:VX, Float:VY, Float:VZ; v != MAX_VEHICLES; v++)
{
if(GetVehiclePos(v, VX, VY, VZ))
{
VX -= X, VY -= Y, VZ -= Z;
temp = VX * VX + VY * VY + VZ * VZ;
if(temp < dis) dis = temp, vehicleid = v;
}
}
dis = floatpower(dis, 0.5);
return vehicleid;
}
return INVALID_VEHICLE_ID;
}
CMD:trunkdeposit(playerid, params[])
{
new Float:cPos[3], vID = GetNearestVehicle(playerid, 1);
if(vID == INVALID_VEHICLE_ID) return SendClientMessage(playerid, -1, "Error. you must be near a car."); // if the player wasnt near from any car
GetPosBehindVehicle(vID, cPos[0], cPos[1], cPos[2], 1.0); // getting the positions according to the stocks above ^
if(!IsPlayerInRangeOfPoint(playerid, 1.0, cPos[0], cPos[1], cPos[2])) return SendClientMessage(playerid, -1, "Error. you must be near the trunk of the car."); // if player wasnt behind car
// Other code here
return 1;
}