[HELP] GetVehiclePos Really this bugged?!?!? - 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: [HELP] GetVehiclePos Really this bugged?!?!? (
/showthread.php?tid=94823)
[HELP] GetVehiclePos Really this bugged?!?!? -
cyber_punk - 01.09.2009
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 -.-
Re: [HELP] GetVehiclePos Really this bugged?!?!? -
MrSns - 01.09.2009
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
Re: [HELP] GetVehiclePos Really this bugged?!?!? -
cyber_punk - 01.09.2009
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.
Re: [HELP] GetVehiclePos Really this bugged?!?!? -
Joosephe - 01.09.2009
BUMP Could someone help Enzo? I tried to tackle it too, failed
Re: [HELP] GetVehiclePos Really this bugged?!?!? -
cyber_punk - 01.09.2009
-.- 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.