SA-MP Forums Custom function problem
 New Account Members List Search Today's Posts Mark Forums Read

 05/05/2014, 07:30 PM #1 moof2010 Big Clucker   Join Date: Nov 2013 Posts: 66 Reputation: 0 Custom function problem i use this: Code: ```stock GetClosestVehicle(playerid, Float:range) { new Float:p_X; new Float:p_Y; new Float:p_Z; new Float:Distance; new Float:PretendentDistance = range +1; new Pretendent; GetPlayerPos(playerid, p_X, p_Y, p_Z); for(new vehicleid=1; vehicleid < MAX_VEHICLES; vehicleid++) { Distance = GetVehicleDistanceFromPoint(vehicleid, p_X, p_Y, p_Z); if(Distance <= range && Distance <= PretendentDistance) { Pretendent = vehicleid; PretendentDistance = Distance; } } return Pretendent; }``` but it returned me 1999 all time. I check at less than 10m from an vehicle end it tell me that nearrest vehicle is 1999 too Why?
 05/05/2014, 07:39 PM #2 Smileys Huge Clucker     Join Date: Dec 2013 Location: Home. Posts: 384 Reputation: 31 Re: Custom function problem I wonder why you start with vehicleid 1, instead of 0, vehicle ids start with 0, not with one, so what you should be using is: pawn Code: `for(new vehicleid=0; vehicleid < MAX_VEHICLES; vehicleid++)` unless you have a specific reason to start at 1. not sure if this will fix it, but the rest of the code seems fine to me; this is the only thing I could find. tho, I also wonder why you do this: pawn Code: `new     Float:PretendentDistance = range +1; // creates a variable that has the range + 1;if(Distance <= range && Distance <= PretendentDistance) // checks if the vehicle is within the normal range, and within the range of the normal range +1;` if it inside the normal range then obviously it's also inside the range + 1; so I don't really understand why you do that. also, you should change this pawn Code: `new     Float:p_X;    new     Float:p_Y;    new     Float:p_Z;    new     Float:Distance;    new     Float:PretendentDistance = range +1;    new     Pretendent;` to this. pawn Code: `new         Float:p_X,    Float:p_Y,    Float:p_Z,    Float:Distance,    Float:PretendentDistance = range +1,    Pretendent;`
05/05/2014, 07:48 PM   #3
Vince
Spam Machine

Join Date: Sep 2007
Location: Belgium
Posts: 10,067
Reputation: 2660
Re: Custom function problem

Quote:
 Originally Posted by Smileys I wonder why you start with vehicleid 1, instead of 0, vehicle ids start with 0, not with one, so what you should be using is:
False. Vehicleids do start at 1. This is probably done to give GetPlayerVehicleID a proper return value.
__________________

05/05/2014, 07:50 PM   #4
Teemo
Big Clucker

Join Date: Jan 2014
Location: SA-MP
Posts: 89
Reputation: 4
Re: Custom function problem

Quote:
 Originally Posted by Vince False. Vehicleids do start at 1. This is probably done to give GetPlayerVehicleID a proper return value.
Right
__________________

 05/05/2014, 07:51 PM #5 Konstantinos Spam Machine     Join Date: Dec 2011 Posts: 11,828 Reputation: 1401 Re: Custom function problem __________________ Life is like riding a bicycle. To keep your balance, you must keep moving. [Tutorial] How to use SQLite [FilterScript] Tune System
05/05/2014, 07:51 PM   #6
Smileys
Huge Clucker

Join Date: Dec 2013
Location: Home.
Posts: 384
Reputation: 31
Re: Custom function problem

Quote:
 Originally Posted by Vince False. Vehicleids do start at 1. This is probably done to give GetPlayerVehicleID a proper return value.
hm, I didn't know that; probably because other stuff does start at 0.

well, thanks for telling anyway

05/05/2014, 07:54 PM   #7
moof2010
Big Clucker

Join Date: Nov 2013
Posts: 66
Reputation: 0
Re: Custom function problem

Quote:
 Originally Posted by Smileys I wonder why you start with vehicleid 1, instead of 0, vehicle ids start with 0, not with one, so what you should be using is: pawn Code: `for(new vehicleid=0; vehicleid < MAX_VEHICLES; vehicleid++)` unless you have a specific reason to start at 1. not sure if this will fix it, but the rest of the code seems fine to me; this is the only thing I could find. tho, I also wonder why you do this: pawn Code: `new     Float:PretendentDistance = range +1; // creates a variable that has the range + 1;if(Distance <= range && Distance <= PretendentDistance) // checks if the vehicle is within the normal range, and within the range of the normal range +1;` if it inside the normal range then obviously it's also inside the range + 1; so I don't really understand why you do that. also, you should change this pawn Code: `new     Float:p_X;    new     Float:p_Y;    new     Float:p_Z;    new     Float:Distance;    new     Float:PretendentDistance = range +1;    new     Pretendent;` to this. pawn Code: `new         Float:p_X,    Float:p_Y,    Float:p_Z,    Float:Distance,    Float:PretendentDistance = range +1,    Pretendent;`

i don't see what is the diference?

and about pretendentdistance i change it inside for

05/05/2014, 08:08 PM   #8
moof2010
Big Clucker

Join Date: Nov 2013
Posts: 66
Reputation: 0
Re: Custom function problem

Quote:
 Originally Posted by Konstantinos http://pastebin.com/4p3c0wba
0 all times

for
Code:
```new testrsadas[128];

 05/05/2014, 08:18 PM #9 Konstantinos Spam Machine     Join Date: Dec 2011 Posts: 11,828 Reputation: 1401 Re: Custom function problem I guess GetVehicleDistanceFromPoint returns 0 if a vehicle doesn't exist so check if it does. pawn Code: `GetClosestVehicle(playerid, Float: range){    new        vehicleid = INVALID_VEHICLE_ID,        Float: pX,        Float: pY,        Float: pZ,        Float: distance = 9999.0,        Float: tmp_distance;        GetPlayerPos(playerid, pX, pY, pZ);     for (new v = 1; v != MAX_VEHICLES; ++v)    {        if (!GetVehicleModel(v)) continue;        tmp_distance = GetVehicleDistanceFromPoint(v, pX, pY, pZ);        if (tmp_distance <= range && tmp_distance < distance)        {            distance = tmp_distance;            vehicleid = v;        }    }    return vehicleid;}` __________________ Life is like riding a bicycle. To keep your balance, you must keep moving. [Tutorial] How to use SQLite [FilterScript] Tune System
 05/05/2014, 08:37 PM #10 moof2010 Big Clucker   Join Date: Nov 2013 Posts: 66 Reputation: 0 Re: Custom function problem thank you very much, it works. sorry for late, i ate http://imgur.com/RMdzKIx,DaQQIyg,AoSCcvu#0

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Lz Scripting Help 6 15/12/2012 02:38 PM Chriham3 Scripting Help 7 24/06/2012 07:57 PM mrcoolballs Scripting Help 5 18/06/2012 01:17 PM dcmd_crash Help Archive 0 08/05/2010 06:14 AM biltong Help Archive 7 08/04/2010 06:05 PM

All times are GMT. The time now is 11:04 AM.

 -- (EN) English -- (RU) Русски SA-MP - Archive - Top