Trunk Coordinates
#1

How is it possible to make it so my /trunkdeposit command only works when a player is standing by a vehicles trunk?
Reply
#2

pawn Code:
if(IsPlayerInVehicle(playerid, caid))
        {
            SendClientMessage(playerid,0xFFFFFFFFF,"You're not in a trucker car!");
        }
Try This. You want to do this, when player is in a truck?
Reply
#3

Nope. I wanna be able to deposit my weapons into my cars boot but only want the command to work when a player is standing right behind the car by the boot/trunk.
Reply
#4

Hm, this might not be perfect, but let's use GetVehicleModelInfo.

pawn Code:
new
    Float:X,
    Float:Y,
    Float:Z;
GetVehicleModelInfo(model, VEHICLE_MODEL_INFO_WHEELSREAR, X, Y, Z);
//IsPlayerInRangeOfPoint(playerid, 3.0, X, Y, Z)
Additionally you could add some offset using sin/cos functions, so only when player stands behind the car he'll can access the trunk
Reply
#5

I have used MP2's function which is:

pawn Code:
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));
}
But I'm not sure what to do from here. Do I use IsPlayerInRangeOfPoint of GetPosBehindVehicle? Thanks.

I'm sorry there's loose indents in the code but I had to type it up on mobile cause no Internet access.
Reply
#6

Is anyone able to help me please?
Reply
#7

i made an example

pawn Code:
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;
}
Reply
#8

Hmm, that code just tells me I must be near a car even if I'm right by one
Reply
#9

my bad try increase from 1 to 20.0 in GetNearestVehicle function inside the command.
Reply
#10

That doesn't work. I managed to get it working but not exactly how I need it to. Example is shown here:
http://forum.sa-mp.com/showthread.ph...04#post2694404
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)