[HELP] GetVehiclePos Really this bugged?!?!?
#1

I was wondering if GetVehiclePos is really this bugged up or is it some weird ass error in my code. I know GetVehiclePos is supposed to return either the players last vehicles position or the original spawn location. Yet from the printf in the console no matter what I do, get in a car or just get near a fresh spawned car the result is always the same. GetClosestVehicle returns 0, and in the print I get the distance to the vehicle as being 1158606533 (read EDIT2).

WTF do I do or can I do to get this to work?

Here is the 2 functions code.
pawn Код:
stock GetClosestVehicle(playerid)
{
    new x,Float:dis,Float:dis2,vehicleid;
    vehicleid = -1;
    dis = 99999.99;
    for (x=0;x<MAX_VEHICLES;x++)
    {
        dis2 = GetDistanceToVehicle(playerid, vehicleid);
        if(dis2 < dis && dis2 != -1.00)
        {
            dis = dis2;
            vehicleid = x;
        }

    }
    printf("Closest Vehicle: %d", vehicleid);
    return vehicleid;
}

stock Float:GetDistanceToVehicle(playerid, vehicleid)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    GetPlayerPos(playerid,x1,y1,z1);
    GetVehiclePos(vehicleid ,x2,y2,z2);
    new Float:tmpdis = floatsqroot((x2-=x1)*x2 + (y2-=y1)*y2 + (z2-=z1)*z2);
    printf("Distance to Vehicle: %.2f", tmpdis);
    return tmpdis;
}
[EDIT] Does it matter that I spawn the cars with AddStaticVehicleEx ?

[EDIT2]Whoops I see now why I wasn't getting a float value on print (duh) but still why am I only getting the same distance of 2471.96 no matter what I do -.-
Reply
#2

hmm, yeah i was looking at this and i noticed something...


But i forgot what i noticed, when i rember ill get back to you...


Sorry
Reply
#3

Well i can get different values in distance yet the closest vehicle returned is always 0, no matter what, I can't seem to figure out why it won't get the position of all the vehicles in the loop.

Anyone got any ideas I really need this LOL.
Reply
#4

BUMP Could someone help Enzo? I tried to tackle it too, failed
Reply
#5

-.- Wow I just checked my server log, I happened to get it to check the vehicles and get there distances it seems that the function was counting a distance of 0 being my closest distance so for example every time it was getting coords 0.0 0.0 0.0 and it produced the square root 0 that was my closest vehicle. I believe I can solve the puzzle now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)