Problem with getclosestcar -
JulietaZ - 18.10.2010
I just wanted to test some stuff before do something with this code, but for some reason it allways returns ID -1 and the distance its like 11600(and then numbers that changes) even when im inside the car it gives a really long number, isnt supossed when im very closer to the car it must have distance 0 or something?....
if (strcmp(cmdtext, "/test", true)==0)
{
new carids = GetClosestCar(playerid);
new Float:dist= GetDistanceFromPlayerToVehicle(playerid,carids);
new stringa[256];
format(stringa, sizeof stringa, "Distancia a vehiculo mas cercano: %i Id:[%i]", dist,carids);
SendClientMessage(playerid, 0xCCFFDD56, stringa);
return 1;
}
Respuesta: Problem with getclosestcar -
The_Moddler - 18.10.2010
pawn Код:
if (strcmp(cmdtext, "/test", true)==0)
{
new carids = GetClosestCar(playerid);
new Float: dist = GetDistanceFromPlayerToVehicle(playerid, carids);
new stringa[256];
format(stringa, sizeof stringa, "Distancia a vehiculo mas cercano: %2.f Id:[%i]", dist, carids);
SendClientMessage(playerid, 0xCCFFDD56, stringa);
return 1;
}
There you go.. ahi tenes
Re: Problem with getclosestcar -
JulietaZ - 18.10.2010
thanks, but why the car ID is allways -1 ? thats important, im trying to make omething like a cmomand to spawn a car, only if there is no cars closer to the player...but since it allways gives id -1 it will not detect any car closer so it will spawn cars anywais
Re: Problem with getclosestcar -
JulietaZ - 18.10.2010
i have this version: (didnt maded this one)
stock GetClosestVehicle(playerid) //By Darkrealm (edited by Gabrie "Larcius" Cordes)
{
if(IsPlayerConnected(playerid) && IsVehicleConnected(0))
{
new closestvehicle=0;
new Float:closestdist=GetDistanceToVehicle(playerid,0) ;
for(new vehicleid=0; vehicleid<MAX_VEHICLES; vehicleid++)
{
new Float:dist = GetDistanceToVehicle(playerid,vehicleid);
if ((dist < closestdist))
{
closestdist = dist;
closestvehicle = vehicleid;
}
}
return closestvehicle;
}
return -1;
}
Respuesta: Problem with getclosestcar -
The_Moddler - 18.10.2010
Yes, it always returns -1 if there is no vehicle?
Use TheCrazyKiller stock.
Re: Problem with getclosestcar -
JulietaZ - 19.10.2010
Not working stills does not gives the id...now its 0
Re: Problem with getclosestcar -
Babul - 19.10.2010
heres a working zcmd version - it takes 1, maybe 2 ms to finish:
Код:
CMD:test(playerid,params[]){
new TimerOld=GetTickCount();
new VehID;
new Dist,DistLower=8500,DistLowerSA;
new Float:X,Float:Y,Float:Z;
new Float:pX,Float:pY,Float:pZ;
new XX,YY,ZZ;
new sXX,sYY,sZZ;
GetPlayerPos(playerid,pX,pY,pZ);
for(new v=0;v<MAX_VEHICLES;v++)
{
if(IsPlayerInVehicle(playerid,v)==1) continue;
GetVehiclePos(v,X,Y,Z);
if(IsPlayerInRangeOfPoint(playerid,DistLower,X,Y,Z))
{
XX=floatround(X-pX,floatround_floor);
YY=floatround(Y-pY,floatround_floor);
ZZ=floatround(Z-pZ,floatround_floor);
sXX=XX*XX;
sYY=YY*YY;
sZZ=ZZ*ZZ;
DistLowerSA=sXX+sYY+sZZ;
DistLower=floatround(floatsqroot(DistLowerSA),floatround_floor);
VehID=v;
}
}
new TimerNew=GetTickCount();
new string[48];
format(string,sizeof(string),"Closest Veh:%d Dist:%d ms:%d",VehID,DistLower,TimerNew-TimerOld);
SendClientMessage(playerid,0x33cc33ff,string);
return VehID;
}
http://www.xfire.com/video/38ed30/
have fun reinventing the wheel ^^
Respuesta: Re: Problem with getclosestcar -
The_Moddler - 19.10.2010
Quote:
Originally Posted by JulietaZ
Not working stills does not gives the id...now its 0
|
It gives you zero because there isn't a near car..
Re: Problem with getclosestcar -
JulietaZ - 19.10.2010
it gives 0 even when im inside a car....XD...Im just trying to get distance between player and most closer car, but since this thing allways gives -1 or 0 then i cant use the distance function until i get the ID ..