Guest User

Untitled

a guest
Aug 28th, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.95 KB | None | 0 0
  1. #include <a_samp>
  2. #include <foreach> // by Kar - http://forum.sa-mp.com/showthread.php?t=570868
  3. #include <izcmd> // by Yashas - http://forum.sa-mp.com/showthread.php?t=576114
  4. #include <mapandreas> // by RyDeR - http://forum.sa-mp.com/showthread.php?t=273263
  5.  
  6. #define MAX_DROPS (50)
  7. #define DIST (300.0)
  8.  
  9. // Config
  10. #define PLANE_TIME (7) // how many seconds does a plane need before flying (Default: 7)
  11. #define REQ_COOLDOWN (15) // how many minutes does someone need to wait for requesting a supply drop again (Default: 3)
  12. #define DROP_LIFE (5) // life time of a supply drop, in minutes (Default: 5)
  13. #define AMMO_PRICE (750) // price of ammo request (Default: 750)
  14. #define HEALTH_PRICE (500) // price of health kit request (Default: 500)
  15. #define ARMOR_PRICE (450) // price of body armor request (Default: 450)
  16. #define AMMO_AMOUNT (150) // how much ammo will be given with a weapon/ammo drop (Default: 150)
  17.  
  18. enum _:E_DROPTYPE
  19. {
  20. DROP_TYPE_WEAPON,
  21. DROP_TYPE_AMMO,
  22. DROP_TYPE_HEALTH,
  23. DROP_TYPE_ARMOR
  24. }
  25.  
  26. enum _:E_DROPDIALOG
  27. {
  28. DIALOG_DROP_MENU,
  29. DIALOG_DROP_WEAPONS,
  30. DIALOG_DROP_CONFIRM
  31. }
  32.  
  33. enum E_WEPDATA
  34. {
  35. weaponID,
  36. weaponPrice
  37. }
  38.  
  39. enum E_DROP
  40. {
  41. // objects
  42. planeObj,
  43. boxObj,
  44. paraObj,
  45. // pickup (created after drop is done)
  46. dropPickup,
  47. // label
  48. Text3D: dropLabel,
  49. // drop data
  50. dropType,
  51. dropData,
  52. // timer
  53. dropTimer,
  54. // other
  55. requestedBy
  56. }
  57.  
  58. new
  59. SupplyData[MAX_DROPS][E_DROP],
  60. Iterator: SupplyDrops<MAX_DROPS>;
  61.  
  62. new
  63. AvailableWeapons[][E_WEPDATA] = {
  64. // weapon id, price
  65. // you can get weapon ids from here: https://wiki.sa-mp.com/wiki/Weapons
  66. {WEAPON_SHOTGUN, 300},
  67. {WEAPON_SAWEDOFF, 130},
  68. {WEAPON_AK47, 500},
  69. {WEAPON_MINIGUN, 5000000}
  70. };
  71.  
  72. formatInt(intVariable, iThousandSeparator = ',', iCurrencyChar = '$')
  73. {
  74. /*
  75. By Kar
  76. https://gist.github.com/Kar2k/bfb0eafb2caf71a1237b349684e091b9/8849dad7baa863afb1048f40badd103567c005a5#file-formatint-function
  77. */
  78. static
  79. s_szReturn[ 32 ],
  80. s_szThousandSeparator[ 2 ] = { ' ', EOS },
  81. s_szCurrencyChar[ 2 ] = { ' ', EOS },
  82. s_iVariableLen,
  83. s_iChar,
  84. s_iSepPos,
  85. bool:s_isNegative
  86. ;
  87.  
  88. format( s_szReturn, sizeof( s_szReturn ), "%d", intVariable );
  89.  
  90. if(s_szReturn[0] == '-')
  91. s_isNegative = true;
  92. else
  93. s_isNegative = false;
  94.  
  95. s_iVariableLen = strlen( s_szReturn );
  96.  
  97. if ( s_iVariableLen >= 4 && iThousandSeparator)
  98. {
  99. s_szThousandSeparator[ 0 ] = iThousandSeparator;
  100.  
  101. s_iChar = s_iVariableLen;
  102. s_iSepPos = 0;
  103.  
  104. while ( --s_iChar > _:s_isNegative )
  105. {
  106. if ( ++s_iSepPos == 3 )
  107. {
  108. strins( s_szReturn, s_szThousandSeparator, s_iChar );
  109.  
  110. s_iSepPos = 0;
  111. }
  112. }
  113. }
  114. if(iCurrencyChar) {
  115. s_szCurrencyChar[ 0 ] = iCurrencyChar;
  116. strins( s_szReturn, s_szCurrencyChar, _:s_isNegative );
  117. }
  118. return s_szReturn;
  119. }
  120.  
  121. ConvertToMinutes(time)
  122. {
  123. // http://forum.sa-mp.com/showpost.php?p=3223897&postcount=11
  124. new string[15];//-2000000000:00 could happen, so make the string 15 chars to avoid any errors
  125. format(string, sizeof(string), "%02d:%02d", time / 60, time % 60);
  126. return string;
  127. }
  128.  
  129. GetWeaponModel(weaponid)
  130. {
  131. switch(weaponid)
  132. {
  133. case 1: return 331;
  134. case 2..8: return weaponid+331;
  135. case 9: return 341;
  136. case 10..15: return weaponid+311;
  137. case 16..18: return weaponid+326;
  138. case 22..29: return weaponid+324;
  139. case 30,31: return weaponid+325;
  140. case 32: return 372;
  141. case 33..45: return weaponid+324;
  142. case 46: return 371;
  143. }
  144.  
  145. return 18631;
  146. }
  147.  
  148. ReturnDropPickupModel(id)
  149. {
  150. new model = 18631;
  151.  
  152. switch(SupplyData[id][dropType])
  153. {
  154. case DROP_TYPE_WEAPON: model = GetWeaponModel(SupplyData[id][dropData]);
  155. case DROP_TYPE_AMMO: model = 19832;
  156. case DROP_TYPE_HEALTH: model = 11738;
  157. case DROP_TYPE_ARMOR: model = 1242;
  158. }
  159.  
  160. return model;
  161. }
  162.  
  163. ShowDropMenu(playerid)
  164. {
  165. new string[128];
  166. format(string, sizeof(string), "Request Weapons\t\nRequest Ammo\t{2ECC71}%s\nRequest Health Kit\t{2ECC71}%s\nRequest Body Armor\t{2ECC71}%s", formatInt(AMMO_PRICE), formatInt(HEALTH_PRICE), formatInt(ARMOR_PRICE));
  167. ShowPlayerDialog(playerid, DIALOG_DROP_MENU, DIALOG_STYLE_TABLIST, "Supply Drop", string, "Request", "Close");
  168. return 1;
  169. }
  170.  
  171. ShowWeaponsMenu(playerid)
  172. {
  173. new string[512], wname[24];
  174. format(string, sizeof(string), "Weapon\tPrice\n");
  175.  
  176. for(new i; i < sizeof(AvailableWeapons); i++)
  177. {
  178. GetWeaponName(AvailableWeapons[i][weaponID], wname, sizeof(wname));
  179. format(string, sizeof(string), "%s%s\t{2ECC71}%s\n", string, wname, formatInt(AvailableWeapons[i][weaponPrice]));
  180. }
  181.  
  182. ShowPlayerDialog(playerid, DIALOG_DROP_WEAPONS, DIALOG_STYLE_TABLIST_HEADERS, "Supply Drop » {FFFFFF}Weapons", string, "Request", "Back");
  183. return 1;
  184. }
  185.  
  186. ShowConfirmDialog(playerid)
  187. {
  188. if(GetPVarInt(playerid, "supply_Price") > GetPlayerMoney(playerid)) return 1;
  189. new string[128];
  190.  
  191. switch(GetPVarInt(playerid, "supply_ReqType"))
  192. {
  193. case DROP_TYPE_WEAPON:
  194. {
  195. new wname[24];
  196. GetWeaponName(AvailableWeapons[ GetPVarInt(playerid, "supply_WepIndex") ][weaponID], wname, sizeof(wname));
  197. format(string, sizeof(string), "{FFFFFF}You're about to order a supply drop for {F1C40F}%s.\n\n{FFFFFF}Price: {2ECC71}%s", wname, formatInt(GetPVarInt(playerid, "supply_Price")));
  198. }
  199.  
  200. case DROP_TYPE_AMMO:
  201. {
  202. format(string, sizeof(string), "{FFFFFF}You're about to order a supply drop for {F1C40F}Ammo.\n\n{FFFFFF}Price: {2ECC71}%s", formatInt(GetPVarInt(playerid, "supply_Price")));
  203. }
  204.  
  205. case DROP_TYPE_HEALTH:
  206. {
  207. format(string, sizeof(string), "{FFFFFF}You're about to order a supply drop for {F1C40F}Health Kit.\n\n{FFFFFF}Price: {2ECC71}%s", formatInt(GetPVarInt(playerid, "supply_Price")));
  208. }
  209.  
  210. case DROP_TYPE_ARMOR:
  211. {
  212. format(string, sizeof(string), "{FFFFFF}You're about to order a supply drop for {F1C40F}Body Armor.\n\n{FFFFFF}Price: {2ECC71}%s", formatInt(GetPVarInt(playerid, "supply_Price")));
  213. }
  214. }
  215.  
  216. ShowPlayerDialog(playerid, DIALOG_DROP_CONFIRM, DIALOG_STYLE_MSGBOX, "Supply Drop » {FFFFFF}Confirmation", string, "Confirm", "Cancel");
  217. return 1;
  218. }
  219.  
  220. public OnFilterScriptInit()
  221. {
  222. for(new i; i < MAX_DROPS; i++)
  223. {
  224. SupplyData[i][planeObj] = SupplyData[i][boxObj] = SupplyData[i][paraObj] = SupplyData[i][dropPickup] = SupplyData[i][dropTimer] = SupplyData[i][requestedBy] = -1;
  225. SupplyData[i][dropLabel] = Text3D: -1;
  226. }
  227.  
  228. return 1;
  229. }
  230.  
  231. public OnFilterScriptExit()
  232. {
  233. foreach(new i : SupplyDrops)
  234. {
  235. if(IsValidObject(SupplyData[i][planeObj])) DestroyObject(SupplyData[i][planeObj]);
  236. if(IsValidObject(SupplyData[i][boxObj])) DestroyObject(SupplyData[i][boxObj]);
  237. if(IsValidObject(SupplyData[i][paraObj])) DestroyObject(SupplyData[i][paraObj]);
  238.  
  239. if(SupplyData[i][dropPickup] != -1) DestroyPickup(SupplyData[i][dropPickup]);
  240. if(SupplyData[i][dropTimer] != -1) KillTimer(SupplyData[i][dropTimer]);
  241. if(SupplyData[i][dropLabel] != Text3D: -1) Delete3DTextLabel(SupplyData[i][dropLabel]);
  242. }
  243.  
  244. return 1;
  245. }
  246.  
  247. public OnPlayerDisconnect(playerid, reason)
  248. {
  249. foreach(new i : SupplyDrops) if(SupplyData[i][requestedBy] == playerid) SupplyData[i][requestedBy] = -1;
  250. return 1;
  251. }
  252.  
  253. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  254. {
  255. switch(dialogid)
  256. {
  257. case DIALOG_DROP_MENU:
  258. {
  259. if(!response) return 1;
  260. SetPVarInt(playerid, "supply_ReqType", listitem);
  261.  
  262. if(listitem == 0) {
  263. ShowWeaponsMenu(playerid);
  264. }else{
  265. new price;
  266. switch(listitem)
  267. {
  268. case DROP_TYPE_AMMO: price = AMMO_PRICE;
  269. case DROP_TYPE_HEALTH: price = HEALTH_PRICE;
  270. case DROP_TYPE_ARMOR: price = ARMOR_PRICE;
  271. }
  272.  
  273. if(price > GetPlayerMoney(playerid))
  274. {
  275. SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't afford this request.");
  276. return ShowDropMenu(playerid);
  277. }
  278.  
  279. SetPVarInt(playerid, "supply_Price", price);
  280. ShowConfirmDialog(playerid);
  281. }
  282.  
  283. return 1;
  284. }
  285.  
  286. case DIALOG_DROP_WEAPONS:
  287. {
  288. if(!response) return ShowDropMenu(playerid);
  289. new price = AvailableWeapons[listitem][weaponPrice];
  290. if(price > GetPlayerMoney(playerid))
  291. {
  292. SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't afford this weapon.");
  293. return ShowWeaponsMenu(playerid);
  294. }
  295.  
  296. SetPVarInt(playerid, "supply_WepIndex", listitem);
  297. SetPVarInt(playerid, "supply_Price", price);
  298. ShowConfirmDialog(playerid);
  299. return 1;
  300. }
  301.  
  302. case DIALOG_DROP_CONFIRM:
  303. {
  304. if(!response) return ShowDropMenu(playerid);
  305. new price = GetPVarInt(playerid, "supply_Price");
  306. if(price > GetPlayerMoney(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't afford this drop.");
  307. new cooldown = GetPVarInt(playerid, "supply_Cooldown");
  308. if(cooldown > gettime())
  309. {
  310. new string[72];
  311. format(string, sizeof(string), "ERROR: {FFFFFF}Please wait %s more to request a supply drop again.", ConvertToMinutes(cooldown - gettime()));
  312. return SendClientMessage(playerid, 0xE74C3CFF, string);
  313. }
  314.  
  315. new id = Iter_Free(SupplyDrops);
  316. if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't request a supply drop right now.");
  317. GivePlayerMoney(playerid, -price);
  318.  
  319. new Float: x, Float: y, Float: z;
  320. GetPlayerPos(playerid, x, y, z);
  321. GetPointZPos(x, y, z);
  322.  
  323. SupplyData[id][requestedBy] = playerid;
  324. SupplyData[id][dropType] = GetPVarInt(playerid, "supply_ReqType");
  325. SupplyData[id][dropData] = AvailableWeapons[ GetPVarInt(playerid, "supply_WepIndex") ][weaponID];
  326. SupplyData[id][dropTimer] = SetTimerEx("FlyPlane", PLANE_TIME * 1000, false, "ifffi", id, x, y, z, random(360));
  327. Iter_Add(SupplyDrops, id);
  328.  
  329. SendClientMessage(playerid, 0x3498DBFF, "PILOT: {FFFFFF}Request received.");
  330. SetPVarInt(playerid, "supply_Cooldown", gettime() + REQ_COOLDOWN * 60);
  331. return 1;
  332. }
  333. }
  334.  
  335. return 0;
  336. }
  337.  
  338. public OnObjectMoved(objectid)
  339. {
  340. switch(GetObjectModel(objectid))
  341. {
  342. case 1681:
  343. {
  344. // it's a plane, validate it & remove
  345. foreach(new i : SupplyDrops)
  346. {
  347. if(SupplyData[i][planeObj] == objectid)
  348. {
  349. DestroyObject(SupplyData[i][planeObj]);
  350. SupplyData[i][planeObj] = -1;
  351. break;
  352. }
  353. }
  354. }
  355.  
  356. case 2975:
  357. {
  358. // it's a supply drop, validate it, create pickup then remove
  359. foreach(new i : SupplyDrops)
  360. {
  361. if(SupplyData[i][boxObj] == objectid)
  362. {
  363. new Float: x, Float: y, Float: z, string[48];
  364. switch(SupplyData[i][dropType])
  365. {
  366. case DROP_TYPE_WEAPON:
  367. {
  368. new weap_name[24];
  369. GetWeaponName(SupplyData[i][dropData], weap_name, sizeof(weap_name));
  370. format(string, sizeof(string), "Supply Drop\n\n{FFFFFF}%s", weap_name);
  371. }
  372.  
  373. case DROP_TYPE_AMMO: format(string, sizeof(string), "Supply Drop\n\n{FFFFFF}Ammo");
  374. case DROP_TYPE_HEALTH: format(string, sizeof(string), "Supply Drop\n\n{FFFFFF}Health");
  375. case DROP_TYPE_ARMOR: format(string, sizeof(string), "Supply Drop\n\n{FFFFFF}Body Armor");
  376. }
  377.  
  378. GetObjectPos(objectid, x, y, z);
  379. SupplyData[i][dropPickup] = CreatePickup(ReturnDropPickupModel(i), 1, x, y, z + 0.85);
  380. SupplyData[i][dropLabel] = Create3DTextLabel(string, 0xF1C40FFF, x, y, z + 1.65, 10.0, 0, 1);
  381.  
  382. DestroyObject(SupplyData[i][paraObj]);
  383. DestroyObject(SupplyData[i][boxObj]);
  384. SupplyData[i][boxObj] = SupplyData[i][paraObj] = -1;
  385. SupplyData[i][dropTimer] = SetTimerEx("RemoveDrop", DROP_LIFE * 60000, false, "i", i);
  386.  
  387. if(IsPlayerConnected(SupplyData[i][requestedBy])) SendClientMessage(SupplyData[i][requestedBy], 0x3498DBFF, "SUPPLY DROP: {FFFFFF}Drop complete.");
  388. break;
  389. }
  390. }
  391. }
  392. }
  393.  
  394. return 1;
  395. }
  396.  
  397. public OnPlayerPickUpPickup(playerid, pickupid)
  398. {
  399. foreach(new i : SupplyDrops)
  400. {
  401. if(pickupid == SupplyData[i][dropPickup])
  402. {
  403. switch(SupplyData[i][dropType])
  404. {
  405. case DROP_TYPE_WEAPON: GivePlayerWeapon(playerid, SupplyData[i][dropData], AMMO_AMOUNT);
  406.  
  407. case DROP_TYPE_AMMO:
  408. {
  409. new weapon, ammo;
  410. for(new x = 2; x <= 7; x++)
  411. {
  412. GetPlayerWeaponData(playerid, x, weapon, ammo);
  413. SetPlayerAmmo(playerid, weapon, ammo + AMMO_AMOUNT);
  414. }
  415. }
  416.  
  417. case DROP_TYPE_HEALTH: SetPlayerHealth(playerid, 100.0);
  418. case DROP_TYPE_ARMOR: SetPlayerArmour(playerid, 100.0);
  419. }
  420.  
  421. DestroyPickup(SupplyData[i][dropPickup]);
  422. Delete3DTextLabel(SupplyData[i][dropLabel]);
  423. KillTimer(SupplyData[i][dropTimer]);
  424.  
  425. SupplyData[i][dropPickup] = SupplyData[i][requestedBy] = SupplyData[i][dropTimer] = -1;
  426. SupplyData[i][dropLabel] = Text3D: -1;
  427.  
  428. new next;
  429. Iter_SafeRemove(SupplyDrops, i, next);
  430. break;
  431. }
  432. }
  433.  
  434. return 1;
  435. }
  436.  
  437. forward FlyPlane(id, Float: x, Float: y, Float: z, angle);
  438. public FlyPlane(id, Float: x, Float: y, Float: z, angle)
  439. {
  440. SupplyData[id][planeObj] = CreateObject(1681, x + (DIST * -floatsin(-angle, degrees)), y + (DIST * -floatcos(-angle, degrees)), z + 75.0, 0.0, 0.0, angle);
  441. new time = MoveObject(SupplyData[id][planeObj], x + (DIST * floatsin(-angle, degrees)), y + (DIST * floatcos(-angle, degrees)), z + 75.0, 60.0);
  442.  
  443. SupplyData[id][dropTimer] = SetTimerEx("MakeDrop", floatround(time / 2.5), false, "ifff", id, x, y, z);
  444.  
  445. if(IsPlayerConnected(SupplyData[id][requestedBy])) SendClientMessage(SupplyData[id][requestedBy], 0x3498DBFF, "PILOT: {FFFFFF}I'm getting close.");
  446. return 1;
  447. }
  448.  
  449. forward MakeDrop(id, Float: x, Float: y, Float: z);
  450. public MakeDrop(id, Float: x, Float: y, Float: z)
  451. {
  452. new Float: plx, Float: ply, Float: plz;
  453. GetObjectPos(SupplyData[id][planeObj], plx, ply, plz);
  454.  
  455. SupplyData[id][boxObj] = CreateObject(2975, plx, ply, plz - 15.0, 0.0, 0.0, 0.0);
  456. SupplyData[id][paraObj] = CreateObject(18849, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  457. SetObjectMaterial(SupplyData[id][paraObj], 2, 19478, "signsurf", "sign", 0xFFFFFFFF);
  458. AttachObjectToObject(SupplyData[id][paraObj], SupplyData[id][boxObj], 0.0, -0.05, 7.5, 0.0, 0.0, 0.0);
  459. MoveObject(SupplyData[id][boxObj], x, y, z, 8.0);
  460.  
  461. if(IsPlayerConnected(SupplyData[id][requestedBy])) SendClientMessage(SupplyData[id][requestedBy], 0x3498DBFF, "PILOT: {FFFFFF}Supplies dropped.");
  462. return 1;
  463. }
  464.  
  465. forward RemoveDrop(id);
  466. public RemoveDrop(id)
  467. {
  468. DestroyPickup(SupplyData[id][dropPickup]);
  469. Delete3DTextLabel(SupplyData[id][dropLabel]);
  470.  
  471. SupplyData[id][dropPickup] = SupplyData[id][requestedBy] = SupplyData[id][dropTimer] = -1;
  472. SupplyData[id][dropLabel] = Text3D: -1;
  473.  
  474. Iter_Remove(SupplyDrops, id);
  475. return 1;
  476. }
  477.  
  478. CMD:drop(playerid, params[])
  479. {
  480. if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't use this command in a vehicle.");
  481. new cooldown = GetPVarInt(playerid, "supply_Cooldown");
  482. if(cooldown > gettime())
  483. {
  484. new string[72];
  485. format(string, sizeof(string), "ERROR: {FFFFFF}Please wait %s more to request a supply drop again.", ConvertToMinutes(cooldown - gettime()));
  486. return SendClientMessage(playerid, 0xE74C3CFF, string);
  487. }
  488.  
  489. ShowDropMenu(playerid);
  490. return 1;
  491. }
Advertisement
Add Comment
Please, Sign In to add comment