Trunk position
#1

So i don't know what the heck the problem is, this function should get trunk possition from burrito, id 482, but it doesnt, it returns me You're not behind vehicles trunk.

pawn Код:
if(newkeys & 6) // KEY LMB
    {
        if(SvercaMaterijale[playerid] == 2)
        {
            new Float:Poz[3];
            GetPosBehindVehicle(482, Poz[0], Poz[1], Poz[2]);
            if(PI[playerid][Clan] == 7)
            {
                if(IsPlayerInRangeOfPoint(playerid, 2.0, Poz[0], Poz[1], Poz[2]))
                {
                    DisablePlayerCheckpoint(playerid);
                    SvercaMaterijale[playerid] = 3;
                    SetPlayerCheckpoint(playerid, 1263.2574,-2029.8651,59.3268, 3.0);
                    if(IsPlayerAttachedObjectSlotUsed(playerid, 2)) RemovePlayerAttachedObject(playerid, 2);
                    SetPlayerSpecialAction(playerid, SPECIAL_ACTION_NONE);
                }
                else return SCM(playerid, GREY, "You're not behind vehicles trunk.");
            }
        }
    }
pawn Код:
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));
}
Reply
#2

Does anyone know, it's kinda urgent ?
Reply
#3

pawn Код:
GetPosBehindVehicle(482, Poz[0], Poz[1], Poz[2]);
'482' is the vehicle model ID... not the vehicle id. There is a difference.

What you should be doing is replacing the '482' with the vehicle ID of the closest vehicle to the player.
Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
pawn Код:
// Usage: GetClosestVehicle(playerid)
stock GetClosestVehicle(playerid, & Float: distance = Float: 0x7F800000) {
    new
        i = GetPlayerVehicleID(playerid)
    ;
    if(i) {
        distance = 0.0;
        return i;
    }
    new
        Float: X,
        Float: Y,
        Float: Z
    ;
    if(GetPlayerPos(playerid, X, Y, Z)) {
        new
            Float: dis,
            closest = INVALID_VEHICLE_ID
        ;
        while(i != MAX_VEHICLES) {
            if(0.0 < (dis = GetVehicleDistanceFromPoint(++i, X, Y, Z)) < distance) {
                distance = dis;
                closest = i;
            }
        }
        return closest;
    }
    return INVALID_VEHICLE_ID;
}
After adding that, your code would be:
pawn Код:
if(newkeys & 6) // KEY LMB
    {
        if(SvercaMaterijale[playerid] == 2)
        {
            new Float:Poz[3];
            GetPosBehindVehicle(GetClosestVehicle(playerid), Poz[0], Poz[1], Poz[2]);
            if(PI[playerid][Clan] == 7)
            {
                if(IsPlayerInRangeOfPoint(playerid, 2.0, Poz[0], Poz[1], Poz[2]))
                {
                    DisablePlayerCheckpoint(playerid);
                    SvercaMaterijale[playerid] = 3;
                    SetPlayerCheckpoint(playerid, 1263.2574,-2029.8651,59.3268, 3.0);
                    if(IsPlayerAttachedObjectSlotUsed(playerid, 2)) RemovePlayerAttachedObject(playerid, 2);
                    SetPlayerSpecialAction(playerid, SPECIAL_ACTION_NONE);
                }
                else return SCM(playerid, GREY, "You're not behind vehicles trunk.");
            }
        }
    }
Reply
#4

But what if for example the closest vehicle must be turismo, or burrito ? With this function he can be behind any vehicle
Reply
#5

pawn Код:
if(newkeys & 6) // KEY LMB
    {
        if(SvercaMaterijale[playerid] == 2)
        {
            new vehicleid = GetClosestVehicle(playerid);
            if(vehicleid == INVALID_VEHICLE_ID) return 1;// no closest vehicle.
            if(GetVehicleModel(vehicleid) != 482) return SendClientMessage(playerid, -1, "Thats not the right car!");
            new Float:Poz[3];
            GetPosBehindVehicle(GetClosestVehicle(playerid), Poz[0], Poz[1], Poz[2]);
            if(PI[playerid][Clan] == 7)
            {
                if(IsPlayerInRangeOfPoint(playerid, 2.0, Poz[0], Poz[1], Poz[2]))
                {
                    DisablePlayerCheckpoint(playerid);
                    SvercaMaterijale[playerid] = 3;
                    SetPlayerCheckpoint(playerid, 1263.2574,-2029.8651,59.3268, 3.0);
                    if(IsPlayerAttachedObjectSlotUsed(playerid, 2)) RemovePlayerAttachedObject(playerid, 2);
                    SetPlayerSpecialAction(playerid, SPECIAL_ACTION_NONE);
                }
                else return SCM(playerid, GREY, "You're not behind vehicles trunk.");
            }
        }
    }
This also verifies that the closest vehicle actually exists.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)