tow.pwn 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. /$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$
  3. | $$$ | $$ /$$__ $$ | $$__ $$| $$__ $$
  4. | $$$$| $$| $$ \__/ | $$ \ $$| $$ \ $$
  5. | $$ $$ $$| $$ /$$$$ /$$$$$$| $$$$$$$/| $$$$$$$/
  6. | $$ $$$$| $$|_ $$|______/| $$__ $$| $$____/
  7. | $$\ $$$| $$ \ $$ | $$ \ $$| $$
  8. | $$ \ $$| $$$$$$/ | $$ | $$| $$
  9. |__/ \__/ \______/ |__/ |__/|__/
  10. Towing System
  11. Next Generation Gaming, LLC
  12. (created by Next Generation Gaming Development Team)
  13. * Copyright (c) 2016, Next Generation Gaming, LLC
  14. *
  15. * All rights reserved.
  16. *
  17. * Redistribution and use in source and binary forms, with or without modification,
  18. * are not permitted in any case.
  19. *
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  25. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. CMD:tow(playerid, params[])
  34. {
  35. if(IsPlayerInAnyVehicle(playerid))
  36. {
  37. new
  38. carid = GetPlayerVehicleID(playerid);
  39. if(IsATowTruck(carid))
  40. {
  41. new
  42. closestcar = GetClosestCar(playerid, carid);
  43. foreach(new i: Player)
  44. {
  45. if(arr_Towing[i] == closestcar || (GetPlayerVehicleID(i) == closestcar && GetPlayerState(i) == 2)) return SendClientMessageEx(playerid, COLOR_GREY, "You can't tow a vehicle which is occupied, or in tow.");
  46. }
  47. if(GetDistanceToCar(playerid,closestcar) <= 8 && !IsTrailerAttachedToVehicle(carid)) {
  48. foreach(new i: Player)
  49. {
  50. if(IsAPlane(closestcar) || IsABike(closestcar) || IsASpawnedTrain(closestcar) || IsATrain(closestcar) || IsAHelicopter(closestcar)) {
  51. return SendClientMessageEx(playerid, COLOR_GRAD2, "You cannot tow this type of vehicle.");
  52. }
  53. if(GetPlayerVehicle(i, closestcar) != -1) {
  54. new
  55. hKey;
  56. if(((hKey = PlayerInfo[i][pPhousekey]) != INVALID_HOUSE_ID) && IsPlayerInRangeOfPoint(playerid, 50.0, HouseInfo[hKey][hExteriorX], HouseInfo[hKey][hExteriorY], HouseInfo[hKey][hExteriorZ])
  57. ||((hKey = PlayerInfo[i][pPhousekey2]) != INVALID_HOUSE_ID) && IsPlayerInRangeOfPoint(playerid, 50.0, HouseInfo[hKey][hExteriorX], HouseInfo[hKey][hExteriorY], HouseInfo[hKey][hExteriorZ])
  58. ||((hKey = PlayerInfo[i][pPhousekey3]) != INVALID_HOUSE_ID) && IsPlayerInRangeOfPoint(playerid, 50.0, HouseInfo[hKey][hExteriorX], HouseInfo[hKey][hExteriorY], HouseInfo[hKey][hExteriorZ])) {
  59. return SendClientMessageEx(playerid, COLOR_GREY, "This vehicle doesn't need to be towed.");
  60. }
  61. RemoveVehicleFromMeter(closestcar);
  62. arr_Towing[playerid] = closestcar;
  63. SendClientMessageEx(playerid, COLOR_GRAD2, "This vehicle is available for impounding.");
  64. return AttachTrailerToVehicle(closestcar,carid);
  65. }
  66. }
  67. SendClientMessageEx(playerid, COLOR_GRAD2, "This vehicle has no registration, it is available for impounding.");
  68. AttachTrailerToVehicle(closestcar,carid);
  69. arr_Towing[playerid] = closestcar;
  70. RemoveVehicleFromMeter(closestcar);
  71. return 1;
  72. }
  73. }
  74. else if(IsAAircraftTowTruck(carid)) //Tug
  75. {
  76. new
  77. closestcar = GetClosestCar(playerid, carid);
  78. foreach(new i: Player)
  79. {
  80. if(arr_Towing[i] == closestcar || (GetPlayerVehicleID(i) == closestcar && GetPlayerState(i) == 2)) return SendClientMessageEx(playerid, COLOR_GREY, "You can't tow a vehicle which is occupied, or in tow.");
  81. }
  82. if(GetDistanceToCar(playerid,closestcar) <= 8 && !IsTrailerAttachedToVehicle(carid))
  83. {
  84. foreach(new i: Player)
  85. {
  86. if(IsAPlane(closestcar))
  87. {
  88. if(GetPlayerVehicle(i, closestcar) != -1)
  89. {
  90. RemoveVehicleFromMeter(closestcar);
  91. arr_Towing[playerid] = closestcar;
  92. SendClientMessageEx(playerid, COLOR_GRAD2, "This vehicle is available for impounding.");
  93. return AttachTrailerToVehicle(closestcar,carid);
  94. }
  95. }
  96. else return SendClientMessageEx(playerid, COLOR_GRAD2, "You can only tow aircrafts with this vehicle!");
  97. }
  98. SendClientMessageEx(playerid, COLOR_GRAD2, "This vehicle has no registration, it is available for impounding.");
  99. AttachTrailerToVehicle(closestcar,carid);
  100. arr_Towing[playerid] = closestcar;
  101. RemoveVehicleFromMeter(closestcar);
  102. }
  103. }
  104. else SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to tow with this vehicle.");
  105. }
  106. else SendClientMessageEx(playerid, COLOR_GRAD2, "You need to be inside a vehicle to use this command!");
  107. return 1;
  108. }
  109. CMD:untow(playerid, params[])
  110. {
  111. if(IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid)))
  112. {
  113. SendClientMessageEx(playerid, COLOR_GRAD1, "You have unhooked the vehicle that you were towing.");
  114. arr_Towing[playerid] = INVALID_VEHICLE_ID;
  115. DetachTrailerFromVehicle(GetPlayerVehicleID(playerid));
  116. }
  117. else SendClientMessageEx(playerid, COLOR_GRAD1, "You are currently not towing anything.");
  118. return 1;
  119. }