• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Server] How to check if you have a vehicle in position
#1
Hello guys, I have a problem. I'm making a garage system and I would like to know if there are any vehicles parked.





I tried that way, but the vehicle is created in the same position in the second wave, the system works perfectly until the second wave, the third time the truck is created on top of the other.



My English is bad, for a better interpretation of the problem, watch the video:?https://youtu.be/QOKytHFMVQQ

Code:
enum VacancyInfo

{

? ? Float:posX,

? ? Float:posY,

? ? Float:posZ,

? ? Float:posA

}

new TruckerVacancy[MAX_TRUCKER_VACANCY][VacancyInfo] =

{

? ? {2788.3999000,-2484.7000000,14.8000000,90.0000000},

? ? {2788.3999000,-2474.3999000,14.8000000,90.0000000},

? ? {2788.3999000,-2464.1001000,14.8000000,90.0000000},

? ? {2788.3999000,-2453.8000000,14.8000000,90.0000000},

? ? {2788.3999000,-2443.5000000,14.8000000,90.0000000},

? ? {2788.3999000,-2433.2000000,14.8000000,90.0000000},

? ? {2788.3999000,-2422.8999000,14.8000000,90.0000000}

};



#define IsVehicleInRangeOfPoint(%0,%1,%2,%3,%4)\

? ? (%1 >= GetVehicleDistanceFromPoint(%0, %2, %3, %4))



stock IsVehicleFromRangePointEx(Float:range, Float:x, Float:y, Float:z)

{

? ? foreach(new i: Vehicle)

? ? {

? ? ? ? return IsVehicleInRangeOfPoint(i, range, x, y, z);

? ? }

? ? return 0;

}



CMD:etruck(playerid, params[])

{

? ? for(new i; i < MAX_TRUCKER_VACANCY; i)

? ? {

? ? ? ? if(!IsVehicleFromRangePointEx(5.0, TruckerVacancy[i][posX],TruckerVacancy[i][posY],TruckerVacancy[i][posZ]))

? ? ? ? {

? ? ? ? ? ? CreateVehicleEx(403, TruckerVacancy[i][posX],TruckerVacancy[i][posY],TruckerVacancy[i][posZ],TruckerVacancy[i][posA], 0, 0);

? ? ? ? ? ? return 1;

? ? ? ? }

? ? }

? ? return 1;

}
  Reply
#2
Hello

I think the problem is with the "IsVehicleFromRangePointEx" function.



Try this:

Code:
stock IsVehicleFromRangePointEx(Float:range, Float:x, Float:y, Float:z)

{

? ? foreach(new i: Vehicle)

? ? {

? ? ? ? if ( IsVehicleInRangeOfPoint(i, range, x, y, z) ) return 1;

? ? }

? ? return 0;

}
  Reply
#3
(2020-12-09, 08:33 PM)Radical Wrote: Hello

I think the problem is with the "IsVehicleFromRangePointEx" function.



Try this:

Code:
stock IsVehicleFromRangePointEx(Float:range, Float:x, Float:y, Float:z)

{

? ? foreach(new i: Vehicle)

? ? {

? ? ? ? if ( IsVehicleInRangeOfPoint(i, range, x, y, z) ) return 1;

? ? }

? ? return 0;

}





Thanks, it worked
  Reply
#4
Browhat
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply


Forum Jump: