Advertisement
Guest User

Air Trafficking From GTA V

a guest
Aug 4th, 2015
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.51 KB | None | 0 0
  1. #define     FILTERSCRIPT
  2. #include    <a_samp>
  3. #include    <mapandreas>    // http://forum.sa-mp.com/showthread.php?t=273263
  4.  
  5. #define     PACKAGE_MODEL   (2912)
  6. #define     MAPICON_INDEX   (69)
  7.  
  8. #define PRESSED(%0) \
  9.     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  10.  
  11. enum    e_droplocations
  12. {
  13.     dropLocation[32],
  14.     Float: dropX,
  15.     Float: dropY,
  16.     Float: dropZ
  17. };
  18.  
  19. enum    e_dropobjects
  20. {
  21.     OBJECT_PACKAGE,
  22.     OBJECT_ZONE
  23. };
  24.  
  25. new
  26.     DropLocations[][e_droplocations] = {
  27.     // example locations
  28.         {"Farm", 22.3, 17.4, 5.0},
  29.         {"Area 51", 302.2160, 1955.8740, 17.6406},
  30.         {"Flying School", 415.5471, 2503.8643, 16.9425},
  31.         {"NSA HQ", -317.4946, 1523.1005, 75.3594}
  32.     };
  33.  
  34. new
  35.     bool: InDelivery[MAX_PLAYERS] = {false, ...},
  36.     PackageCount[MAX_PLAYERS] = {5, ...},
  37.     TraffickingObjects[MAX_PLAYERS][2];
  38.  
  39. stock IsATraffickingPlane(modelid)
  40. {
  41.     new planes[] = {593, 511, 460};
  42.     for(new i; i < sizeof(planes); ++i)
  43.     {
  44.         if(planes[i] == modelid) return 1;
  45.     }
  46.  
  47.     return 0;
  48. }
  49.  
  50. stock ResetDelivery(playerid)
  51. {
  52.     if(!IsPlayerConnected(playerid)) return 0;
  53.     InDelivery[playerid] = false;
  54.     PackageCount[playerid] = 5;
  55.     RemovePlayerMapIcon(playerid, MAPICON_INDEX);
  56.     SetPVarInt(playerid, "DeliveryCooldown", tickcount()+120000);
  57.    
  58.     if(IsValidObject(TraffickingObjects[playerid][OBJECT_PACKAGE]))
  59.     {
  60.         DestroyObject(TraffickingObjects[playerid][OBJECT_PACKAGE]);
  61.         TraffickingObjects[playerid][OBJECT_PACKAGE] = INVALID_OBJECT_ID;
  62.     }
  63.  
  64.     if(IsValidPlayerObject(playerid, TraffickingObjects[playerid][OBJECT_ZONE]))
  65.     {
  66.         DestroyPlayerObject(playerid, TraffickingObjects[playerid][OBJECT_ZONE]);
  67.         TraffickingObjects[playerid][OBJECT_ZONE] = INVALID_OBJECT_ID;
  68.     }
  69.    
  70.     return 1;
  71. }
  72.  
  73. stock Float:Distance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2) // http://forum.sa-mp.com/showpost.php?p=2919962&postcount=2
  74.     return floatsqroot((((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))+((z1-z2)*(z1-z2))));
  75.  
  76. stock RandomEx(min, max)
  77.     return random(max - min) + min;
  78.  
  79. public OnPlayerConnect(playerid)
  80. {
  81.     InDelivery[playerid] = false;
  82.     PackageCount[playerid] = 5;
  83.     TraffickingObjects[playerid][OBJECT_PACKAGE] = INVALID_OBJECT_ID;
  84.     TraffickingObjects[playerid][OBJECT_ZONE] = INVALID_OBJECT_ID;
  85.     return 1;
  86. }
  87.  
  88. public OnPlayerDisconnect(playerid, reason)
  89. {
  90.     ResetDelivery(playerid);
  91.     return 1;
  92. }
  93.  
  94. public OnPlayerDeath(playerid, killerid, reason)
  95. {
  96.     if(InDelivery[playerid])
  97.     {
  98.         SendClientMessage(playerid, 0xE74C3CFF, "DELIVERY FAILED: {FFFFFF}You died.");
  99.         ResetDelivery(playerid);
  100.     }
  101.    
  102.     return 1;
  103. }
  104.  
  105. public OnPlayerStateChange(playerid, newstate, oldstate)
  106. {
  107.     if(newstate == PLAYER_STATE_DRIVER && IsATraffickingPlane(GetVehicleModel(GetPlayerVehicleID(playerid))) && GetPVarInt(playerid, "DeliveryCooldown") < tickcount())
  108.     {
  109.         GameTextForPlayer(playerid, "~n~~n~~n~~w~Air Trafficking Available~n~Press ~y~~k~~TOGGLE_SUBMISSIONS~ ~w~to start", 3000, 3);
  110.     }
  111.    
  112.     return 1;
  113. }
  114.  
  115. public OnPlayerExitVehicle(playerid, vehicleid)
  116. {
  117.     if(InDelivery[playerid])
  118.     {
  119.         SendClientMessage(playerid, 0xE74C3CFF, "DELIVERY FAILED: {FFFFFF}You left your plane.");
  120.         ResetDelivery(playerid);
  121.     }
  122.    
  123.     return 1;
  124. }
  125.  
  126. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  127. {
  128.     if(IsATraffickingPlane(GetVehicleModel(GetPlayerVehicleID(playerid))) && PRESSED(KEY_SUBMISSION))
  129.     {
  130.         if(!InDelivery[playerid]) {
  131.             if(GetPVarInt(playerid, "DeliveryCooldown") > tickcount()) return SendClientMessage(playerid, 0xE74C3CFF, "DELIVERY: {FFFFFF}Please wait to start another delivery mission again.");
  132.             new id = random(sizeof(DropLocations)), string[144];
  133.             TraffickingObjects[playerid][OBJECT_ZONE] = CreatePlayerObject(playerid, 19946, DropLocations[id][dropX], DropLocations[id][dropY], DropLocations[id][dropZ], 0.0, 0.0, 0.0, 1200.0);
  134.            
  135.             SetPlayerMapIcon(playerid, MAPICON_INDEX, DropLocations[id][dropX], DropLocations[id][dropY], DropLocations[id][dropZ], 24, 0, MAPICON_GLOBAL);
  136.             SendClientMessage(playerid, 0x2ECC71FF, "DELIVERY: {FFFFFF}You've started a delivery mission.");
  137.             format(string, sizeof(string), "DELIVERY: {FFFFFF}Drop the package in the marked area at {3498DB}%s {FFFFFF}and you'll get your money.", DropLocations[id][dropLocation]);
  138.             SendClientMessage(playerid, 0x2ECC71FF, string);
  139.             SendClientMessage(playerid, 0x2ECC71FF, "DELIVERY: {FFFFFF}You can drop a crate using H/CAPS LOCK.");
  140.             SendClientMessage(playerid, 0x2ECC71FF, "DELIVERY: {FFFFFF}You can cancel the delivery mission using 2 or by leaving your plane.");
  141.             InDelivery[playerid] = true;
  142.             PackageCount[playerid] = 5;
  143.         }else{
  144.             SendClientMessage(playerid, 0xE74C3CFF, "DELIVERY CANCELLED: {FFFFFF}You've cancelled the delivery mission.");
  145.             ResetDelivery(playerid);
  146.         }
  147.     }
  148.    
  149.     if(InDelivery[playerid] && PRESSED(KEY_CROUCH))
  150.     {
  151.         if(IsValidObject(TraffickingObjects[playerid][OBJECT_PACKAGE])) return 1;
  152.         if(PackageCount[playerid] == 0) return SendClientMessage(playerid, 0xE74C3CFF, "DELIVERY: {FFFFFF}You don't have any more packages.");
  153.         new Float: x, Float: y, Float: z, Float: z2;
  154.         GetPlayerPos(playerid, x, y, z);
  155.         GetPointZPos(x, y, z2);
  156.         TraffickingObjects[playerid][OBJECT_PACKAGE] = CreateObject(PACKAGE_MODEL, x, y, z-1.5, 0.0, 0.0, 0.0);
  157.         MoveObject(TraffickingObjects[playerid][OBJECT_PACKAGE], x, y, z2, 20.0);
  158.         PackageCount[playerid]--;
  159.     }
  160.    
  161.     return 1;
  162. }
  163.  
  164. public OnObjectMoved(objectid)
  165. {
  166.     if(GetObjectModel(objectid) == PACKAGE_MODEL)
  167.     {
  168.         new owner = INVALID_PLAYER_ID;
  169.         for(new i, p = GetPlayerPoolSize(); i <= p; ++i)
  170.         {
  171.             if(objectid == TraffickingObjects[i][OBJECT_PACKAGE])
  172.             {
  173.                 owner = i;
  174.                 break;
  175.             }
  176.         }
  177.        
  178.         new Float: objx, Float: objy, Float: objz, Float: zonex, Float: zoney, Float: zonez, money;
  179.         GetObjectPos(objectid, objx, objy, objz);
  180.         GetPlayerObjectPos(owner, TraffickingObjects[owner][OBJECT_ZONE], zonex, zoney, zonez);
  181.         new Float: dist = Distance(objx, objy, objz, zonex, zoney, zonez);
  182.         if(dist < 8.0) {
  183.             money = 1500 + floatround(-100 * dist, floatround_floor);
  184.             if(money < 250) money = 250;
  185.             GivePlayerMoney(owner, money);
  186.  
  187.             new id = random(sizeof(DropLocations)), string[144];
  188.             format(string, sizeof(string), "DELIVERY: {FFFFFF}You've delivered a package and earned {2ECC71}$%d{FFFFFF}.", money);
  189.             SendClientMessage(owner, 0x2ECC71FF, string);
  190.            
  191.             DestroyPlayerObject(owner, TraffickingObjects[owner][OBJECT_ZONE]);
  192.             TraffickingObjects[owner][OBJECT_ZONE] = CreatePlayerObject(owner, 19946, DropLocations[id][dropX], DropLocations[id][dropY], DropLocations[id][dropZ], 0.0, 0.0, 0.0, 1200.0);
  193.             SetPlayerMapIcon(owner, 69, DropLocations[id][dropX], DropLocations[id][dropY], DropLocations[id][dropZ], 24, 0, MAPICON_GLOBAL);
  194.             format(string, sizeof(string), "DELIVERY: {FFFFFF}Drop the package in the marked area at {3498DB}%s{FFFFFF}.", DropLocations[id][dropLocation]);
  195.             SendClientMessage(owner, 0x2ECC71FF, string);
  196.             format(string, sizeof(string), "DELIVERY: {FFFFFF}Packages left: {3498DB}%d{FFFFFF}.", PackageCount[owner]);
  197.             SendClientMessage(owner, 0x2ECC71FF, string);
  198.         }else{
  199.             SendClientMessage(owner, 0xE74C3CFF, "DELIVERY: {FFFFFF}Package didn't land in the marked area, better luck next time.");
  200.         }
  201.        
  202.         DestroyObject(TraffickingObjects[owner][OBJECT_PACKAGE]);
  203.         TraffickingObjects[owner][OBJECT_PACKAGE] = INVALID_OBJECT_ID;
  204.         if(PackageCount[owner] == 0)
  205.         {
  206.             SendClientMessage(owner, 0x2ECC71FF, "DELIVERY: {FFFFFF}You're out of packages.");
  207.             ResetDelivery(owner);
  208.         }
  209.     }
  210.    
  211.     return 1;
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement