Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Support [Server] How to check if you have a vehicle in position

 
  • 0 Vote(s) - 0 Average
Server How to check if you have a vehicle in position
Frajola
Offline

Burgershot Member
Posts: 12
Threads: 6
Joined: Apr 2019
Reputation: 0
Location: Rio de Janeiro
#1
2020-12-09, 01:37 AM (This post was last modified: 2020-12-09, 05:53 AM by Frajola.)
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;
}
Radical
Offline

Burgershot Member
Posts: 148
Threads: 21
Joined: Dec 2020
Reputation: 16
#2
2020-12-09, 08:33 PM
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;
}
Frajola
Offline

Burgershot Member
Posts: 12
Threads: 6
Joined: Apr 2019
Reputation: 0
Location: Rio de Janeiro
#3
2020-12-09, 09:24 PM
(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
Pinch
Offline

Burgershot Member
Posts: 391
Threads: 19
Joined: Apr 2019
Reputation: 22
Location: Belgrade, Serbia
#4
2020-12-10, 11:13 AM
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.
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode