Function don't work. -
budelis - 31.10.2012
Hi,
i use function:
Код:
new Float:DISTANCE;
GetPlayerPos(playerid, SavePos[ playerid ][ 0 ], SavePos[ playerid ][ 1 ], SavePos[ playerid ][ 2 ]);
for(ivh= 1; ivh < MAX_VEHICLES; ivh ++)
{
DISTANCE = GetVehicleDistanceFromPoint(ivh, SavePos[ playerid ][ 0 ], SavePos[ playerid ][ 1 ], SavePos[ playerid ][ 2 ]);
}
But when i print distance i get 0.000000.
Re: Function don't work. -
[HK]Ryder[AN] - 31.10.2012
are the savepos variables Floats?
Re: Function don't work. -
budelis - 31.10.2012
Yes. I just want to get closest car, but server always found, but it's realy not.
Код:
stock GetClosestVehicle(playerid, Float:range)
{
SAVEVEHICLEID[ playerid ] = 0;
new Float:DISTANCE;
GetPlayerPos(playerid, SavePos[ playerid ][ 0 ], SavePos[ playerid ][ 1 ], SavePos[ playerid ][ 2 ]);
for(new ivh = 1; ivh < MAX_VEHICLES; ivh ++)
{
DISTANCE = GetVehicleDistanceFromPoint(CikleSave[ playerid ], SavePos[ playerid ][ 0 ], SavePos[ playerid ][ 1 ], SavePos[ playerid ][ 2 ]);
if(DISTANCE <= range )
{
SAVEVEHICLEID[ playerid ] = ivh;
break;
}
}
}
i try to check if
Код:
if( SAVEVEHICLEID[ playerid ] == 0 )
This will be, if there is no near vehicle in 7 metres, but this never happen there is always car. Then i try to print and i get distance 0, then this check will work:
Код:
if(DISTANCE <= range )
{
And this happen for vehicleid 1.
Re: Function don't work. -
[HK]Ryder[AN] - 31.10.2012
can you show the full command
Re: Function don't work. -
[NYO] Kael - 31.10.2012
I use this
pawn Код:
GetDistanceToCar(playerid,carid) //By Darkrealm (Edited by Sacky)
{
new Float:dis;
new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
if (!IsPlayerConnected(playerid)) return -1;
GetPlayerPos(playerid,x1,y1,z1);
GetVehiclePos(carid,x2,y2,z2);
dis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
return floatround(dis);
}
pawn Код:
stock GetClosestCar(playerid) //By Darkrealm
{
if (!IsPlayerConnected(playerid)) return -1;
new Float:prevdist = 100000.000;
new prevcar;
for (new carid = 0; carid < MAX_VEHICLES; carid++)
{
new Float:dist = GetDistanceToCar(playerid,carid);
if ((dist < prevdist))
{
prevdist = dist;
prevcar = carid;
}
}
return prevcar;
}
Re: Function don't work. -
budelis - 31.10.2012
Код:
CMD:check(playerid,params[])
{
GetClosestVehicle(playerid, 7.0)
if( SAVEVEHICLEID[ playerid ] == 0 )
{
SendClientMessage( playerid, COLOR_RED,"* No vehicle exist.");
return 1;
}
return 1;
}
I never get this message "No vehicle exist.". But it's really not car near my.
Re: Function don't work. -
[HK]Ryder[AN] - 31.10.2012
try changing the for loop in our stock to
pawn Код:
for(new ivh = 0; ivh < MAX_VEHICLES; ivh ++)