SA-MP Forums Archive
GetClosestTire - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: GetClosestTire (/showthread.php?tid=187435)



GetClosestTire - MisterTickle - 02.11.2010

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.


Re: GetClosestTire - (SF)Noobanatior - 02.11.2010

for a passenger you could work off the seatid's


Re: GetClosestTire - Bessensap - 02.11.2010

Getvehiclepos, getvehicleZAngle,

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

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


Re: GetClosestTire - boelie - 02.11.2010

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


Respuesta: GetClosestTire - MrDeath537 - 02.11.2010

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.


Re: GetClosestTire - boelie - 02.11.2010

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.


Re: GetClosestTire - Miguel - 02.11.2010

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?


Re: GetClosestTire - Bessensap - 02.11.2010

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);
}



Re: GetClosestTire - Tannz0rz - 02.11.2010

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!


Re: GetClosestTire - MisterTickle - 04.11.2010

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)