GetClosestTire
#1

This is an interesting request and I'm not sure if its even possible but, how could I check the nearest tire on a vehicle? I'd figure you'd get the closest vehicle but, than you'd have to figuire out where the nearest tire was which I'm not sure how to go about.
Reply
#2

for a passenger you could work off the seatid's
Reply
#3

Getvehiclepos, getvehicleZAngle,

GetXYInFrontOfPlayer,GetXYBehindPlayer, this could help you with front and back

Im not gonnna code the whole thing cause i have homework:
Reply
#4

Got it right here in some of my scripts

Код:
GetXYInFrontOfVehicle(vehicleid, &Float:x, &Float:y, Float:distance)
{
	new Float:a;
	GetVehiclePos(vehicleid,x,y,a);
	GetVehicleZAngle(vehicleid,a);

             //a +=180; (uncomment this if you want the coцrds behind the vehicle
	x += (distance * floatsin(-a, degrees));
	y += (distance * floatcos(-a, degrees));
}
have fun
Reply
#5

It won't be easy to do. You'll need to get the pos of tires and then get the pos of player/vehicle, and check who's closest.

BTW: For get the pos of tires you need to know vehicle dimensions.
Reply
#6

Quote:

It won't be easy to do. You'll need to get the pos of tires and then get the pos of player/vehicle, and check who's closest.

BTW: For get the pos of tires you need to know vehicle dimensions.

True... maybe if you can tell us about 'why' you need to check the closest tire someone might come up with an alternative.
Reply
#7

Quote:
Originally Posted by boelie
Посмотреть сообщение
True... maybe if you can tell us about 'why' you need to check the closest tire someone might come up with an alternative.
Maybe stingers?
Reply
#8

Quote:
Originally Posted by Miguel
Посмотреть сообщение
Maybe stingers?
There's an easier way for that.
OnPlayerEnterArea from Dracoblue's dcallbacks..

pawn Код:
if(areaid == thespikestriparea)
{
    new panels, doors, lights, tires;  
    GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
    UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, 15);
}
Reply
#9

pawn Код:
// Tire IDs: -1 (Not near a tire), 0 (Front-left), 1 (Back-left), 2 (Back-right), 3 (Front-right)

GetClosestTire(playerid)
{
    if(IsPlayerInAnyVehicle(playerid))
        return -1;

    new
        car;
       
    if((car = GetClosestVehicle(playerid)) == INVALID_VEHICLE_ID)
        return -1;
       
    new
        Float:p[3],
        Float:c[3],
        Float:ang,
        Float:dist[2],
        tire;
       
    GetPlayerPos(playerid, p[0], p[1], p[2]);
    GetVehiclePos(car, c[0], c[1], c[2]);
   
    GetVehicleZAngle(car, ang);
   
    tire = 0;
    dist[0] = Float:0xFFFFFFFF;
    ang += 45.0;
   
    for(new t = 0; t < 4; t++, ang += 90.0)
    {
        dist[1] = floatsqroot(
            ((p[0] - (c[0] + floatsin(-ang, degrees))) * (p[0] - (c[0] + floatsin(-ang, degrees)))) +
            ((p[1] - (c[1] + floatcos(-ang, degrees))) * (p[1] - (c[1] + floatcos(-ang, degrees)))));
           
        if(dist[1] < dist[0])
        {
            dist[0] = dist[1];
            tire = t;
        }
    }
   
    return tire;
}

GetClosestVehicle(playerid)
{
    if(IsPlayerInAnyVehicle(playerid))
        return INVALID_VEHICLE_ID;

    new
        Float:p[3],
        Float:c[3],
        Float:dist[2],
        car;

    GetPlayerPos(playerid, p[0], p[1], p[2]);

    car = INVALID_VEHICLE_ID;
    dist[0] = Float:0xFFFFFFFF;

    for(new vehicleid = 0; vehicleid < MAX_VEHICLES; vehicleid++)
    {
        GetVehiclePos(vehicleid, c[0], c[1], c[2]);
       
        dist[1] = floatsqroot(((p[0] - c[0]) * (p[0] - c[0])) + ((p[1] - c[1]) * (p[1] - c[1])) + ((p[2] - c[2]) * (p[2] - c[2])));
       
        if(dist[1] < dist[0] && dist[1] <= 4.0)
        {
            dist[0] = dist[1];
            car = vehicleid;
        }
    }
   
    return car;
}
Currently doesn't account for what type of vehicle you're near and the distance check in GetClosestVehicle doesn't account for how large the vehicle is (the player must be within 4 meters of the vehicle in order for it to return the vehicle id).

I'd expect you'd know what to do with it to rid of those potential bugs, but enjoy anyways!
Reply
#10

Thank you very much Tannz0rz.

I have one other question if anyone could help I want to update one of the tires damage status while keeping the others the same. I know you would do something like this to damage all of them

Код:
new panels, doors, lights, tires;
new carid = GetPlayerVehicleID(playerid);
GetVehicleDamageStatus(carid, panels, doors, lights, tires);
tires = encode_tires(1, 1, 1, 1);
UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
I want to find a way to do something like

Код:
new panels, doors, lights, tires;
new carid = GetPlayerVehicleID(playerid);
GetVehicleDamageStatus(carid, panels, doors, lights, tires);
tires = encode_tires(1, tire2, tire3, tire4);
UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
So I could damage the first tire while keeping the others the same (whether popped or not)
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)