cratesystem.pwn 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945
  1. /*
  2. /$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$
  3. | $$$ | $$ /$$__ $$ | $$__ $$| $$__ $$
  4. | $$$$| $$| $$ \__/ | $$ \ $$| $$ \ $$
  5. | $$ $$ $$| $$ /$$$$ /$$$$$$| $$$$$$$/| $$$$$$$/
  6. | $$ $$$$| $$|_ $$|______/| $$__ $$| $$____/
  7. | $$\ $$$| $$ \ $$ | $$ \ $$| $$
  8. | $$ \ $$| $$$$$$/ | $$ | $$| $$
  9. |__/ \__/ \______/ |__/ |__/|__/
  10. Crate System (Re-done)
  11. by Shane Roberts
  12. Next Generation Gaming, LLC
  13. (created by Next Generation Gaming Development Team)
  14. * Copyright (c) 2016, Next Generation Gaming, LLC
  15. *
  16. * All rights reserved.
  17. *
  18. * Redistribution and use in source and binary forms, with or without modification,
  19. * are not permitted in any case.
  20. *
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  26. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <YSI\y_hooks>
  35. new
  36. CrateBeingProcessed[MAX_CRATE_FACILITY],
  37. CrateBeingDelivered[MAX_GROUPS],
  38. CrateFacilityRaid[MAX_CRATE_FACILITY];
  39. hook OnGameModeInit() {
  40. for(new i = 0; i < MAX_CRATE_FACILITY; i++) {
  41. AdminOpened[i] = 0; // Disable by default.
  42. CrateBeingProcessed[i] = 0;
  43. CrateFacility[i][cfTextID] = Text3D: -1;
  44. CrateFacility[i][cfPickupID] = -1;
  45. CrateFacility[i][cfMapIcon] = -1;
  46. CrateFacilityRaid[i] = 0;
  47. }
  48. for(new c = 0; c < MAX_CRATES; c++) {
  49. BeingMoved[c] = INVALID_PLAYER_ID;
  50. CrateBox[c][cbObject] = -1;
  51. CrateBox[c][cbTextID] = Text3D: -1;
  52. }
  53. return 1;
  54. }
  55. hook OnPlayerConnect(playerid) {
  56. CarryCrate[playerid] = -1;
  57. return 1;
  58. }
  59. hook OnPlayerDisconnect(playerid, reason) {
  60. if(CarryCrate[playerid] != -1) {
  61. PlayerCarryCrate(playerid, CarryCrate[playerid], -1, 1);
  62. }
  63. return 1;
  64. }
  65. hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  66. if(IsKeyJustDown(KEY_FIRE, newkeys, oldkeys)) {
  67. if(CarryCrate[playerid] >= 0) {
  68. ApplyAnimation(playerid, "CARRY", "putdwn", 4.1, 0, 0, 0, 0, 0, 1);
  69. SetTimerEx("PlayerCarryCrate", 1000, false, "iiii", playerid, CarryCrate[playerid], -1, 1);
  70. }
  71. }
  72. return 1;
  73. }
  74. hook OnPlayerStateChange(playerid, newstate, oldstate) {
  75. if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER) {
  76. if(CarryCrate[playerid] >= 0) {
  77. SendClientMessageEx(playerid, COLOR_GREY, "You can't be in any vehicles whilst carrying a crate!");
  78. return RemovePlayerFromVehicle(playerid);
  79. }
  80. }
  81. return 1;
  82. }
  83. hook OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) {
  84. if(CarryCrate[playerid] >= 0) {
  85. new Float:pos[3];
  86. GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  87. SetPlayerPos(playerid, pos[0], pos[1], pos[2]+1.3);
  88. PlayerPlaySound(playerid, 1130, pos[0], pos[1], pos[2]+1.3);
  89. SendClientMessageEx(playerid, COLOR_GREY, "You can't enter any vehicles whilst carrying a crate!");
  90. return 1;
  91. }
  92. return 1;
  93. }
  94. stock LoadCrateOrders() {
  95. mysql_tquery(MainPipeline, "SELECT * FROM `crate_orders`", "OnLoadCrateOrders", "");
  96. }
  97. forward OnLoadCrateOrders();
  98. public OnLoadCrateOrders()
  99. {
  100. new i, rows;
  101. cache_get_row_count(rows);
  102. while(i < rows)
  103. {
  104. if (!(0 <= i < MAX_GROUPS)) break;
  105. cache_get_value_name_int(i, "id", CrateOrder[i][coGroup]);
  106. cache_get_value_name_int(i, "Facility", CrateOrder[i][coFacility]);
  107. cache_get_value_name_int(i, "Crates", CrateOrder[i][coCrates]);
  108. cache_get_value_name_int(i, "PerCrate", CrateOrder[i][coPerCrate]);
  109. cache_get_value_name(i, "OrderBy", CrateOrder[i][coOrderBy], MAX_PLAYER_NAME);
  110. cache_get_value_name_int(i, "Delivered", CrateOrder[i][coDelivered]);
  111. cache_get_value_name_int(i, "Status", CrateOrder[i][coStatus]);
  112. cache_get_value_name_int(i, "Time", CrateOrder[i][coTime]);
  113. i++;
  114. }
  115. return 1;
  116. }
  117. stock SaveOrder(i) {
  118. new query[2048];
  119. format(query, 2048, "UPDATE `crate_orders` SET ");
  120. SaveInteger(query, "crate_orders", i+1, "Facility", CrateOrder[i][coFacility]);
  121. SaveInteger(query, "crate_orders", i+1, "Crates", CrateOrder[i][coCrates]);
  122. SaveInteger(query, "crate_orders", i+1, "PerCrate", CrateOrder[i][coPerCrate]);
  123. SaveString(query, "crate_orders", i+1, "OrderBy", CrateOrder[i][coOrderBy]);
  124. SaveInteger(query, "crate_orders", i+1, "Delivered", CrateOrder[i][coDelivered]);
  125. SaveInteger(query, "crate_orders", i+1, "Status", CrateOrder[i][coStatus]);
  126. SaveInteger(query, "crate_orders", i+1, "Time", CrateOrder[i][coTime]);
  127. SQLUpdateFinish(query, "crate_orders", i+1);
  128. return 1;
  129. }
  130. stock LoadCrateBoxes()
  131. {
  132. printf("[Dynamic Crate Boxes] Loading Dynamic Crate Boxes from the database, please wait...");
  133. mysql_tquery(MainPipeline, "SELECT * FROM `crates`", "OnLoadCrateBoxes", "");
  134. }
  135. forward OnLoadCrateBoxes();
  136. public OnLoadCrateBoxes()
  137. {
  138. new i, rows, number[16];
  139. cache_get_row_count(rows);
  140. while(i < rows)
  141. {
  142. cache_get_value_name_int(i, "Facility", CrateBox[i][cbFacility]);
  143. cache_get_value_name_int(i, "Group", CrateBox[i][cbGroup]);
  144. cache_get_value_name_float(i, "CrateX", CrateBox[i][cbPos][0]);
  145. cache_get_value_name_float(i, "CrateY", CrateBox[i][cbPos][1]);
  146. cache_get_value_name_float(i, "CrateZ", CrateBox[i][cbPos][2]);
  147. cache_get_value_name_int(i, "Int", CrateBox[i][cbInt]);
  148. cache_get_value_name_int(i, "InVehicle", CrateBox[i][cbInVeh]);
  149. cache_get_value_name_int(i, "OnVehicle", CrateBox[i][cbOnVeh]);
  150. cache_get_value_name_int(i, "VW", CrateBox[i][cbVw]);
  151. cache_get_value_name_int(i, "Materials", CrateBox[i][cbMats]);
  152. for(new w = 0; w < 16; w++) {
  153. format(number, sizeof(number), "Gun%d", w+1);
  154. cache_get_value_name_int(i, number, CrateBox[i][cbWep][w]);
  155. format(number, sizeof(number), "GunAmount%d", w+1);
  156. cache_get_value_name_int(i, number, CrateBox[i][cbWepAmount][w]);
  157. }
  158. cache_get_value_name(i, "PlacedBy", CrateBox[i][cbPlacedBy], MAX_PLAYER_NAME);
  159. cache_get_value_name_int(i, "Lifespan", CrateBox[i][cbLifespan]);
  160. cache_get_value_name_int(i, "Transfer", CrateBox[i][cbTransfer]);
  161. cache_get_value_name_int(i, "DoorID", CrateBox[i][cbDoor]);
  162. cache_get_value_name_int(i, "DoorType", CrateBox[i][cbDoorType]);
  163. cache_get_value_name_int(i, "Price", CrateBox[i][cbPrice]);
  164. cache_get_value_name_int(i, "Paid", CrateBox[i][cbPaid]);
  165. cache_get_value_name_int(i, "Active", CrateBox[i][cbActive]);
  166. UpdateCrateBox(i);
  167. i++;
  168. }
  169. if(i > 0) printf("[Dynamic Crate Boxes] %d dynamic Crate Boxes have been loaded.", i);
  170. else printf("[Dynamic Crate Boxes] There are no dynamic crate boxes to load.");
  171. return 1;
  172. }
  173. stock UpdateCrateBox(id)
  174. {
  175. new string[256];
  176. if(IsValidDynamicObject(CrateBox[id][cbObject])) DestroyDynamicObject(CrateBox[id][cbObject]), CrateBox[id][cbObject] = -1;
  177. if(IsValidDynamic3DTextLabel(CrateBox[id][cbTextID])) DestroyDynamic3DTextLabel(CrateBox[id][cbTextID]), CrateBox[id][cbTextID] = Text3D: -1;
  178. if(!CrateBox[id][cbActive] || CrateBox[id][cbInVeh] != -1) return 1;
  179. /*
  180. foreach(new p: Player) {
  181. if(CarryCrate[p] == id) return 1;
  182. }*/
  183. if(BeingMoved[id] != INVALID_PLAYER_ID) return 1;
  184. //if(CrateBox[id][cbOnVeh] != -1) return CrateVehCheck(CrateBox[id][cbOnVeh]);
  185. if(CrateBox[id][cbOnVeh] != -1) {
  186. if(CrateVehicle[CrateBox[id][cbOnVeh]][cvCrate] != id) return DestroyCrate(id);
  187. }
  188. if(CrateBox[id][cbGroup] != -1 && !ValidGroup(CrateBox[id][cbGroup])) return DestroyCrate(id);
  189. if(CrateBox[id][cbGroup] == -1) {
  190. format(string, sizeof(string), "{FFFF00}---- ID: {FF8000}%d\n{FFFF00}Time Remaining: {FF8000}00:00:00\n{FFFF00}Placed By: {FF8000}%s", id, CrateBox[id][cbPlacedBy]);
  191. } else {
  192. format(string, sizeof(string), "{FFFF00}ID: {FF8000}%d\n{FFFF00}Crate Owner: {FF8000}%s\n{FFFF00}Placed By: {FF8000}%s", id, arrGroupData[CrateBox[id][cbGroup]][g_szGroupName], CrateBox[id][cbPlacedBy]);
  193. }
  194. CrateBox[id][cbTextID] = CreateDynamic3DTextLabel(string, COLOR_YELLOW, CrateBox[id][cbPos][0], CrateBox[id][cbPos][1], CrateBox[id][cbPos][2]+1.5, 20.0, .testlos = 1, .worldid = CrateBox[id][cbVw], .interiorid = CrateBox[id][cbInt], .streamdistance = 20.0);
  195. CrateBox[id][cbObject] = CreateDynamicObject(964, CrateBox[id][cbPos][0], CrateBox[id][cbPos][1], CrateBox[id][cbPos][2], 0.00000000, 0.00000000, 0.00000000, CrateBox[id][cbVw], CrateBox[id][cbInt]);
  196. return 1;
  197. }
  198. stock SaveCrate(i) {
  199. new query[2048], wep[16];
  200. format(query, 2048, "UPDATE `crates` SET ");
  201. SaveInteger(query, "crates", i+1, "Facility", CrateBox[i][cbFacility]);
  202. SaveInteger(query, "crates", i+1, "Group", CrateBox[i][cbGroup]);
  203. SaveFloat(query, "crates", i+1, "CrateX", CrateBox[i][cbPos][0]);
  204. SaveFloat(query, "crates", i+1, "CrateY", CrateBox[i][cbPos][1]);
  205. SaveFloat(query, "crates", i+1, "CrateZ", CrateBox[i][cbPos][2]);
  206. SaveInteger(query, "crates", i+1, "Int", CrateBox[i][cbInt]);
  207. SaveInteger(query, "crates", i+1, "InVehicle", CrateBox[i][cbInVeh]);
  208. SaveInteger(query, "crates", i+1, "OnVehicle", CrateBox[i][cbOnVeh]);
  209. SaveInteger(query, "crates", i+1, "VW", CrateBox[i][cbVw]);
  210. SaveInteger(query, "crates", i+1, "Materials", CrateBox[i][cbMats]);
  211. for(new w = 0; w < 16; w++) {
  212. format(wep, sizeof(wep), "Gun%d", w+1);
  213. SaveInteger(query, "crates", i+1, wep, CrateBox[i][cbWep][w]);
  214. format(wep, sizeof(wep), "GunAmount%d", w+1);
  215. SaveInteger(query, "crates", i+1, wep, CrateBox[i][cbWepAmount][w]);
  216. }
  217. SaveString(query, "crates", i+1, "PlacedBy", CrateBox[i][cbPlacedBy]);
  218. SaveInteger(query, "crates", i+1, "Lifespan", CrateBox[i][cbLifespan]);
  219. SaveInteger(query, "crates", i+1, "Transfer", CrateBox[i][cbTransfer]);
  220. SaveInteger(query, "crates", i+1, "DoorID", CrateBox[i][cbDoor]);
  221. SaveInteger(query, "crates", i+1, "DoorType", CrateBox[i][cbDoorType]);
  222. SaveInteger(query, "crates", i+1, "Price", CrateBox[i][cbPrice]);
  223. SaveInteger(query, "crates", i+1, "Paid", CrateBox[i][cbPaid]);
  224. SaveInteger(query, "crates", i+1, "Active", CrateBox[i][cbActive]);
  225. SQLUpdateFinish(query, "crates", i+1);
  226. return 1;
  227. }
  228. stock LoadCrateFacilities()
  229. {
  230. printf("[Dynamic Crate Facility] Loading Dynamic Crate Facilities from the database, please wait...");
  231. mysql_tquery(MainPipeline, "SELECT * FROM `crate_facility`", "OnLoadCrateFacilities", "");
  232. }
  233. forward OnLoadCrateFacilities();
  234. public OnLoadCrateFacilities()
  235. {
  236. new i, rows;
  237. cache_get_row_count(rows);
  238. while(i < rows)
  239. {
  240. cache_get_value_name_int(i, "id", CrateFacility[i][cfId]);
  241. cache_get_value_name(i, "Name", CrateFacility[i][cfName], 32);
  242. cache_get_value_name_int(i, "Group", CrateFacility[i][cfGroup]);
  243. cache_get_value_name_float(i, "Posx", CrateFacility[i][cfPos][0]);
  244. cache_get_value_name_float(i, "Posy", CrateFacility[i][cfPos][1]);
  245. cache_get_value_name_float(i, "Posz", CrateFacility[i][cfPos][2]);
  246. cache_get_value_name_float(i, "Posr", CrateFacility[i][cfPos][3]);
  247. cache_get_value_name_int(i, "Int", CrateFacility[i][cfInt]);
  248. cache_get_value_name_int(i, "Vw", CrateFacility[i][cfVw]);
  249. cache_get_value_name_int(i, "Prodmax", CrateFacility[i][cfProdMax]);
  250. cache_get_value_name_int(i, "ProdPrep", CrateFacility[i][cfProdPrep]);
  251. cache_get_value_name_int(i, "ProdReady", CrateFacility[i][cfProdReady]);
  252. cache_get_value_name_int(i, "ProdTimer", CrateFacility[i][cfProdTimer]);
  253. cache_get_value_name_int(i, "ProdStatus", CrateFacility[i][cfProdStatus]);
  254. cache_get_value_name_int(i, "ProdCost", CrateFacility[i][cfProdCost]);
  255. cache_get_value_name_int(i, "ProdMulti", CrateFacility[i][cfProdMulti]);
  256. cache_get_value_name_int(i, "RaidTimer", CrateFacility[i][cfRaidTimer]);
  257. cache_get_value_name_int(i, "Cooldown", CrateFacility[i][cfCooldown]);
  258. cache_get_value_name_int(i, "Raidable", CrateFacility[i][cfRaidable]);
  259. cache_get_value_name_int(i, "Active", CrateFacility[i][cfActive]);
  260. cache_get_value_name_int(i, "Timer", CrateFacility[i][cfTimer]);
  261. UpdateFacility(i);
  262. if(CrateFacility[i][cfRaidTimer] > 0) TriggerGates(i);
  263. i++;
  264. }
  265. if(i > 0) printf("[Dynamic Crate Facility] %d dynamic Crate Facilities have been loaded.", i);
  266. else printf("[Dynamic Crate Facility] No dynamic Crate Facilities have been loaded.");
  267. return 1;
  268. }
  269. stock UpdateFacility(id)
  270. {
  271. new string[256];
  272. //964 box | 11 - Map Icon
  273. if(IsValidDynamicObject(CrateFacility[id][cfPickupID])) DestroyDynamicObject(CrateFacility[id][cfPickupID]), CrateFacility[id][cfPickupID] = -1;
  274. if(IsValidDynamic3DTextLabel(CrateFacility[id][cfTextID])) DestroyDynamic3DTextLabel(CrateFacility[id][cfTextID]), CrateFacility[id][cfTextID] = Text3D: -1;
  275. if(IsValidDynamicMapIcon(CrateFacility[id][cfMapIcon])) DestroyDynamicMapIcon(CrateFacility[id][cfMapIcon]), CrateFacility[id][cfMapIcon] = -1;
  276. if(CrateFacility[id][cfPos][0] == 0.0) return 1;
  277. CrateFacility[id][cfMapIcon] = CreateDynamicMapIcon(CrateFacility[id][cfPos][0], CrateFacility[id][cfPos][1], CrateFacility[id][cfPos][2], 11, 0, CrateFacility[id][cfVw], CrateFacility[id][cfInt], .streamdistance = 1000.0, .style = MAPICON_GLOBAL);
  278. // Box Object.
  279. CrateFacility[id][cfPickupID] = CreateDynamicObject(964, CrateFacility[id][cfPos][0], CrateFacility[id][cfPos][1], CrateFacility[id][cfPos][2], 0.00000000, 0.00000000, CrateFacility[id][cfPos][3], CrateFacility[id][cfVw], CrateFacility[id][cfInt]);
  280. format(string, sizeof(string), "{FFFF00}%s (ID: {1FBDFF}%d{FFFF00})\n{FFFF00}Crates Available: {1FBDFF}%d/%d", CrateFacility[id][cfName], id, CrateFacility[id][cfProdReady], CrateFacility[id][cfProdMax]);
  281. CrateFacility[id][cfTextID] = CreateDynamic3DTextLabel(string, COLOR_YELLOW, CrateFacility[id][cfPos][0], CrateFacility[id][cfPos][1], CrateFacility[id][cfPos][2]+1.5, 20.0, .testlos = 1, .worldid = CrateFacility[id][cfVw], .interiorid = CrateFacility[id][cfInt], .streamdistance = 20.0);
  282. return 1;
  283. }
  284. stock SaveFacility(i) {
  285. new query[2048];
  286. format(query, 2048, "UPDATE `crate_facility` SET ");
  287. SaveInteger(query, "crate_facility", i+1, "Group", CrateFacility[i][cfGroup]);
  288. SaveString(query, "crate_facility", i+1, "Name", CrateFacility[i][cfName]);
  289. SaveFloat(query, "crate_facility", i+1, "Posx", CrateFacility[i][cfPos][0]);
  290. SaveFloat(query, "crate_facility", i+1, "Posy", CrateFacility[i][cfPos][1]);
  291. SaveFloat(query, "crate_facility", i+1, "Posz", CrateFacility[i][cfPos][2]);
  292. SaveFloat(query, "crate_facility", i+1, "Posr", CrateFacility[i][cfPos][3]);
  293. SaveInteger(query, "crate_facility", i+1, "Int", CrateFacility[i][cfInt]);
  294. SaveInteger(query, "crate_facility", i+1, "Vw", CrateFacility[i][cfVw]);
  295. SaveInteger(query, "crate_facility", i+1, "Prodmax", CrateFacility[i][cfProdMax]);
  296. SaveInteger(query, "crate_facility", i+1, "ProdPrep", CrateFacility[i][cfProdPrep]);
  297. SaveInteger(query, "crate_facility", i+1, "ProdReady", CrateFacility[i][cfProdReady]);
  298. SaveInteger(query, "crate_facility", i+1, "ProdTimer", CrateFacility[i][cfProdTimer]);
  299. SaveInteger(query, "crate_facility", i+1, "ProdStatus", CrateFacility[i][cfProdStatus]);
  300. SaveInteger(query, "crate_facility", i+1, "ProdCost", CrateFacility[i][cfProdCost]);
  301. SaveInteger(query, "crate_facility", i+1, "ProdMulti", CrateFacility[i][cfProdMulti]);
  302. SaveInteger(query, "crate_facility", i+1, "RaidTimer", CrateFacility[i][cfRaidTimer]);
  303. SaveInteger(query, "crate_facility", i+1, "Cooldown", CrateFacility[i][cfCooldown]);
  304. SaveInteger(query, "crate_facility", i+1, "Raidable", CrateFacility[i][cfRaidable]);
  305. SaveInteger(query, "crate_facility", i+1, "Active", CrateFacility[i][cfActive]);
  306. SaveInteger(query, "crate_facility", i+1, "Timer", CrateFacility[i][cfTimer]);
  307. SQLUpdateFinish(query, "crate_facility", i+1);
  308. return 1;
  309. }
  310. task UpdateFacilityCrates[1000]()
  311. {
  312. for(new i = 0; i < MAX_CRATE_FACILITY; i++)
  313. {
  314. if(CrateFacility[i][cfId] > 0 && CrateFacility[i][cfActive] == 1) {
  315. if(CrateFacility[i][cfProdPrep] > 0 && CrateFacility[i][cfProdStatus] == 1 && CrateFacility[i][cfProdTimer] > 0) {
  316. if(CrateFacility[i][cfTimer] > 0) CrateFacility[i][cfTimer]--;
  317. if(!CrateFacility[i][cfTimer]) {
  318. if(CrateFacility[i][cfProdReady] < CrateFacility[i][cfProdMax]) {
  319. ++CrateFacility[i][cfProdReady];
  320. --CrateFacility[i][cfProdPrep];
  321. CrateFacility[i][cfTimer] = CrateFacility[i][cfProdTimer];
  322. }
  323. }
  324. }
  325. if(CrateFacility[i][cfRaidable]) {
  326. if((CrateFacility[i][cfCooldown] - 300) == gettime() && CrateFacility[i][cfRaidTimer] == 0) {
  327. CrateFacilityRaid[i] = 1;
  328. foreach(new g: Player) {
  329. if(PlayerInfo[g][pMember] == CrateFacility[i][cfGroup]) {
  330. SendClientMessageEx(g, COLOR_LIGHTRED, "%s: We're about to go into production mode be advised.", CrateFacility[i][cfName]);
  331. SendClientMessageEx(g, COLOR_YELLOW, "** You have 5 minutes to prepare for a facility raid. **");
  332. }
  333. }
  334. }
  335. if(CrateFacility[i][cfCooldown] < gettime() && CrateFacility[i][cfRaidTimer] == 0) {
  336. CrateFacility[i][cfRaidTimer] = gettime()+5400; // 1 hour 30 minutes
  337. CrateFacilityRaid[i] = 1; // Just incase an admin sets the raid time lower than 5 min interval
  338. SaveFacility(i);
  339. TriggerGates(i);
  340. foreach(new g: Player) {
  341. if(IsACriminal(g)) {
  342. SendClientMessageEx(g, COLOR_YELLOW, "SMS: Word on the street is that %s facility is processing crates!, Sender: Unknown.", CrateFacility[i][cfName]);
  343. SendClientMessageEx(g, COLOR_YELLOW, "** You have 1 hour 30 minutes to raid the facility before it goes into a cooldown. **");
  344. }
  345. if(PlayerInfo[g][pMember] == CrateFacility[i][cfGroup]) {
  346. SendClientMessageEx(g, COLOR_LIGHTRED, "%s: We're now processing crates!", CrateFacility[i][cfName]);
  347. SendClientMessageEx(g, COLOR_YELLOW, "** You have 1 hour 30 minutes to protect the facility before it goes into a cooldown. **");
  348. }
  349. }
  350. }
  351. if((CrateFacility[i][cfRaidTimer] - 300) == gettime() && CrateFacility[i][cfRaidTimer] != 0) {
  352. foreach(new g: Player) {
  353. if(IsACriminal(g)) {
  354. SendClientMessageEx(g, COLOR_YELLOW, "** You have 5 minutes remaining before all gates are closed! **", CrateFacility[i][cfName]);
  355. }
  356. if(PlayerInfo[g][pMember] == CrateFacility[i][cfGroup]) {
  357. SendClientMessageEx(g, COLOR_LIGHTRED, "%s: Crate production is nearly complete!", CrateFacility[i][cfName]);
  358. SendClientMessageEx(g, COLOR_YELLOW, "** You have 5 minutes remaining to protect the facility until the facility goes into lockdown. **");
  359. }
  360. }
  361. }
  362. if(CrateFacility[i][cfRaidTimer] < gettime() && CrateFacility[i][cfRaidTimer] != 0) {
  363. CrateFacility[i][cfCooldown] = gettime()+10800; // 3 hours
  364. CrateFacility[i][cfRaidTimer] = 0;
  365. CrateFacilityRaid[i] = 0;
  366. SaveFacility(i);
  367. TriggerGates(i, 0);
  368. foreach(new g: Player) {
  369. if(IsACriminal(g)) {
  370. SendClientMessageEx(g, COLOR_YELLOW, "SMS: %s facility is now on lockdown. (( Cooldown Period )), Sender: Unknown.", CrateFacility[i][cfName]);
  371. SendClientMessageEx(g, COLOR_YELLOW, "** You can no longer raid the facility, it'll be on cooldown for a random time period. **", CrateFacility[i][cfName]);
  372. }
  373. if(PlayerInfo[g][pMember] == CrateFacility[i][cfGroup]) {
  374. SendClientMessageEx(g, COLOR_LIGHTRED, "%s: Crate Production at this facility has finished!", CrateFacility[i][cfName]);
  375. SendClientMessageEx(g, COLOR_YELLOW, "** This facility can no longer be raided, it'll be on a cooldown period for a random amount of time. **");
  376. }
  377. }
  378. }
  379. }
  380. }
  381. if((CrateFacility[i][cfProdReady] >= CrateFacility[i][cfProdMax]) && CrateFacility[i][cfProdPrep] > 0) {
  382. CrateFacility[i][cfProdPrep] = 0;
  383. }
  384. FacilityBoxUpdate(i);
  385. }
  386. for(new c = 0; c < MAX_CRATES; c++)
  387. {
  388. if(CrateBox[c][cbActive] == 1 && CrateBox[c][cbFacility] != -1 && CrateBox[c][cbGroup] == -1) {
  389. if(CrateBox[c][cbLifespan] > 0) CrateBox[c][cbLifespan]--;
  390. if(!CrateBox[c][cbLifespan]) {
  391. DestroyCrate(c);
  392. }
  393. CrateBoxUpdate(c);
  394. }
  395. }
  396. foreach(new p: Player) {
  397. if(CarryCrate[p] >= 0) {
  398. if(PlayerHoldingObject[p][8] != 0 || IsPlayerAttachedObjectSlotUsed(p, 8))
  399. RemovePlayerAttachedObject(p, 8), PlayerHoldingObject[p][8] = 0;
  400. SetPlayerAttachedObject(p, 8, 964, 1, -0.071, 0.536, -0.026999, -2.19999, 87.1999, 0.699999, 0.479999, 0.538999, 0.419999);
  401. if(GetPlayerSpecialAction(p) != SPECIAL_ACTION_CARRY) SetPlayerSpecialAction(p, SPECIAL_ACTION_CARRY);
  402. }
  403. if(CarryCrate[p] >= 0) {
  404. if(PlayerInfo[p][pHospital] > 0 || PlayerInfo[p][pJailTime] > 0 || GetPVarType(p, "IsInArena") || GetPVarInt(p, "EventToken") != 0) {
  405. PlayerCarryCrate(p, CarryCrate[p], -1, 4);
  406. }
  407. if(PlayerCuffed[p] != 0 || GetPVarInt(p, "Injured") != 0) {
  408. PlayerCarryCrate(p, CarryCrate[p], -1, 5);
  409. }
  410. }
  411. }
  412. }
  413. forward CrateBoxUpdate(id);
  414. public CrateBoxUpdate(id) {
  415. new string[256];
  416. if(IsValidDynamic3DTextLabel(CrateBox[id][cbTextID])) {
  417. format(string, sizeof(string), "{FFFF00}%s (ID: {FF8000}%d{FFFF00})\n{FFFF00}Time Remaining: {FF8000}%s\n{FFFF00}Placed By: {FF8000}%s\n{FFFF00}Materials: {FF8000}%d/50", CrateFacility[CrateBox[id][cbFacility]][cfName], id, TimeConvert(CrateBox[id][cbLifespan]), CrateBox[id][cbPlacedBy], CrateBox[id][cbMats]);
  418. //format(string, sizeof(string), "{FFFF00}ID: {FF8000}%d\n{FFFF00}Time Remaining: {FF8000}%s\n{FFFF00}Placed By: {FF8000}%s", id, TimeConvert(CrateBox[id][cbLifespan]), CrateBox[id][cbPlacedBy]);
  419. UpdateDynamic3DTextLabelText(CrateBox[id][cbTextID], COLOR_ORANGE, string);
  420. }
  421. return 1;
  422. }
  423. forward FacilityBoxUpdate(id);
  424. public FacilityBoxUpdate(id) {
  425. new string[256];
  426. if(CrateFacility[id][cfActive] == 1) {
  427. if(CrateFacility[id][cfProdStatus] == 1 && CrateFacility[id][cfProdTimer] > 0) {
  428. if(CrateFacility[id][cfProdReady] < CrateFacility[id][cfProdMax] && CrateFacility[id][cfProdPrep] > 0) {
  429. format(string, sizeof(string), "{FFFF00}%s (ID: {FF8000}%d{FFFF00})\n{FFFF00}Crates Available: {FF8000}%d/%d\n{FFFF00}Next Production in: {FF8000}%s", CrateFacility[id][cfName], id, CrateFacility[id][cfProdReady], CrateFacility[id][cfProdMax], STimeConvert(CrateFacility[id][cfTimer]));
  430. }
  431. else if(CrateFacility[id][cfProdReady] < CrateFacility[id][cfProdMax] && CrateFacility[id][cfProdPrep] == 0) {
  432. format(string, sizeof(string), "{FFFF00}%s (ID: {FF8000}%d{FFFF00})\n{FFFF00}Crates Available: {FF8000}%d/%d\n{FFFF00}Production stopped all crates\nhave been exported.", CrateFacility[id][cfName], id, CrateFacility[id][cfProdReady], CrateFacility[id][cfProdMax]);
  433. }
  434. else format(string, sizeof(string), "{FFFF00}%s (ID: {FF8000}%d{FFFF00})\n{FFFF00}Crates Available: {FF8000}%d/%d", CrateFacility[id][cfName], id, CrateFacility[id][cfProdReady], CrateFacility[id][cfProdMax]);
  435. }
  436. else format(string, sizeof(string), "{FFFF00}%s (ID: {FF8000}%d{FFFF00})\n{FFFF00}Crates Available: {FF8000}%d/%d\n{FFFF00}Production has been paused\nno crates will be manufactured.", CrateFacility[id][cfName], id, CrateFacility[id][cfProdReady], CrateFacility[id][cfProdMax]);
  437. } else {
  438. format(string, sizeof(string), "{FFFF00}%s (ID: {FF8000}%d{FFFF00})\n{FFFF00}Production has been stopped.\nThis facility is currently closed.", CrateFacility[id][cfName], id);
  439. }
  440. UpdateDynamic3DTextLabelText(CrateFacility[id][cfTextID], COLOR_YELLOW, string);
  441. return 1;
  442. }
  443. stock FetchFacility(playerid, &facility, Float:range)
  444. {
  445. facility = -1;
  446. for(new f = 0; f < MAX_CRATE_FACILITY; f++)
  447. {
  448. if(IsPlayerInRangeOfPoint(playerid,range,CrateFacility[f][cfPos][0], CrateFacility[f][cfPos][1], CrateFacility[f][cfPos][2]))
  449. {
  450. if(GetPlayerVirtualWorld(playerid) == CrateFacility[f][cfVw] && GetPlayerInterior(playerid) == CrateFacility[f][cfInt]) {
  451. facility = f;
  452. }
  453. break;
  454. }
  455. }
  456. }
  457. stock GetCrateBox(playerid, &box, Float:range)
  458. {
  459. box = -1;
  460. for(new b = 0; b < MAX_CRATES; b++)
  461. {
  462. if(BeingMoved[b] == INVALID_PLAYER_ID && CrateBox[b][cbOnVeh] == -1 && CrateBox[b][cbInVeh] == -1 && CrateBox[b][cbActive]) {
  463. if(IsPlayerInRangeOfPoint(playerid,range,CrateBox[b][cbPos][0], CrateBox[b][cbPos][1], CrateBox[b][cbPos][2]))
  464. {
  465. if(GetPlayerVirtualWorld(playerid) == CrateBox[b][cbVw] && GetPlayerInterior(playerid) == CrateBox[b][cbInt]) {
  466. box = b;
  467. }
  468. break;
  469. }
  470. }
  471. }
  472. }
  473. // Used for tracking / transferring weapons from and to the locker
  474. stock GetGroupCrate(playerid, &box) {
  475. box = -1;
  476. for(new b = 0; b < MAX_CRATES; b++)
  477. {
  478. if(PlayerInfo[playerid][pMember] == CrateBox[b][cbGroup])
  479. {
  480. box = b;
  481. break;
  482. }
  483. }
  484. }
  485. forward LoadForklift(playerid, facility, boxid, vehicle);
  486. public LoadForklift(playerid, facility, boxid, vehicle) {
  487. szMiscArray[0] = 0;
  488. new string[128];
  489. SetPVarInt(playerid, "LoadForkliftTime", GetPVarInt(playerid, "LoadForkliftTime")-1);
  490. format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~w~%d seconds left", GetPVarInt(playerid, "LoadForkliftTime"));
  491. GameTextForPlayer(playerid, string, 1100, 3);
  492. if(GetPVarInt(playerid, "LoadForkliftTime") > 0) SetTimerEx("LoadForklift", 1000, 0, "iiii", playerid, facility, boxid, vehicle);
  493. if(GetPVarInt(playerid, "LoadForkliftTime") <= 0)
  494. {
  495. DeletePVar(playerid, "LoadForkliftTime");
  496. CrateBeingProcessed[facility] = 0;
  497. CrateBox[boxid][cbFacility] = -1;
  498. TogglePlayerControllable(playerid, 1);
  499. if(!ValidGroup(PlayerInfo[playerid][pMember])) {
  500. SendClientMessageEx(playerid, COLOR_GRAD2, "You failed to load the crate. You're no longer apart of a group!");
  501. return 1;
  502. }
  503. if(!IsPlayerInRangeOfPoint(playerid, 3.0, CrateFacility[facility][cfPos][0], CrateFacility[facility][cfPos][1], CrateFacility[facility][cfPos][2])) {
  504. SendClientMessageEx(playerid, COLOR_GRAD2, "You failed to load the crate. You're not in range of the facility!");
  505. return 1;
  506. }
  507. if(GetPlayerVirtualWorld(playerid) != CrateFacility[facility][cfVw] || GetPlayerInterior(playerid) != CrateFacility[facility][cfInt]) {
  508. SendClientMessageEx(playerid, COLOR_GRAD2, "You failed to load the crate. You're not in the same virtual/interior world.");
  509. return 1;
  510. }
  511. if(playerTabbed[playerid] != 0) {
  512. SendClientMessageEx(playerid, COLOR_GRAD2, "You failed to load the crate. You were alt-tabbed.");
  513. return 1;
  514. }
  515. if(IsACriminal(playerid)) CrateBox[boxid][cbPaid] = 1;
  516. if(!IsACriminal(playerid)) {
  517. if(CrateFacility[facility][cfProdCost] > 0) {
  518. if(PlayerInfo[playerid][pMember] != CrateFacility[facility][cfGroup]) {
  519. if(GetGroupBudget(PlayerInfo[playerid][pMember]) < CrateFacility[facility][cfProdCost]) return SendClientMessageEx(playerid, COLOR_GRAD1, "Your group doesn't have $%s to purcahse this crate!", number_format(CrateFacility[facility][cfProdCost]));
  520. SetGroupBudget(PlayerInfo[playerid][pMember], -CrateFacility[facility][cfProdCost]);
  521. CrateBox[boxid][cbPaid] = 1;
  522. format(string, sizeof(string), "%s has purchased a crate from the %s facility costing %s.", GetPlayerNameEx(playerid), CrateFacility[facility][cfName], number_format(CrateFacility[facility][cfProdCost]));
  523. GroupPayLog(PlayerInfo[playerid][pMember], string);
  524. if(CrateFacility[facility][cfGroup] == -1) {
  525. if(arrGroupData[PlayerInfo[playerid][pMember]][g_iAllegiance] == 2) {
  526. TRTax += CrateFacility[facility][cfProdCost];
  527. format(string, sizeof(string), "%s has purchased a crate from an unowned facility in your nation adding $%s", arrGroupData[PlayerInfo[playerid][pMember]][g_szGroupName], number_format(CrateFacility[facility][cfProdCost]));
  528. GroupPayLog(8, string);
  529. } else {
  530. Tax += CrateFacility[facility][cfProdCost];
  531. format(string, sizeof(string), "%s has purchased a crate from an unowned facility in your nation adding $%s", arrGroupData[PlayerInfo[playerid][pMember]][g_szGroupName], number_format(CrateFacility[facility][cfProdCost]));
  532. GroupPayLog(5, string);
  533. }
  534. } else {
  535. SetGroupBudget(CrateFacility[facility][cfGroup], CrateFacility[facility][cfProdCost]);
  536. format(string, sizeof(string), "%s has purchased a crate from your facility adding $%s", arrGroupData[PlayerInfo[playerid][pMember]][g_szGroupName], number_format(CrateFacility[facility][cfProdCost]));
  537. GroupPayLog(CrateFacility[facility][cfGroup], string);
  538. }
  539. SendClientMessageEx(playerid, COLOR_YELLOW, "Your group has been charged %s for this crate!", number_format(CrateFacility[facility][cfProdCost]));
  540. }
  541. else {
  542. SendClientMessageEx(playerid, COLOR_YELLOW, "Your group will not be charged for this crate but if you deposit it into your locker payment is required!");
  543. }
  544. }
  545. SaveGroup(PlayerInfo[playerid][pMember]);
  546. format(string, sizeof(string), "%s %s has manufactured a crate at %s facility.", arrGroupRanks[PlayerInfo[playerid][pMember]][PlayerInfo[playerid][pRank]], GetPlayerNameEx(playerid), CrateFacility[facility][cfName]);
  547. GroupLog(PlayerInfo[playerid][pMember], string);
  548. ABroadCast(COLOR_LIGHTRED, string, 2);
  549. if(ValidGroup(CrateFacility[facility][cfGroup])) {
  550. foreach(new i: Player) {
  551. if(PlayerInfo[i][pMember] == CrateFacility[facility][cfGroup]) {
  552. SendClientMessageEx(i, COLOR_LIGHTRED, "A crate has been manufactured at %s facility.", CrateFacility[facility][cfName]);
  553. }
  554. }
  555. }
  556. }
  557. CrateBox[boxid][cbLifespan] = 7200;
  558. CrateBox[boxid][cbFacility] = facility;
  559. CrateBox[boxid][cbGroup] = -1;
  560. CrateBox[boxid][cbTransfer] = 1;
  561. CrateBox[boxid][cbOnVeh] = vehicle;
  562. CrateBox[boxid][cbPrice] = CrateFacility[facility][cfProdCost];
  563. CrateBox[boxid][cbMats] = 50;
  564. CrateBox[boxid][cbActive] = 1;
  565. CrateVehicle[vehicle][cvForkObject] = CreateDynamicObject(964,-1077.59997559,4274.39990234,3.40000010,0.00000000,0.00000000,0.00000000);
  566. AttachDynamicObjectToVehicle(CrateVehicle[vehicle][cvForkObject], CrateVehicle[vehicle][cvSpawnID], 0, 0.9, -0.2, 0, 0, 0);
  567. CrateVehicle[vehicle][cvCrate] = boxid;
  568. --CrateFacility[facility][cfProdReady];
  569. SaveCrate(boxid);
  570. SaveFacility(facility);
  571. SaveCrateVehicle(vehicle);
  572. Streamer_Update(playerid);
  573. }
  574. return 1;
  575. }
  576. forward PlayerCarryCrate(playerid, boxid, vehid, action);
  577. public PlayerCarryCrate(playerid, boxid, vehid, action) {
  578. /*
  579. --- Action ---
  580. 0 - Pickup from floor
  581. 1 - Put on floor
  582. 2 - Take from vehicle
  583. 3 - Put in vehicle
  584. 4-5 - Player went to busy mode (Events, Prison, Death etc..)
  585. */
  586. if(action == 0) {
  587. SendClientMessageEx(playerid, COLOR_GRAD2, "Press the '{FFFF00}FIRE{BFC0C2}' button to place the crate on the floor");
  588. SendClientMessageEx(playerid, COLOR_GRAD2, "or you can use '{FFFF00}/crate store{BFC0C2}' to place it into the designated vehicle.");
  589. if(PlayerHoldingObject[playerid][8] != 0 || IsPlayerAttachedObjectSlotUsed(playerid, 8))
  590. RemovePlayerAttachedObject(playerid, 8), PlayerHoldingObject[playerid][8] = 0;
  591. SetPlayerAttachedObject(playerid, 8, 964, 1, -0.071, 0.536, -0.026999, -2.19999, 87.1999, 0.699999, 0.479999, 0.538999, 0.419999);
  592. if(GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_CARRY) SetPlayerSpecialAction(playerid, SPECIAL_ACTION_CARRY);
  593. CarryCrate[playerid] = boxid;
  594. BeingMoved[boxid] = playerid;
  595. }
  596. if(action == 1) {
  597. new Float: pcbPos[3];
  598. GetPlayerPos(playerid, pcbPos[0], pcbPos[1], pcbPos[2]);
  599. GetXYInFrontOfPlayer(playerid, pcbPos[0], pcbPos[1], 1);
  600. CrateBox[boxid][cbPos][0] = pcbPos[0];
  601. CrateBox[boxid][cbPos][1] = pcbPos[1];
  602. CrateBox[boxid][cbPos][2] = pcbPos[2]-1.0;
  603. CrateBox[boxid][cbInt] = GetPlayerInterior(playerid);
  604. CrateBox[boxid][cbVw] = GetPlayerVirtualWorld(playerid);
  605. CrateBox[boxid][cbPlacedBy] = GetPlayerNameEx(playerid);
  606. RemovePlayerAttachedObject(playerid, 8);
  607. PlayerHoldingObject[playerid][8] = 0;
  608. SetPlayerSpecialAction(playerid, SPECIAL_ACTION_NONE);
  609. CarryCrate[playerid] = -1;
  610. BeingMoved[boxid] = INVALID_PLAYER_ID;
  611. SaveCrate(boxid);
  612. }
  613. if(action == 2) {
  614. SendClientMessageEx(playerid, COLOR_GRAD2, "Press the '{FFFF00}FIRE{BFC0C2}' button to place the crate on the floor");
  615. SendClientMessageEx(playerid, COLOR_GRAD2, "or you can use '{FFFF00}/crate store{BFC0C2}' to place it into the designated vehicle.");
  616. if(PlayerHoldingObject[playerid][8] != 0 || IsPlayerAttachedObjectSlotUsed(playerid, 8))
  617. RemovePlayerAttachedObject(playerid, 8), PlayerHoldingObject[playerid][8] = 0;
  618. SetPlayerAttachedObject(playerid, 8, 964, 1, -0.071, 0.536, -0.026999, -2.19999, 87.1999, 0.699999, 0.479999, 0.538999, 0.419999);
  619. if(GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_CARRY) SetPlayerSpecialAction(playerid, SPECIAL_ACTION_CARRY);
  620. CrateBox[boxid][cbInVeh] = -1;
  621. CarryCrate[playerid] = boxid;
  622. BeingMoved[boxid] = playerid;
  623. format(szMiscArray, sizeof(szMiscArray), "* %s has unloaded a crate from the %s.", GetPlayerNameEx(playerid), GetVehicleName(CrateVehicle[vehid][cvSpawnID]));
  624. ProxDetector(25.0, playerid, szMiscArray, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
  625. }
  626. if(action == 3) {
  627. CrateBox[boxid][cbInVeh] = vehid;
  628. RemovePlayerAttachedObject(playerid, 8);
  629. PlayerHoldingObject[playerid][8] = 0;
  630. SetPlayerSpecialAction(playerid, SPECIAL_ACTION_NONE);
  631. CarryCrate[playerid] = -1;
  632. BeingMoved[boxid] = INVALID_PLAYER_ID;
  633. SaveCrate(boxid);
  634. format(szMiscArray, sizeof(szMiscArray), "* %s has loaded a crate into the %s.", GetPlayerNameEx(playerid), GetVehicleName(CrateVehicle[vehid][cvSpawnID]));
  635. ProxDetector(25.0, playerid, szMiscArray, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
  636. }
  637. if(action == 4 || action == 5) {
  638. if(action == 4) SendClientMessageEx(playerid, COLOR_YELLOW, "SMS: What do you think your doing?! I'll take that box from you as you seem busy to finish the job!, Sender: Unknown");
  639. if(action == 5) {
  640. SendClientMessageEx(playerid, COLOR_YELLOW, "SMS: You were prevented from carrying the crate it has been dropped!, Sender: Unknown");
  641. new Float: pcbPos[3];
  642. GetPlayerPos(playerid, pcbPos[0], pcbPos[1], pcbPos[2]);
  643. GetXYInFrontOfPlayer(playerid, pcbPos[0], pcbPos[1], 1);
  644. CrateBox[boxid][cbPos][0] = pcbPos[0];
  645. CrateBox[boxid][cbPos][1] = pcbPos[1];
  646. CrateBox[boxid][cbPos][2] = pcbPos[2]-1.0;
  647. CrateBox[boxid][cbInt] = GetPlayerInterior(playerid);
  648. CrateBox[boxid][cbVw] = GetPlayerVirtualWorld(playerid);
  649. CrateBox[boxid][cbPlacedBy] = GetPlayerNameEx(playerid);
  650. SaveCrate(boxid);
  651. }
  652. RemovePlayerAttachedObject(playerid, 8);
  653. PlayerHoldingObject[playerid][8] = 0;
  654. SetPlayerSpecialAction(playerid, SPECIAL_ACTION_NONE);
  655. CarryCrate[playerid] = -1;
  656. BeingMoved[boxid] = INVALID_PLAYER_ID;
  657. }
  658. UpdateCrateBox(boxid);
  659. Streamer_Update(playerid);
  660. return 1;
  661. }
  662. stock DestroyCrate(box) {
  663. // Is the box on a fork lift?
  664. if(CrateBox[box][cbOnVeh] != -1) {
  665. if(IsValidDynamicObject(CrateVehicle[CrateBox[box][cbOnVeh]][cvForkObject])) DestroyDynamicObject(CrateVehicle[CrateBox[box][cbOnVeh]][cvForkObject]);
  666. CrateVehicle[CrateBox[box][cbOnVeh]][cvCrate] = -1;
  667. CrateVehicle[CrateBox[box][cbOnVeh]][cvCrateLoad] = 0;
  668. SaveCrateVehicle(CrateBox[box][cbOnVeh]);
  669. CrateBox[box][cbOnVeh] = -1;
  670. }
  671. /*
  672. foreach(new p: Player) {
  673. if(CarryCrate[p] == box) {
  674. RemovePlayerAttachedObject(p, 8);
  675. PlayerHoldingObject[p][8] = 0;
  676. SetPlayerSpecialAction(p, SPECIAL_ACTION_NONE);
  677. CarryCrate[p] = -1;
  678. BeingMoved[box] = INVALID_PLAYER_ID;
  679. }
  680. }*/
  681. if(BeingMoved[box] != INVALID_PLAYER_ID) {
  682. RemovePlayerAttachedObject(BeingMoved[box], 8);
  683. PlayerHoldingObject[BeingMoved[box]][8] = 0;
  684. SetPlayerSpecialAction(BeingMoved[box], SPECIAL_ACTION_NONE);
  685. CarryCrate[BeingMoved[box]] = -1;
  686. BeingMoved[box] = INVALID_PLAYER_ID;
  687. }
  688. if(CrateBox[box][cbFacility] != -1) {
  689. ++CrateFacility[CrateBox[box][cbFacility]][cfProdPrep];
  690. }
  691. CrateBox[box][cbFacility] = -1;
  692. CrateBox[box][cbGroup] = -1;
  693. CrateBox[box][cbPos][0] = 0.00000;
  694. CrateBox[box][cbPos][1] = 0.00000;
  695. CrateBox[box][cbPos][2] = 0.00000;
  696. CrateBox[box][cbInt] = 0;
  697. CrateBox[box][cbInVeh] = -1;
  698. CrateBox[box][cbOnVeh] = -1;
  699. CrateBox[box][cbVw] = 0;
  700. CrateBox[box][cbMats] = 0;
  701. for(new w = 0; w < 16; w++) {
  702. CrateBox[box][cbWep][w] = 0;
  703. CrateBox[box][cbWepAmount][w] = 0;
  704. }
  705. format(CrateBox[box][cbPlacedBy], MAX_PLAYER_NAME, "Unknown");
  706. CrateBox[box][cbLifespan] = 0;
  707. CrateBox[box][cbTransfer] = 0;
  708. CrateBox[box][cbDoor] = -1;
  709. CrateBox[box][cbDoorType] = -1;
  710. CrateBox[box][cbPrice] = 0;
  711. CrateBox[box][cbPaid] = 0;
  712. CrateBox[box][cbActive] = 0;
  713. SaveCrate(box);
  714. UpdateCrateBox(box);
  715. return 1;
  716. }
  717. stock IsValidCrate(box) {
  718. if((0 <= box < MAX_CRATES)) return 1;
  719. else return 0;
  720. }
  721. CMD:facility(playerid, params[]) {
  722. if(PlayerInfo[playerid][pAdmin] > 3 || PlayerInfo[playerid][pASM] > 0 || PlayerInfo[playerid][pFactionModerator] > 0) {
  723. szMiscArray[0] = 0;
  724. new choice[32], fac, value;
  725. if(sscanf(params, "s[32]iD(-1)", choice, fac, value))
  726. {
  727. SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /facility [name] [id]");
  728. SendClientMessageEx(playerid, COLOR_GREY, "Names: sync goto, raidable, info");
  729. SendClientMessageEx(playerid, COLOR_GREY, "EXTRA: There is only /cfedit if you want to edit a facility.");
  730. return 1;
  731. }
  732. if(!(0 <= fac < MAX_CRATE_FACILITY)) return SendClientMessageEx(playerid, COLOR_GREY, "Invalid Facility ID. (0 - %d)", MAX_CRATE_FACILITY-1);
  733. if(strcmp(choice, "sync", true) == 0) {
  734. if(!CrateFacility[fac][cfActive]) return SendClientMessageEx(playerid, COLOR_GREY, "That crate facility is not active!");
  735. SyncFacility(fac);
  736. SendClientMessageEx(playerid, COLOR_WHITE, "You have sycned the %s facility, if boxes are missing they'll be put into production.", CrateFacility[fac][cfName]);
  737. return 1;
  738. }
  739. else if(strcmp(choice, "goto", true) == 0) {
  740. if(CrateFacility[fac][cfPos][0] == 0.0) return SendClientMessageEx(playerid, COLOR_GREY, "Unable to go to facility as it's currently not being used!");
  741. SetPlayerInterior(playerid, CrateFacility[fac][cfInt]);
  742. SetPlayerPos(playerid, CrateFacility[fac][cfPos][0], CrateFacility[fac][cfPos][1], CrateFacility[fac][cfPos][2]+1.0);
  743. PlayerInfo[playerid][pInt] = CrateFacility[fac][cfInt];
  744. SetPlayerVirtualWorld(playerid, CrateFacility[fac][cfVw]);
  745. PlayerInfo[playerid][pVW] = CrateFacility[fac][cfVw];
  746. if(CrateFacility[fac][cfInt] > 0) Player_StreamPrep(playerid, CrateFacility[fac][cfPos][0], CrateFacility[fac][cfPos][1], CrateFacility[fac][cfPos][2]+1.0, FREEZE_TIME);
  747. SendClientMessageEx(playerid, COLOR_WHITE, "You have teleported to create facility %d.", fac);
  748. return 1;
  749. }
  750. else if(strcmp(choice, "raidable", true) == 0) {
  751. if(!CrateFacility[fac][cfActive]) return SendClientMessageEx(playerid, COLOR_GREY, "That crate facility is not active!");
  752. if(AdminOpened[fac]) {
  753. if(CrateFacility[fac][cfRaidTimer] == 0) TriggerGates(fac, 0);
  754. format(szMiscArray, sizeof(szMiscArray), "{AA3333}AdmWarning{FFFF00}: %s has made %s facility unable to be raided freely. (ID: %d)", GetPlayerNameEx(playerid), CrateFacility[fac][cfName], fac);
  755. SendClientMessageEx(playerid, COLOR_WHITE, "You have made %s facility unable to be raided freely.", CrateFacility[fac][cfName]);
  756. ABroadCast(COLOR_YELLOW, szMiscArray, 2);
  757. AdminOpened[fac] = 0;
  758. } else {
  759. TriggerGates(fac);
  760. format(szMiscArray, sizeof(szMiscArray), "{AA3333}AdmWarning{FFFF00}: %s has made %s facility able to be raided freely. (ID: %d)", GetPlayerNameEx(playerid), CrateFacility[fac][cfName], fac);
  761. SendClientMessageEx(playerid, COLOR_WHITE, "You have made %s facility able to be raided freely.", CrateFacility[fac][cfName]);
  762. ABroadCast(COLOR_YELLOW, szMiscArray, 2);
  763. AdminOpened[fac] = 1;
  764. }
  765. return 1;
  766. }
  767. else if(strcmp(choice, "info", true) == 0) {
  768. new crates = 0, group[32];
  769. for(new c = 0; c < MAX_CRATES; c++) {
  770. if(CrateBox[c][cbFacility] == fac) {
  771. ++crates;
  772. }
  773. }
  774. if(CrateFacility[fac][cfGroup] != -1 && ValidGroup(CrateFacility[fac][cfGroup])) {
  775. format(group, sizeof(group), "%s", arrGroupData[CrateFacility[fac][cfGroup]][g_szGroupName]);
  776. } else {
  777. format(group, sizeof(group), "--");
  778. }
  779. SendClientMessageEx(playerid, COLOR_GREEN, "|___________ Facility Info (ID: %d) ___________|", fac);
  780. SendClientMessageEx(playerid, COLOR_WHITE, "X: %f | Y: %f | Z: %f | Int: %d | VW: %d | Active: %s", CrateFacility[fac][cfPos][0], CrateFacility[fac][cfPos][1], CrateFacility[fac][cfPos][2], CrateFacility[fac][cfInt], CrateFacility[fac][cfVw], (CrateFacility[fac][cfActive]) ? ("Yes") : ("No"));
  781. SendClientMessageEx(playerid, COLOR_WHITE, "Next Raid: %s | Raid Progress: %s | Raidable Status: %s", date(CrateFacility[fac][cfCooldown], 1), (CrateFacilityRaid[fac]) ? ("Active") : ("Not Ready"), (CrateFacility[fac][cfRaidable]) ? ("Active") : ("Disabled"));
  782. SendClientMessageEx(playerid, COLOR_WHITE, "Crates Ready: %d | Crates in production: %d | Crates in use: %d | Max Crates: %d", CrateFacility[fac][cfProdReady], CrateFacility[fac][cfProdPrep], crates, CrateFacility[fac][cfProdMax]);
  783. SendClientMessageEx(playerid, COLOR_WHITE, "Cost Per Crate: %s | Production status: %s", number_format(CrateFacility[fac][cfProdCost]), (CrateFacility[fac][cfProdStatus]) ? ("Active") : ("Paused"));
  784. SendClientMessageEx(playerid, COLOR_WHITE, "Owner: %s | Deliver Multiplier: %d", group, CrateFacility[fac][cfProdMulti]);
  785. return 1;
  786. }
  787. else SendClientMessageEx(playerid, COLOR_GREY, "Invalid name selected!");
  788. } else {
  789. SendClientMessageEx(playerid, COLOR_GREY, "You are not authorized to use this command!");
  790. }
  791. return 1;
  792. }
  793. stock SyncFacility(id) {
  794. new total = 0;
  795. for(new c = 0; c < MAX_CRATES; c++) {
  796. if(CrateBox[c][cbFacility] == id) {
  797. ++total;
  798. }
  799. }
  800. new ready = ((CrateFacility[id][cfProdReady] + CrateFacility[id][cfProdPrep]) + total);
  801. if(ready < 0) ready = CrateFacility[id][cfProdMax];
  802. if(CrateFacility[id][cfProdMax] != ready) {
  803. CrateFacility[id][cfProdPrep] = (CrateFacility[id][cfProdMax] - ready);
  804. }
  805. SaveFacility(id);
  806. return 1;
  807. }
  808. CMD:crate(playerid, params[]) {
  809. szMiscArray[0] = 0;
  810. new string[128], choice[32], box, crate;
  811. if(sscanf(params, "s[32]D(-1)", choice, crate))
  812. {
  813. SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /crate [name]");
  814. SendClientMessageEx(playerid, COLOR_GREY, "(On-Foot): Carry, Take, Contents, Seize");
  815. SendClientMessageEx(playerid, COLOR_GREY, "(Forklift): Load, Drop, Store");
  816. if(PlayerInfo[playerid][pAdmin] > 3) SendClientMessageEx(playerid, COLOR_GREY, "Administrator: Destroy, Spawn");
  817. return 1;
  818. }
  819. if(PlayerBusy(playerid)) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't do that right now.");
  820. if(strcmp(choice, "carry", true) == 0) {
  821. GetCrateBox(playerid, box, 2.0);
  822. if(box == -1) return SendClientMessageEx(playerid, COLOR_GREY, "You're not near any crate boxes to pickup!");
  823. if(CarryCrate[playerid] != -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "you're currently carraying a crate either store or drop it before carrying another!");
  824. ApplyAnimation(playerid, "CARRY", "liftup", 4.1, 0, 0, 0, 0, 0, 1);
  825. SetTimerEx("PlayerCarryCrate", 1000, false, "iiii", playerid, box, -1, 0);
  826. return 1;
  827. }
  828. else if(strcmp(choice, "contents", true) == 0) {
  829. new weaponname[32], title[24];
  830. GetCrateBox(playerid, box, 2.0);
  831. if(box == -1) return SendClientMessageEx(playerid, COLOR_GREY, "You're not in range of any crate boxes!");
  832. if(CrateBox[box][cbGroup] == -1) return SendClientMessageEx(playerid, COLOR_GREY, "This crate is not a transfer crate, use /cgun instead!");
  833. format(title, sizeof(title), "Crate Contents (ID: %d)", box);
  834. format(szMiscArray, sizeof(szMiscArray), "Weapon\tQuantity\n");
  835. for(new w = 0; w < 16; w++) {
  836. if(CrateBox[box][cbWep][w] > 0) {
  837. GetWeaponName(CrateBox[box][cbWep][w], weaponname, sizeof(weaponname));
  838. format(szMiscArray, sizeof(szMiscArray), "%s%s\t%s\n", szMiscArray, weaponname, number_format(CrateBox[box][cbWepAmount][w]));
  839. }
  840. }
  841. if(strlen(szMiscArray) == 16) format(szMiscArray, sizeof(szMiscArray), "%sThere are no weapons in this crate.", szMiscArray);
  842. Dialog_Show(playerid, -1, DIALOG_STYLE_TABLIST_HEADERS, title, szMiscArray, "Close", "");
  843. return 1;
  844. }
  845. else if(strcmp(choice, "load", true) == 0) {
  846. new facility, vehicleid = GetPlayerVehicleID(playerid), veh;
  847. FetchFacility(playerid, facility, 3.0);
  848. GetCrateBox(playerid, box, 3.0);
  849. if(!ValidGroup(PlayerInfo[playerid][pMember])) return SendClientMessage(playerid, COLOR_GRAD2, " You need to be apart of a group to use this command!");
  850. if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessageEx(playerid, COLOR_GRAD2, "You need to be in a vehicle to do this!");
  851. if(GetVehicleModel(vehicleid) != 530) return SendClientMessageEx(playerid, COLOR_GRAD2, "You need to be in a forklift vehicle to load crates!");
  852. if((veh = IsDynamicCrateVehicle(vehicleid)) == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "You're not in the designated forklift vehicle for this operation!");
  853. if(CrateVehicle[veh][cvCrate] != -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "There is already a crate loaded on the forklift!");
  854. if(facility != -1) {
  855. if(!CrateFacility[facility][cfActive]) return SendClientMessageEx(playerid, COLOR_GRAD1, "This facility is currently not in operation!");
  856. if(CrateFacility[facility][cfProdReady] < 1) return SendClientMessageEx(playerid, COLOR_GRAD1, "This facility has no crates available to load!");
  857. if(CrateBeingProcessed[facility] > 0) return SendClientMessageEx(playerid, COLOR_GRAD2, "Please wait a crate is being procssed!");
  858. if(PlayerInfo[playerid][pConnectHours] < 25)
  859. {
  860. format(string, sizeof(string), "{AA3333}AdmWarning{FFFF00}: %s has attempted to load a crate with only %d playing hours.", GetPlayerNameEx(playerid), PlayerInfo[playerid][pConnectHours]);
  861. ABroadCast(COLOR_YELLOW, string, 4);
  862. return SendClientMessageEx(playerid, COLOR_GRAD2, " You've not played long enough in order to load crates!");
  863. }
  864. if(IsACriminal(playerid)) {
  865. if(!CrateFacility[facility][cfRaidable]) return SendClientMessageEx(playerid, COLOR_GRAD1, "This facility can't be raided!");
  866. if(!AdminOpened[facility] && !CrateFacility[facility][cfRaidTimer]) return SendClientMessageEx(playerid, COLOR_GRAD1, "This facility is currently on cooldown from raids.");
  867. }
  868. for(new c = 0; c < MAX_CRATES; c++) {
  869. if(CrateBox[c][cbFacility] == -1) {
  870. CrateBeingProcessed[facility] = 1;
  871. CrateBox[c][cbFacility] = facility;
  872. SetPVarInt(playerid, "LoadForkliftTime", 5);
  873. SetTimerEx("LoadForklift", 1000, 0, "iiii", playerid, facility, c, veh);
  874. GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~n~~n~~w~5 seconds left", 1100, 3);
  875. TogglePlayerControllable(playerid, 0);
  876. break;
  877. }
  878. }
  879. }
  880. else if(box != -1) {
  881. CrateBox[box][cbOnVeh] = veh;
  882. CrateVehicle[veh][cvCrate] = box;
  883. format(string, sizeof(string), "* %s has loaded a crate onto the forklift.", GetPlayerNameEx(playerid));
  884. ProxDetector(25.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
  885. SaveCrateVehicle(veh);
  886. SaveCrate(box);
  887. UpdateCrateBox(box);
  888. CrateVehCheck(veh);
  889. }
  890. else SendClientMessageEx(playerid, COLOR_GRAD2, "You're not near any crate boxes to load onto the forklift!");
  891. return 1;
  892. }
  893. else if(strcmp(choice, "store", true) == 0) {
  894. szMiscArray[0] = 0;
  895. new Float:vPos[3], inveh = GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet ,boot, objective, VehFound = -1, boxid;
  896. for(new i = 0; i < MAX_CRATE_VEHCILES; i++) {
  897. if(CrateVehicle[i][cvSpawnID] != INVALID_VEHICLE_ID) {
  898. GetPosBehindVehicle(CrateVehicle[i][cvSpawnID], vPos[0], vPos[1], vPos[2], (IsAPlane(CrateVehicle[i][cvSpawnID]) ? -8 : 0));
  899. if(IsPlayerInRangeOfPoint(playerid, (IsAPlane(CrateVehicle[i][cvSpawnID]) ? 6 : 2), vPos[0], vPos[1], vPos[2])) {
  900. if(CrateVehicle[i][cvSpawnID] != inveh) {
  901. VehFound = i; // Do not use the vehicle ID as we store the array ID for the validation since vehicles do not store "spawn id".
  902. break;
  903. }
  904. }
  905. }
  906. }
  907. if(VehFound == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "You're not near any designated vehicles that can store crates.");
  908. if(CrateVehicle[VehFound][cvCrateMax] < 1) return SendClientMessageEx(playerid, COLOR_GRAD3, "You can't store crates in this vehicle!");
  909. if(CreateCount(VehFound) >= CrateVehicle[VehFound][cvCrateMax]) return SendClientMessageEx(playerid, COLOR_GRAD3, "You can't store anymore crates in this vehicle it's at max capacity!");
  910. if(VehDelivering[VehFound]) return SendClientMessageEx(playerid, COLOR_GRAD3, "This vehicle is currently unloading crates - Please Wait!");
  911. GetVehicleParamsEx(CrateVehicle[VehFound][cvSpawnID], engine, lights, alarm, doors, bonnet, boot, objective);
  912. if(inveh > 0 && GetVehicleModel(inveh) == 530) { // Forklift -> Vehicle
  913. if(IsDynamicCrateVehicle(inveh) == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "Your not in the designated forklift vehicle!");
  914. if((boxid = CrateVehicle[IsDynamicCrateVehicle(inveh)][cvCrate]) == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "There is no crate loaded on the forklift!");
  915. if(GetVehicleModel(CrateVehicle[VehFound][cvSpawnID]) != 592 && GetVehicleModel(CrateVehicle[VehFound][cvSpawnID]) != 553 && IsAPlane(CrateVehicle[VehFound][cvSpawnID])) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't store crates in this vehicle!");
  916. if(!IsAPlane(CrateVehicle[VehFound][cvSpawnID])) {
  917. if((boot == VEHICLE_PARAMS_OFF || boot == VEHICLE_PARAMS_UNSET)) return SendClientMessageEx(playerid, COLOR_GRAD3, "You can't load crates into a vehicle whilst the trunk is closed! - '/car trunk' to open it.");
  918. }
  919. CrateBox[boxid][cbInVeh] = VehFound;
  920. CrateBox[boxid][cbOnVeh] = -1;
  921. CrateBox[boxid][cbTransfer] = 0;
  922. CrateVehicle[IsDynamicCrateVehicle(inveh)][cvCrate] = -1;
  923. SaveCrateVehicle(IsDynamicCrateVehicle(inveh));
  924. SaveCrate(boxid);
  925. CrateVehCheck(IsDynamicCrateVehicle(inveh));
  926. UpdateCrateBox(boxid);
  927. Streamer_Update(playerid);
  928. format(szMiscArray, sizeof(szMiscArray), "* %s has loaded a crate into the %s.", GetPlayerNameEx(playerid), GetVehicleName(CrateVehicle[VehFound][cvSpawnID]));
  929. ProxDetector(25.0, playerid, szMiscArray, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
  930. }
  931. else if((boxid = CarryCrate[playerid]) != -1) { // Player -> Vehicle
  932. if(IsAPlane(CrateVehicle[VehFound][cvSpawnID])) return SendClientMessageEx(playerid, COLOR_GRAD2, "You need a forklift to load them into the plane!");
  933. if((boot == VEHICLE_PARAMS_OFF || boot == VEHICLE_PARAMS_UNSET)) return SendClientMessageEx(playerid, COLOR_GRAD3, "You can't load crates into the vehicle whilst the trunk is closed! - '/car trunk' to open it.");
  934. ApplyAnimation(playerid, "CARRY", "putdwn105", 4.1, 0, 0, 0, 0, 0, 1);
  935. SetTimerEx("PlayerCarryCrate", 700, false, "iiii", playerid, boxid, VehFound, 3);
  936. }
  937. else SendClientMessageEx(playerid, COLOR_GRAD2, "Your not in possession of any crates that you can store!");
  938. return 1;
  939. }
  940. else if(strcmp(choice, "take", true) == 0) {
  941. szMiscArray[0] = 0;
  942. new Float:vPos[3], inveh = GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet ,boot, objective, VehFound = -1;
  943. for(new i = 0; i < MAX_CRATE_VEHCILES; i++) {
  944. if(CrateVehicle[i][cvSpawnID] != INVALID_VEHICLE_ID) {
  945. GetPosBehindVehicle(CrateVehicle[i][cvSpawnID], vPos[0], vPos[1], vPos[2], (IsAPlane(CrateVehicle[i][cvSpawnID]) ? -8 : 0));
  946. if(IsPlayerInRangeOfPoint(playerid, (IsAPlane(CrateVehicle[i][cvSpawnID]) ? 6 : 2), vPos[0], vPos[1], vPos[2])) {
  947. if(CrateVehicle[i][cvSpawnID] != inveh) {
  948. VehFound = i; // Do not use the vehicle ID as we store the array ID for the validation since vehicles do not store "spawn id".
  949. break;
  950. }
  951. }
  952. }
  953. }
  954. if(VehFound == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "You're not near any designated vehicles that can transport crates!");
  955. if(!CreateCount(VehFound)) return SendClientMessageEx(playerid, COLOR_GRAD3, "There are no crates in the vehicle to take!");
  956. if(VehDelivering[VehFound]) return SendClientMessageEx(playerid, COLOR_GRAD3, "This vehicle is currently unloading crates - Please Wait!");
  957. GetVehicleParamsEx(CrateVehicle[VehFound][cvSpawnID], engine, lights, alarm, doors, bonnet, boot, objective);
  958. if(inveh > 0 && GetVehicleModel(inveh) == 530) { // Vehicle -> Forklift
  959. if(IsDynamicCrateVehicle(inveh) == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "You're not in the designated forklift vehicle to unload crates with!");
  960. if(CrateVehicle[IsDynamicCrateVehicle(inveh)][cvCrate] != -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "There is already a crate loaded on the forklift!");
  961. if(!IsAPlane(CrateVehicle[VehFound][cvSpawnID])) {
  962. if((boot == VEHICLE_PARAMS_OFF || boot == VEHICLE_PARAMS_UNSET)) return SendClientMessageEx(playerid, COLOR_GRAD3, "You can't unload crates whilst the trunk is closed! - '/car trunk' to open it.");
  963. }
  964. for(new b = 0; b < MAX_CRATES; b++) {
  965. if(CrateBox[b][cbInVeh] == VehFound) {
  966. CrateBox[b][cbInVeh] = -1;
  967. CrateBox[b][cbOnVeh] = b;
  968. CrateVehicle[IsDynamicCrateVehicle(inveh)][cvCrate] = b;
  969. SaveCrateVehicle(IsDynamicCrateVehicle(inveh));
  970. SaveCrate(b);
  971. CrateVehCheck(IsDynamicCrateVehicle(inveh));
  972. UpdateCrateBox(b);
  973. Streamer_Update(playerid);
  974. format(szMiscArray, sizeof(szMiscArray), "* %s has unloaded a crate from the %s.", GetPlayerNameEx(playerid), GetVehicleName(CrateVehicle[VehFound][cvSpawnID]));
  975. ProxDetector(25.0, playerid, szMiscArray, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
  976. break;
  977. }
  978. }
  979. }
  980. else if(CarryCrate[playerid] == -1) { // Player -> Vehicle
  981. if(IsAPlane(CrateVehicle[VehFound][cvSpawnID])) return SendClientMessageEx(playerid, COLOR_GRAD2, "You need a forklift to unload crates from planes!");
  982. if((boot == VEHICLE_PARAMS_OFF || boot == VEHICLE_PARAMS_UNSET)) return SendClientMessageEx(playerid, COLOR_GRAD3, "You can't unload crates whilst the trunk is closed! - '/car trunk' to open it.");
  983. for(new b = 0; b < MAX_CRATES; b++) {
  984. if(CrateBox[b][cbInVeh] == VehFound) {
  985. ApplyAnimation(playerid, "CARRY", "liftup105", 4.1, 0, 0, 0, 0, 0, 1);
  986. SetTimerEx("PlayerCarryCrate", 700, false, "iiii", playerid, b, VehFound, 2);
  987. break;
  988. }
  989. }
  990. }
  991. else SendClientMessageEx(playerid, COLOR_GRAD2, "You're already in possession of a crate!");
  992. return 1;
  993. }
  994. else if(strcmp(choice, "drop", true) == 0) {
  995. new vehicleid = GetPlayerVehicleID(playerid), veh, boxid, area;
  996. FetchFacility(playerid, area, 50.0);
  997. if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessageEx(playerid, COLOR_GRAD2, "You need to be in a vehicle to do this!");
  998. if(GetVehicleModel(vehicleid) != 530) return SendClientMessageEx(playerid, COLOR_GRAD2, "You need to be a forklift to drop a crate!");
  999. if((veh = IsDynamicCrateVehicle(vehicleid)) == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "You're not in the designated vehicle for this operation!");
  1000. if((boxid = CrateVehicle[veh][cvCrate]) == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "There is no crate attached to this forklift!");
  1001. if(CrateBox[boxid][cbTransfer]) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't drop the crate it must be loaded into a vehicle first!");
  1002. if(area != -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "Crates cannot be unloaded near crate facilities!");
  1003. new Float: vPos[3];
  1004. GetVehiclePos(vehicleid, vPos[0], vPos[1], vPos[2]);
  1005. GetXYInFrontOfPlayer(playerid, vPos[0], vPos[1], 2);
  1006. CrateBox[boxid][cbOnVeh] = -1;
  1007. CrateVehicle[veh][cvCrate] = -1;
  1008. CrateBox[boxid][cbPos][0] = vPos[0];
  1009. CrateBox[boxid][cbPos][1] = vPos[1];
  1010. CrateBox[boxid][cbPos][2] = vPos[2]-0.8;
  1011. CrateBox[boxid][cbInt] = GetPlayerInterior(playerid);
  1012. CrateBox[boxid][cbVw] = GetPlayerVirtualWorld(playerid);
  1013. CrateBox[boxid][cbPlacedBy] = GetPlayerNameEx(playerid);
  1014. format(string, sizeof(string), "* %s has unloaded the crate from the forklift.", GetPlayerNameEx(playerid));
  1015. ProxDetector(25.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
  1016. SaveCrateVehicle(veh);
  1017. SaveCrate(boxid);
  1018. CrateVehCheck(veh);
  1019. UpdateCrateBox(boxid);
  1020. Streamer_Update(playerid);
  1021. return 1;
  1022. }
  1023. else if(strcmp(choice, "destroy", true) == 0 && PlayerInfo[playerid][pAdmin] > 3) {
  1024. if(crate == -1) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /crate destroy [id]");
  1025. if(0 <= crate < MAX_CRATES) {
  1026. if(!CrateBox[crate][cbActive]) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't destroy a crate that isn't active!");
  1027. SendClientMessageEx(playerid, COLOR_WHITE, "You have destroyed crate ID: %d", crate);
  1028. DestroyCrate(crate);
  1029. }
  1030. else SendClientMessageEx(playerid, COLOR_YELLOW, "Invalid crate ID - Can't be lower than 0 or higher than %d.", MAX_CRATES-1);
  1031. return 1;
  1032. }
  1033. else if(strcmp(choice, "spawn", true) == 0 && PlayerInfo[playerid][pAdmin] > 3) {
  1034. if(crate == -1) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /crate spawn [id]"), SendClientMessageEx(playerid, COLOR_GREY, "NOTE: The ID must be a facility ID not a crate ID!");
  1035. if(0 <= crate < MAX_CRATE_FACILITY) {
  1036. new Float: pcbPos[3];
  1037. GetPlayerPos(playerid, pcbPos[0], pcbPos[1], pcbPos[2]);
  1038. GetXYInFrontOfPlayer(playerid, pcbPos[0], pcbPos[1], 1);
  1039. if(CrateFacility[crate][cfPos][0] != 0.0 && CrateFacility[crate][cfActive]) {
  1040. if(CrateFacility[crate][cfProdReady] > 0) {
  1041. for(new c = 0; c < MAX_CRATES; c++) {
  1042. if(CrateBox[c][cbFacility] == -1 && CrateBox[c][cbGroup] == -1) {
  1043. CrateBox[c][cbLifespan] = 7200;
  1044. CrateBox[c][cbFacility] = crate;
  1045. CrateBox[c][cbGroup] = -1;
  1046. CrateBox[c][cbTransfer] = 0;
  1047. CrateBox[c][cbPrice] = 0;
  1048. CrateBox[c][cbMats] = 50;
  1049. CrateBox[c][cbActive] = 1;
  1050. --CrateFacility[crate][cfProdReady];
  1051. CrateBox[c][cbPos][0] = pcbPos[0];
  1052. CrateBox[c][cbPos][1] = pcbPos[1];
  1053. CrateBox[c][cbPos][2] = pcbPos[2]-1.0;
  1054. CrateBox[c][cbInt] = GetPlayerInterior(playerid);
  1055. CrateBox[c][cbVw] = GetPlayerVirtualWorld(playerid);
  1056. CrateBox[c][cbPlacedBy] = GetPlayerNameEx(playerid);
  1057. CrateBox[c][cbPaid] = 1;
  1058. SaveCrate(c);
  1059. SaveFacility(crate);
  1060. UpdateCrateBox(c);
  1061. Streamer_Update(playerid);
  1062. SendClientMessageEx(playerid, COLOR_WHITE, "You've spawned a crate at your position!");
  1063. return 1;
  1064. }
  1065. }
  1066. return SendClientMessageEx(playerid, COLOR_GRAD2, "ERROR: Unable to spawn crate as non are available!");
  1067. } else {
  1068. SendClientMessageEx(playerid, COLOR_GRAD2, "Error: Crate facility specified has crates available!");
  1069. }
  1070. } else {
  1071. SendClientMessageEx(playerid, COLOR_GRAD2, "Error: Crate facility specified is either not in use or is not active!");
  1072. }
  1073. }
  1074. else SendClientMessageEx(playerid, COLOR_YELLOW, "Invalid Facility ID - Can't be lower than 0 or higher than %d.", MAX_CRATE_FACILITY-1);
  1075. return 1;
  1076. }
  1077. else if(strcmp(choice, "orders", true) == 0) {
  1078. new fac;
  1079. if(!ValidGroup(PlayerInfo[playerid][pMember])) return SendClientMessage(playerid, COLOR_GRAD2, "You need to be apart of a group to use this command!");
  1080. GetFacility(PlayerInfo[playerid][pMember], fac);
  1081. if(fac == -1) return SendClientMessage(playerid, COLOR_GRAD2, "Your group doesn't own a facility!");
  1082. format(szMiscArray, sizeof(szMiscArray), "Group\tCrates (Total Cost)\tDelivered (Money Earned)\n");
  1083. for(new o = 0; o < MAX_GROUPS; o++) {
  1084. if(CrateOrder[o][coFacility] == fac && CrateOrder[o][coStatus] > 0) {
  1085. format(szMiscArray, sizeof(szMiscArray), "%s%s\t%d ($%s)\t%d ($%s)\n", szMiscArray, arrGroupData[o][g_szGroupName], CrateOrder[o][coCrates], number_format((CrateOrder[o][coCrates] * CrateOrder[o][coPerCrate])), CrateOrder[o][coDelivered], number_format((CrateOrder[o][coDelivered] * CrateOrder[o][coPerCrate])));
  1086. }
  1087. }
  1088. if(strlen(szMiscArray) == 51) return SendClientMessageEx(playerid, COLOR_LIGHTRED, "%s: There are no crate orders pending!", CrateFacility[fac][cfName]);
  1089. Dialog_Show(playerid, -1, DIALOG_STYLE_TABLIST_HEADERS, "Crate Orders", szMiscArray, "Close", "");
  1090. }
  1091. else if(strcmp(choice, "seize", true) == 0) {
  1092. new fac;
  1093. GetCrateBox(playerid, box, 2.0);
  1094. GetFacility(PlayerInfo[playerid][pMember], fac);
  1095. if(fac == -1) return SendClientMessage(playerid, COLOR_GRAD2, "Your group doesn't own a facility!");
  1096. if(CrateFacilityRaid[fac]) return SendClientMessage(playerid, COLOR_GRAD2, "Error: You can't use this command during a raid session.");
  1097. if(box == -1) return SendClientMessageEx(playerid, COLOR_GREY, "You're not near any crate boxes to seize!");
  1098. if(CrateBox[box][cbFacility] != fac) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't seize a crate that doesn't belong to your facility!");
  1099. DestroyCrate(box);
  1100. format(szMiscArray, sizeof(szMiscArray), "* %s has seized a crate box!", GetPlayerNameEx(playerid));
  1101. ProxDetector(25.0, playerid, szMiscArray, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
  1102. }
  1103. else SendClientMessageEx(playerid, COLOR_GRAD2, "Unknown choice selected!");
  1104. return 1;
  1105. }
  1106. stock CreateCount(veh) {
  1107. new amount = 0;
  1108. for(new c = 0; c < MAX_CRATES; c++) {
  1109. if(CrateBox[c][cbInVeh] == veh) {
  1110. ++amount;
  1111. }
  1112. }
  1113. return amount;
  1114. }
  1115. CMD:cfnext(playerid, params[]) {
  1116. if(PlayerInfo[playerid][pAdmin] > 3 || PlayerInfo[playerid][pASM] > 0 || PlayerInfo[playerid][pFactionModerator] > 0) {
  1117. for(new f = 0; f < MAX_CRATE_FACILITY; f++) {
  1118. if(CrateFacility[f][cfPos][0] == 0.0) {
  1119. SendClientMessageEx(playerid, COLOR_YELLOW, "Next crate facility available for use: %d", f);
  1120. break;
  1121. }
  1122. }
  1123. }
  1124. return 1;
  1125. }
  1126. CMD:gotocrate(playerid, params[]) {
  1127. if(PlayerInfo[playerid][pAdmin] > 3 || PlayerInfo[playerid][pASM] > 0 || PlayerInfo[playerid][pFactionModerator] > 0) {
  1128. new id, Float:pos[3];
  1129. if(sscanf(params, "i", id)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /gotocrate [id]");
  1130. if(!(0 <= id < MAX_CRATES)) return SendClientMessageEx(playerid, COLOR_GREY, "Invalid crate ID. (0 - %d)", MAX_CRATES-1);
  1131. if(!CrateBox[id][cbActive]) return SendClientMessageEx(playerid, COLOR_GREY, "ERROR: The crate box isn't active.");
  1132. /*
  1133. foreach(new i: Player) {
  1134. if(CarryCrate[i] == id) {
  1135. GetPlayerPos(i, pos[0], pos[1], pos[2]);
  1136. SetPlayerPos(playerid, pos[0], pos[1], pos[2]+1.0);
  1137. SetPlayerInterior(playerid, GetPlayerInterior(i));
  1138. PlayerInfo[playerid][pInt] = GetPlayerInterior(i);
  1139. SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(i));
  1140. PlayerInfo[playerid][pVW] = GetPlayerVirtualWorld(i);
  1141. if(GetPlayerInterior(i) > 0) Player_StreamPrep(playerid, pos[0], pos[1], pos[2]+1.0, FREEZE_TIME);
  1142. SendClientMessageEx(playerid, COLOR_WHITE, "You have teleported to crate %d.", id);
  1143. return 1;
  1144. }
  1145. }*/
  1146. if(BeingMoved[id] != INVALID_PLAYER_ID) {
  1147. GetPlayerPos(BeingMoved[id], pos[0], pos[1], pos[2]);
  1148. SetPlayerPos(playerid, pos[0], pos[1], pos[2]+1.0);
  1149. SetPlayerInterior(playerid, GetPlayerInterior(BeingMoved[id]));
  1150. PlayerInfo[playerid][pInt] = GetPlayerInterior(BeingMoved[id]);
  1151. SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(BeingMoved[id]));
  1152. PlayerInfo[playerid][pVW] = GetPlayerVirtualWorld(BeingMoved[id]);
  1153. if(GetPlayerInterior(BeingMoved[id]) > 0) Player_StreamPrep(playerid, pos[0], pos[1], pos[2]+1.0, FREEZE_TIME);
  1154. SendClientMessageEx(playerid, COLOR_WHITE, "You have teleported to crate %d. (It's currently being carried by %s)", id, GetPlayerNameEx(BeingMoved[id]));
  1155. return 1;
  1156. }
  1157. if(CrateBox[id][cbInVeh] != -1) {
  1158. GetVehiclePos(CrateVehicle[CrateBox[id][cbInVeh]][cvSpawnID], pos[0], pos[1], pos[2]);
  1159. SetPlayerPos(playerid, pos[0], pos[1], pos[2]+1.0);
  1160. SetPlayerInterior(playerid, CrateVehicle[CrateBox[id][cbInVeh]][cvInt]);
  1161. PlayerInfo[playerid][pInt] =CrateVehicle[CrateBox[id][cbInVeh]][cvInt];
  1162. SetPlayerVirtualWorld(playerid, CrateVehicle[CrateBox[id][cbInVeh]][cvVw]);
  1163. PlayerInfo[playerid][pVW] = CrateVehicle[CrateBox[id][cbInVeh]][cvVw];
  1164. if(CrateVehicle[CrateBox[id][cbInVeh]][cvInt] > 0) Player_StreamPrep(playerid, pos[0], pos[1], pos[2]+1.0, FREEZE_TIME);
  1165. SendClientMessageEx(playerid, COLOR_WHITE, "You have teleported to crate %d.", id);
  1166. return 1;
  1167. }
  1168. if(CrateBox[id][cbOnVeh] != -1) {
  1169. GetVehiclePos(CrateVehicle[CrateBox[id][cbOnVeh]][cvSpawnID], pos[0], pos[1], pos[2]);
  1170. SetPlayerPos(playerid, pos[0], pos[1], pos[2]+1.0);
  1171. SetPlayerInterior(playerid, CrateVehicle[CrateBox[id][cbOnVeh]][cvInt]);
  1172. PlayerInfo[playerid][pInt] =CrateVehicle[CrateBox[id][cbOnVeh]][cvInt];
  1173. SetPlayerVirtualWorld(playerid, CrateVehicle[id][cvVw]);
  1174. PlayerInfo[playerid][pVW] = CrateVehicle[CrateBox[id][cbOnVeh]][cvVw];
  1175. if(CrateVehicle[CrateBox[id][cbOnVeh]][cvInt] > 0) Player_StreamPrep(playerid, pos[0], pos[1], pos[2]+1.0, FREEZE_TIME);
  1176. SendClientMessageEx(playerid, COLOR_WHITE, "You have teleported to crate %d.", id);
  1177. return 1;
  1178. }
  1179. SetPlayerPos(playerid, CrateBox[id][cbPos][0], CrateBox[id][cbPos][1], CrateBox[id][cbPos][2]+1.0);
  1180. SetPlayerInterior(playerid, CrateBox[id][cbInt]);
  1181. PlayerInfo[playerid][pInt] = CrateBox[id][cbInt];
  1182. SetPlayerVirtualWorld(playerid, CrateBox[id][cbVw]);
  1183. PlayerInfo[playerid][pVW] = CrateBox[id][cbVw];
  1184. if(CrateBox[id][cbInt] > 0) Player_StreamPrep(playerid, CrateBox[id][cbPos][0], CrateBox[id][cbPos][1], CrateBox[id][cbPos][2]+1.0, FREEZE_TIME);
  1185. SendClientMessageEx(playerid, COLOR_WHITE, "You have teleported to crate %d.", id);
  1186. }
  1187. else SendClientMessageEx(playerid, COLOR_GREY, "Your are not authorized to use this command!");
  1188. return 1;
  1189. }
  1190. CMD:cfname(playerid, params[]) {
  1191. if(PlayerInfo[playerid][pAdmin] > 3 || PlayerInfo[playerid][pASM] > 0 || PlayerInfo[playerid][pFactionModerator] > 0) {
  1192. new id, name[50];
  1193. if(sscanf(params, "is[50]", id, name)) return SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /cfname [facility] [name]");
  1194. if(!(0 <= id < MAX_CRATE_FACILITY)) return SendClientMessageEx(playerid, COLOR_GREY, "Invalid facility ID.");
  1195. if(!(0 < strlen(name) < 50)) return SendClientMessageEx(playerid, COLOR_GRAD2, "Name must be between 1 - 50 character long in length!");
  1196. format(szMiscArray, sizeof(szMiscArray), "%s has set %d facility name from %s to %s.", GetPlayerNameEx(playerid), id, CrateFacility[id][cfName], name);
  1197. strcpy(CrateFacility[id][cfName], name, 50);
  1198. Log("logs/cfedit.log", szMiscArray);
  1199. SendClientMessageEx(playerid, COLOR_WHITE, "You have set the facility name to %s.", name);
  1200. SaveFacility(id);
  1201. UpdateFacility(id);
  1202. }
  1203. else SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use this command!");
  1204. return 1;
  1205. }
  1206. CMD:cfedit(playerid, params[]) {
  1207. if(PlayerInfo[playerid][pAdmin] > 3 || PlayerInfo[playerid][pASM] > 0 || PlayerInfo[playerid][pFactionModerator] > 0) {
  1208. new id, name[32], value;
  1209. if(sscanf(params, "s[32]iD(-1)", name, id, value)) {
  1210. SendClientMessageEx(playerid, COLOR_GREY, "USAGE: /cfedit [name] [id] [value]");
  1211. SendClientMessageEx(playerid, COLOR_GREY, "Names: pos, crates, timer, prodstatus, cost, active");
  1212. SendClientMessageEx(playerid, COLOR_GREY, "Names: owner, raidable, multiplier, delete");
  1213. return 1;
  1214. }
  1215. if(!(0 <= id < MAX_CRATE_FACILITY)) return SendClientMessageEx(playerid, COLOR_GREY, "Invalid facility ID.");
  1216. if(strcmp(name, "pos", true) == 0) {
  1217. new Float:pos[3];
  1218. GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  1219. format(szMiscArray, sizeof(szMiscArray), "%s has moved %d crate facility (B: %f, %f, %f Int: %d, VW: %d | A: %f, %f, %f Int: %d, VW: %d)", GetPlayerNameEx(playerid), id, CrateFacility[id][cfPos][0], CrateFacility[id][cfPos][1], CrateFacility[id][cfPos][2], CrateFacility[id][cfInt], CrateFacility[id][cfVw], pos[0], pos[1], pos[2], GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
  1220. Log("logs/cfedit.log", szMiscArray);
  1221. CrateFacility[id][cfPos][0] = pos[0];
  1222. CrateFacility[id][cfPos][1] = pos[1];
  1223. CrateFacility[id][cfPos][2] = pos[2]-1.0;
  1224. CrateFacility[id][cfInt] = GetPlayerInterior(playerid);
  1225. CrateFacility[id][cfVw] = GetPlayerVirtualWorld(playerid);
  1226. if(CrateFacility[id][cfCooldown] == 0) {
  1227. CrateFacility[id][cfCooldown] = gettime()+10800;
  1228. }
  1229. SendClientMessageEx(playerid, COLOR_WHITE, "You have moved %d crate facility to your location!", id);
  1230. SaveFacility(id);
  1231. UpdateFacility(id);
  1232. return 1;
  1233. }
  1234. else if(strcmp(name, "crates", true) == 0) {
  1235. if(value < 1) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't set the max production lower than 1!");
  1236. if(value > GetMaxProduction()) return SendClientMessageEx(playerid, COLOR_GRAD2, "Your unable to set the production to %d as there's only %d slots left!", id, GetMaxProduction());
  1237. format(szMiscArray, sizeof(szMiscArray), "%s has set %d facility max production from %d to %d.", GetPlayerNameEx(playerid), id, CrateFacility[id][cfProdMax], value);
  1238. Log("logs/cfedit.log", szMiscArray);
  1239. CrateFacility[id][cfProdMax] = value;
  1240. if(CrateFacility[id][cfProdReady] > CrateFacility[id][cfProdMax]) {
  1241. CrateFacility[id][cfProdReady] = value;
  1242. }
  1243. UpdateFacility(id);
  1244. SaveFacility(id);
  1245. SendClientMessageEx(playerid, COLOR_WHITE, "You have set crate facility %d to max production to %d", id, value);
  1246. return 1;
  1247. }
  1248. else if(strcmp(name, "timer", true) == 0) {
  1249. if(value == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "Specify in seconds how long a crate will take to be created.");
  1250. if(value < 1) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't set the max production timer lower than 1!");
  1251. format(szMiscArray, sizeof(szMiscArray), "%s has set %d facility production timer from %d to %d seconds.", GetPlayerNameEx(playerid), id, CrateFacility[id][cfProdTimer], value);
  1252. Log("logs/cfedit.log", szMiscArray);
  1253. CrateFacility[id][cfProdTimer] = value;
  1254. SaveFacility(id);
  1255. SendClientMessageEx(playerid, COLOR_WHITE, "You have set crate facility %d production to %d seconds.", id, value);
  1256. return 1;
  1257. }
  1258. else if(strcmp(name, "prodstatus", true) == 0) {
  1259. if(value == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "0 - Disable | 1 - Active");
  1260. if(!(0 <= value < 2)) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can only choose the following: 0 - Disable | 1 - Active");
  1261. format(szMiscArray, sizeof(szMiscArray), "%s has set %d facility production status from %s to %s.", GetPlayerNameEx(playerid), id, (CrateFacility[id][cfProdStatus]) ? ("Active") : ("Paused"), (value) ? ("Active") : ("Disabled"));
  1262. Log("logs/cfedit.log", szMiscArray);
  1263. CrateFacility[id][cfProdStatus] = value;
  1264. SaveFacility(id);
  1265. SendClientMessageEx(playerid, COLOR_WHITE, "You have set crate facility %d production status to %s.", id, (value) ? ("Active") : ("Paused"));
  1266. return 1;
  1267. }
  1268. else if(strcmp(name, "cost", true) == 0) {
  1269. if(value < 0) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't set the crate cost lower than 0!");
  1270. format(szMiscArray, sizeof(szMiscArray), "%s has set %d facility production cost per crate from $%s to $%s.", GetPlayerNameEx(playerid), id, number_format(CrateFacility[id][cfProdCost]), number_format(value));
  1271. Log("logs/cfedit.log", szMiscArray);
  1272. CrateFacility[id][cfProdCost] = value;
  1273. SaveFacility(id);
  1274. SendClientMessageEx(playerid, COLOR_WHITE, "You have set the facility %d to cost $%s per crate.", id, number_format(value));
  1275. return 1;
  1276. }
  1277. else if(strcmp(name, "active", true) == 0) {
  1278. if(value == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "0 - Disable | 1 - Active");
  1279. if(!(0 <= value < 2)) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can only choose the following: 0 - Disable | 1 - Active");
  1280. format(szMiscArray, sizeof(szMiscArray), "%s has set %d facility status from %s to %s.", GetPlayerNameEx(playerid), id, (CrateFacility[id][cfActive]) ? ("Active") : ("Disabled"), (value) ? ("Active") : ("Disabled"));
  1281. Log("logs/cfedit.log", szMiscArray);
  1282. CrateFacility[id][cfActive] = value;
  1283. SaveFacility(id);
  1284. SendClientMessageEx(playerid, COLOR_WHITE, "You have set crate facility %d status to %s.", id, (value) ? ("Active") : ("Disabled"));
  1285. return 1;
  1286. }
  1287. else if(strcmp(name, "cooldown", true) == 0) {
  1288. if(CrateFacility[id][cfRaidTimer] != 0) return SendClientMessageEx(playerid, COLOR_GRAD2, "ERROR: There is a raid on-going, try again after %s.", date(CrateFacility[id][cfRaidTimer], 1));
  1289. if(value < 1) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't set the cooldown lower than 1 second!");
  1290. CrateFacility[id][cfCooldown] = gettime()+value;
  1291. SaveFacility(id);
  1292. SendClientMessageEx(playerid, COLOR_WHITE, "You have set crate facility %d cooldown to %d.", id, value);
  1293. return 1;
  1294. }
  1295. else if(strcmp(name, "raid", true) == 0) {
  1296. if(CrateFacility[id][cfRaidTimer] == 0) return SendClientMessageEx(playerid, COLOR_GRAD2, "There is no raid on-going.");
  1297. if(value < 1) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't set the raid timer lower than 1 second!");
  1298. CrateFacility[id][cfRaidTimer] = gettime()+value;
  1299. SaveFacility(id);
  1300. SendClientMessageEx(playerid, COLOR_WHITE, "You have set crate facility %d raid timer to %d.", id, value);
  1301. return 1;
  1302. }
  1303. else if(strcmp(name, "multiplier", true) == 0) {
  1304. if(value < 1) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't set the crate multiplier lower than 1!");
  1305. format(szMiscArray, sizeof(szMiscArray), "%s has set %d facility crate delivery multiplier from %d to %d.", GetPlayerNameEx(playerid), id, CrateFacility[id][cfProdMulti], value);
  1306. Log("logs/cfedit.log", szMiscArray);
  1307. CrateFacility[id][cfProdMulti] = value;
  1308. SaveFacility(id);
  1309. SendClientMessageEx(playerid, COLOR_WHITE, "You have set crate facility %d delivery multiplier to %d.", id, value);
  1310. return 1;
  1311. }
  1312. else if(strcmp(name, "raidable", true) == 0) {
  1313. if(!(0 <= value < 2)) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can only choose the following: 0 - Disable | 1 - Active");
  1314. if(CrateFacility[id][cfRaidTimer] != 0) return SendClientMessageEx(playerid, COLOR_GRAD2, "ERROR: There is a raid on-going, try again after %s.", date(CrateFacility[id][cfRaidTimer], 1));
  1315. if(value && !CrateFacility[id][cfRaidable]) CrateFacility[id][cfCooldown] = gettime()+10800;
  1316. format(szMiscArray, sizeof(szMiscArray), "%s has set %d facility raidable status from %s to %s.", GetPlayerNameEx(playerid), id, (CrateFacility[id][cfRaidable]) ? ("Active") : ("Disabled"), (value) ? ("Active") : ("Disabled"));
  1317. Log("logs/cfedit.log", szMiscArray);
  1318. CrateFacility[id][cfRaidable] = value;
  1319. SaveFacility(id);
  1320. SendClientMessageEx(playerid, COLOR_WHITE, "You have set crate facility %d raid status to %s.", id, (value) ? ("Active") : ("Disabled"));
  1321. return 1;
  1322. }
  1323. else if(strcmp(name, "owner", true) == 0) {
  1324. new fac;
  1325. GetFacility(value, fac);
  1326. if(value == -1) {
  1327. if(CrateFacility[id][cfGroup] == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "No group is currently assigned to this facility!");
  1328. format(szMiscArray, sizeof(szMiscArray), "%s has removed %s's ownership over %s facility (ID: %d).", GetPlayerNameEx(playerid), arrGroupData[CrateFacility[id][cfGroup]][g_szGroupName], CrateFacility[id][cfName], id);
  1329. Log("logs/cfedit.log", szMiscArray);
  1330. SendClientMessageEx(playerid, COLOR_YELLOW, "You have removed %s's ownership over %s facility (ID: %d).", arrGroupData[CrateFacility[id][cfGroup]][g_szGroupName], CrateFacility[id][cfName], id);
  1331. DeleteOrder(id, "The crate facility ownership was removed.");
  1332. CrateFacility[id][cfGroup] = -1;
  1333. } else {
  1334. if(!(0 <= value < MAX_GROUPS)) return SendClientMessageEx(playerid, COLOR_GRAD2, "Invalid group Id. (0 - %d)", MAX_GROUPS);
  1335. if(CrateFacility[id][cfPos][0] == 0) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't assign a group to facility %d it's currently not in use.", id);
  1336. if(fac != -1) {
  1337. format(szMiscArray, sizeof(szMiscArray), "%s was removed from %s facility (ID: %d) to prevent duplicate ownership.", arrGroupData[CrateFacility[fac][cfGroup]][g_szGroupName], CrateFacility[fac][cfName], fac);
  1338. Log("logs/cfedit.log", szMiscArray);
  1339. SendClientMessageEx(playerid, COLOR_YELLOW, "%s ownership was removed from %s facility (ID: %d) as they can only own 1 faciltiy at a time!", arrGroupData[CrateFacility[fac][cfGroup]][g_szGroupName], CrateFacility[fac][cfName], fac);
  1340. DeleteOrder(fac, "The crate facility ownership was removed.");
  1341. CrateFacility[fac][cfGroup] = -1;
  1342. }
  1343. CrateFacility[id][cfGroup] = value;
  1344. format(szMiscArray, sizeof(szMiscArray), "%s has assigned %s's ownership over %s facility (ID: %d).", GetPlayerNameEx(playerid), arrGroupData[value][g_szGroupName], CrateFacility[id][cfName], id);
  1345. Log("logs/cfedit.log", szMiscArray);
  1346. SendClientMessageEx(playerid, COLOR_YELLOW, "You have assigned %s ownership over %s facility (ID: %d).", arrGroupData[value][g_szGroupName], CrateFacility[id][cfName], id);
  1347. }
  1348. return 1;
  1349. }
  1350. else if(strcmp(name, "delete", true) == 0) {
  1351. if(CrateFacility[id][cfPos][0] == 0) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't delete a non-active facility!");
  1352. DeleteOrder(id, "Crate facility has been deleted.");
  1353. for(new c = 0; c < MAX_CRATES; c++) {
  1354. if(CrateBox[c][cbFacility] == id) {
  1355. DestroyCrate(c);
  1356. }
  1357. }
  1358. for(new g = 0; g < MAX_GATES; g++) {
  1359. if(GateInfo[g][gFacility] == id) {
  1360. GateInfo[g][gFacility] = -1;
  1361. SaveGate(g);
  1362. }
  1363. }
  1364. AdminOpened[id] = 0; // Disable by default.
  1365. CrateBeingProcessed[id] = 0;
  1366. format(CrateFacility[id][cfName], 4, "----");
  1367. CrateFacility[id][cfGroup] = -1;
  1368. CrateFacility[id][cfPos][0] = 0.00000;
  1369. CrateFacility[id][cfPos][1] = 0.00000;
  1370. CrateFacility[id][cfPos][2] = 0.00000;
  1371. CrateFacility[id][cfPos][3] = 0.00000;
  1372. CrateFacility[id][cfInt] = 0;
  1373. CrateFacility[id][cfVw] = 0;
  1374. CrateFacility[id][cfProdMax] = 0;
  1375. CrateFacility[id][cfProdPrep] = 0;
  1376. CrateFacility[id][cfProdReady] = 0;
  1377. CrateFacility[id][cfProdTimer] = 0;
  1378. CrateFacility[id][cfProdStatus] = 0;
  1379. CrateFacility[id][cfProdCost] = 0;
  1380. CrateFacility[id][cfProdMulti] = 1;
  1381. CrateFacility[id][cfRaidTimer] = 0;
  1382. CrateFacility[id][cfCooldown] = 0;
  1383. CrateFacility[id][cfRaidable] = 1;
  1384. CrateFacility[id][cfActive] = 0;
  1385. CrateFacility[id][cfTimer] = 0;
  1386. CrateFacilityRaid[id] = 0;
  1387. UpdateFacility(id);
  1388. SaveFacility(id);
  1389. SendClientMessageEx(playerid, COLOR_WHITE, "You have deleted crate facility %d", id);
  1390. format(szMiscArray, sizeof(szMiscArray), "%s has deleted facility id %d.", GetPlayerNameEx(playerid), id);
  1391. Log("logs/cfedit.log", szMiscArray);
  1392. return 1;
  1393. }
  1394. else SendClientMessageEx(playerid, COLOR_GREY, "Invalid name given.");
  1395. }
  1396. else SendClientMessageEx(playerid, COLOR_GREY, "Your are not authorized to use this command!");
  1397. return 1;
  1398. }
  1399. stock DeleteOrder(facility, reason[]) {
  1400. szMiscArray[0] = 0;
  1401. for(new g = 0; g < MAX_GROUPS; g++) {
  1402. if(CrateOrder[g][coFacility] == facility) {
  1403. new refund = ((CrateOrder[g][coCrates] - CrateOrder[g][coDelivered]) * CrateOrder[g][coPerCrate]);
  1404. foreach(new p: Player) {
  1405. if(PlayerInfo[p][pMember] == CrateFacility[CrateOrder[g][coFacility]][cfGroup]) {
  1406. SendClientMessageEx(p, COLOR_LIGHTRED, "%s order was auto canceled; %d/%d crates were delivered earning: $%s.", arrGroupData[g][g_szGroupName], CrateOrder[g][coDelivered], CrateOrder[g][coCrates], number_format(CrateOrder[g][coDelivered] * CrateOrder[g][coPerCrate]));
  1407. SendClientMessageEx(p, COLOR_LIGHTRED, "Reason: %s", reason);
  1408. }
  1409. if(PlayerInfo[p][pLeader] == g) {
  1410. SendClientMessageEx(p, COLOR_LIGHTRED, "* Your crate order was auto canceled; %d/%d crates were delivered costing: $%s", CrateOrder[g][coDelivered], CrateOrder[g][coCrates], number_format(CrateOrder[g][coDelivered] * CrateOrder[g][coPerCrate]));
  1411. SendClientMessageEx(p, COLOR_LIGHTRED, "* $%s was refunded back into the vault for undelivered crates.", number_format(refund));
  1412. SendClientMessageEx(p, COLOR_LIGHTRED, "* Reason: %s", reason);
  1413. }
  1414. }
  1415. format(szMiscArray, sizeof(szMiscArray), "Your crate order was auto canceled ; %d/%d crates were delivered costing: $%s ($%s was refunded)", CrateOrder[g][coDelivered], CrateOrder[g][coCrates], number_format(CrateOrder[g][coDelivered] * CrateOrder[g][coPerCrate]), number_format(refund));
  1416. format(szMiscArray, sizeof(szMiscArray), "%sReason: %s", szMiscArray, reason);
  1417. GroupPayLog(g, szMiscArray);
  1418. SetGroupBudget(g, refund);
  1419. format(szMiscArray, sizeof(szMiscArray), "%s order was auto canceled; %d/%d crates were delivered adding: $%s.", arrGroupData[g][g_szGroupName], CrateOrder[g][coDelivered], CrateOrder[g][coCrates], number_format(CrateOrder[g][coDelivered] * CrateOrder[g][coPerCrate]), number_format(refund));
  1420. format(szMiscArray, sizeof(szMiscArray), "%sReason: %s", szMiscArray, reason);
  1421. GroupPayLog(CrateFacility[CrateOrder[g][coFacility]][cfGroup], szMiscArray);
  1422. SetGroupBudget(CrateFacility[CrateOrder[g][coFacility]][cfGroup], (CrateOrder[g][coDelivered] * CrateOrder[g][coPerCrate]));
  1423. ResetOrder(g);
  1424. SaveGroup(g);
  1425. }
  1426. }
  1427. return 1;
  1428. }
  1429. stock GetMaxProduction() {
  1430. new total = 0;
  1431. for(new f = 0; f < MAX_CRATE_FACILITY; f++) {
  1432. total += CrateFacility[f][cfProdMax];
  1433. }
  1434. return (MAX_CRATES - total);
  1435. }
  1436. CMD:ordercrates(playerid, params[]) {
  1437. new group = PlayerInfo[playerid][pMember];
  1438. if(ValidGroup(group)) {
  1439. if(!IsGroupLeader(playerid)) return SendClientMessageEx(playerid, COLOR_GRAD2, "You need to be a group leader to order crates!");
  1440. if(IsACriminal(playerid)) return SendClientMessageEx(playerid, COLOR_GRAD2, "You're unable to order crates from any facility.");
  1441. //if(CrateOrder[group][coFacility] != -1 && CrateOrder[group][coStatus] > 1 && CrateOrder[group][coTime] > gettime()) return SendClientMessageEx(playerid, COLOR_GRAD2, "Your order is currently being processed; You can cancel it after %s", date(CrateOrder[group][coTime], 1));
  1442. if(!CrateOrder[group][coStatus]) {
  1443. PrepOrder(playerid, group);
  1444. } else {
  1445. CancelOrder(playerid);
  1446. }
  1447. }
  1448. else SendClientMessageEx(playerid, COLOR_GRAD2, "You need to be a group use this command!");
  1449. return 1;
  1450. }
  1451. stock CancelOrder(playerid) {
  1452. szMiscArray[0] = 0;
  1453. if(!IsGroupLeader(playerid)) return 1;
  1454. new group = PlayerInfo[playerid][pMember];
  1455. new refund = ((CrateOrder[group][coCrates] - CrateOrder[group][coDelivered]) * CrateOrder[group][coPerCrate]);
  1456. format(szMiscArray, sizeof(szMiscArray), "Are you sure you want to cancel the order you made at %s?\n", CrateFacility[CrateOrder[group][coFacility]][cfName]);
  1457. format(szMiscArray, sizeof(szMiscArray), "%sPlease see transaction information below:\n\n", szMiscArray);
  1458. format(szMiscArray, sizeof(szMiscArray), "%sCrates Ordered: %d\nTotal Cost: $%s\nCrates Delivered: %d\nTotal Spent: $%s\nOrdered By: %s\nTotal to Refund: $%s.\n\n", szMiscArray, CrateOrder[group][coCrates], number_format((CrateOrder[group][coCrates] * CrateOrder[group][coPerCrate])), CrateOrder[group][coDelivered], number_format((CrateOrder[group][coDelivered] * CrateOrder[group][coPerCrate])), CrateOrder[group][coOrderBy], number_format(refund));
  1459. format(szMiscArray, sizeof(szMiscArray), "%sPress 'Confirm' to cancel further crates from being delivered.", szMiscArray, number_format(refund));
  1460. return Dialog_Show(playerid, order_refund, DIALOG_STYLE_MSGBOX, "Cancel Order?", szMiscArray, "Confirm", "Exit");
  1461. }
  1462. Dialog:order_refund(playerid, response, listitem, inputtext[]) {
  1463. if(!IsGroupLeader(playerid)) return SendClientMessageEx(playerid, COLOR_GRAD2, "You need to be a group leader to order crates!");
  1464. new group = PlayerInfo[playerid][pMember];
  1465. if(response) {
  1466. if(!CrateOrder[group][coStatus]) return SendClientMessageEx(playerid, COLOR_RED, "ERROR: You don't have any crate orders pending!");
  1467. new refund = ((CrateOrder[group][coCrates] - CrateOrder[group][coDelivered]) * CrateOrder[group][coPerCrate]), type = (arrGroupData[PlayerInfo[playerid][pMember]][g_iAllegiance] == 2) ? 8 : 5;
  1468. if(CrateFacility[CrateOrder[group][coFacility]][cfGroup] == PlayerInfo[playerid][pMember]) {
  1469. foreach(new p: Player) {
  1470. if(PlayerInfo[p][pMember] == type) {
  1471. SendClientMessageEx(p, COLOR_LIGHTRED, "%s has canceled their own order; %d/%d crates were delivered earning: $%s.", arrGroupData[group][g_szGroupName], CrateOrder[group][coDelivered], CrateOrder[group][coCrates], number_format(CrateOrder[group][coDelivered] * CrateOrder[group][coPerCrate]));
  1472. }
  1473. if(PlayerInfo[p][pLeader] == group) {
  1474. SendClientMessageEx(p, COLOR_LIGHTRED, "* %s %s has canceled the crate order; %d/%d crates were delivered costing: $%s", arrGroupRanks[group][PlayerInfo[playerid][pRank]], GetPlayerNameEx(playerid), CrateOrder[group][coDelivered], CrateOrder[group][coCrates], number_format(CrateOrder[group][coDelivered] * CrateOrder[group][coPerCrate]));
  1475. SendClientMessageEx(p, COLOR_LIGHTRED, "* $%s was refunded back into the vault for undelivered crates.", number_format(refund));
  1476. }
  1477. }
  1478. format(szMiscArray, sizeof(szMiscArray), "%s %s has canceled the crate order; %d/%d crates were delivered costing: $%s ($%s was refunded)", arrGroupRanks[group][PlayerInfo[playerid][pRank]], GetPlayerNameEx(playerid), CrateOrder[group][coDelivered], CrateOrder[group][coCrates], number_format(CrateOrder[group][coDelivered] * CrateOrder[group][coPerCrate]), number_format(refund));
  1479. GroupPayLog(group, szMiscArray);
  1480. SetGroupBudget(group, refund);
  1481. format(szMiscArray, sizeof(szMiscArray), "%s has canceled their crate order; %d/%d crates were delivered adding: $%s.", arrGroupData[group][g_szGroupName], CrateOrder[group][coDelivered], CrateOrder[group][coCrates], number_format(CrateOrder[group][coDelivered] * CrateOrder[group][coPerCrate]), number_format(refund));
  1482. GroupPayLog(type, szMiscArray);
  1483. SetGroupBudget(type, (CrateOrder[group][coDelivered] * CrateOrder[group][coPerCrate]));
  1484. } else {
  1485. foreach(new p: Player) {
  1486. if(PlayerInfo[p][pMember] == CrateFacility[CrateOrder[group][coFacility]][cfGroup]) {
  1487. SendClientMessageEx(p, COLOR_LIGHTRED, "%s has canceled their order; %d/%d crates were delivered earning: $%s.", arrGroupData[group][g_szGroupName], CrateOrder[group][coDelivered], CrateOrder[group][coCrates], number_format(CrateOrder[group][coDelivered] * CrateOrder[group][coPerCrate]));
  1488. }
  1489. if(PlayerInfo[p][pLeader] == group) {
  1490. SendClientMessageEx(p, COLOR_LIGHTRED, "* %s %s has canceled the crate order; %d/%d crates were delivered costing: $%s", arrGroupRanks[group][PlayerInfo[playerid][pRank]], GetPlayerNameEx(playerid), CrateOrder[group][coDelivered], CrateOrder[group][coCrates], number_format(CrateOrder[group][coDelivered] * CrateOrder[group][coPerCrate]));
  1491. SendClientMessageEx(p, COLOR_LIGHTRED, "* $%s was refunded back into the vault for undelivered crates.", number_format(refund));
  1492. }
  1493. }
  1494. format(szMiscArray, sizeof(szMiscArray), "%s %s has canceled the crate order; %d/%d crates were delivered costing: $%s ($%s was refunded)", arrGroupRanks[group][PlayerInfo[playerid][pRank]], GetPlayerNameEx(playerid), CrateOrder[group][coDelivered], CrateOrder[group][coCrates], number_format(CrateOrder[group][coDelivered] * CrateOrder[group][coPerCrate]), number_format(refund));
  1495. GroupPayLog(group, szMiscArray);
  1496. SetGroupBudget(group, refund);
  1497. format(szMiscArray, sizeof(szMiscArray), "%s has canceled their crate order; %d/%d crates were delivered adding: $%s.", arrGroupData[group][g_szGroupName], CrateOrder[group][coDelivered], CrateOrder[group][coCrates], number_format(CrateOrder[group][coDelivered] * CrateOrder[group][coPerCrate]), number_format(refund));
  1498. GroupPayLog(CrateFacility[CrateOrder[group][coFacility]][cfGroup], szMiscArray);
  1499. SetGroupBudget(CrateFacility[CrateOrder[group][coFacility]][cfGroup], (CrateOrder[group][coDelivered] * CrateOrder[group][coPerCrate]));
  1500. }
  1501. ResetOrder(group);
  1502. SaveGroup(group);
  1503. }
  1504. return 1;
  1505. }
  1506. stock PrepOrder(playerid, group) {
  1507. if(!IsGroupLeader(playerid)) return 1;
  1508. new fname[32];
  1509. szMiscArray[0] = 0;
  1510. if(CrateOrder[group][coFacility] != -1) {
  1511. format(fname, sizeof(fname), "%s", CrateFacility[CrateOrder[group][coFacility]][cfName]);
  1512. } else {
  1513. format(fname, sizeof(fname), "Not Selected");
  1514. }
  1515. format(szMiscArray, sizeof(szMiscArray),
  1516. "{BBBBBB}Which facility?:\t{FFFFFF}%s\n\
  1517. {BBBBBB}How many crates?:\t{FFFFFF}%s ($%s)\n\
  1518. {40FFFF}How it works\n\
  1519. {FFD700}Confirm Order",
  1520. fname,
  1521. number_format(CrateOrder[group][coCrates]), number_format((CrateOrder[group][coCrates] * CrateOrder[group][coPerCrate]))
  1522. );
  1523. return Dialog_Show(playerid, place_order, DIALOG_STYLE_TABLIST, "Place Order", szMiscArray, "Select", "Cancel");
  1524. }
  1525. Dialog:place_order(playerid, response, listitem, inputtext[]) {
  1526. if(!IsGroupLeader(playerid)) return 1;
  1527. if(response) {
  1528. szMiscArray[0] = 0;
  1529. new group = PlayerInfo[playerid][pMember];
  1530. switch(listitem) {
  1531. case 0: {
  1532. ListFacility(playerid);
  1533. }
  1534. case 1: {
  1535. if(CrateOrder[group][coFacility] == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "You must choose a facility to order crates from!"), PrepOrder(playerid, group);
  1536. format(szMiscArray, sizeof(szMiscArray), "Please specify how many crates you'd like to order.\n\nPrice per crate: $%s", number_format(CrateFacility[CrateOrder[group][coFacility]][cfProdCost]));
  1537. Dialog_Show(playerid, crate_total, DIALOG_STYLE_INPUT, "How many Crates would you like?", szMiscArray, "Ok", "Go Back");
  1538. }
  1539. case 2: {
  1540. szMiscArray = "{FFFFFF}_______________________________________________________________________________________________________________________________________________________\n\n";
  1541. strcat(szMiscArray, "{40FFFF}Information: How ordering crates works{FFFFFF}\n\n");
  1542. strcat(szMiscArray, "When ordering crates you'll see an overview of which 'Facility' you would like to order from along with how much each crate will cost.\n");
  1543. strcat(szMiscArray, "Once you've selected your facility of choice you'll be able to enter how many 'Crates' you would like (Max of 50 crates can be ordered at once)\n\n");
  1544. strcat(szMiscArray, "You'll see how much in total it will charge your group in brackets once you've confirm your order the money will taken out the vault to pay\n");
  1545. strcat(szMiscArray, "for each crate delivered, the price per crate will also locked so if the facility was to adjust the price your price per crate at the time of\n");
  1546. strcat(szMiscArray, "ordering will not change! (This is to prevent abuse from facility owners)\n\n");
  1547. strcat(szMiscArray, "You may cancel your order at any time by using /ordercrates again, when cancelling an order you'll see a transaction of how many were delivered\n");
  1548. strcat(szMiscArray, "and how much money will be refunded back into your vault.\n\n");
  1549. strcat(szMiscArray, "{FFFFFF}_______________________________________________________________________________________________________________________________________________________");
  1550. Dialog_Show(playerid, how_crates_work, DIALOG_STYLE_MSGBOX, "How crate ordering works", szMiscArray, "Go Back", "");
  1551. }
  1552. case 3: {
  1553. if(CrateOrder[group][coFacility] == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "ERROR: Facility selection is required!"), PrepOrder(playerid, group);
  1554. if(CrateOrder[group][coCrates] < 1) return SendClientMessageEx(playerid, COLOR_GRAD2, "ERROR: You must select how many crates you'd like!"), PrepOrder(playerid, group);
  1555. if(!CrateFacility[CrateOrder[group][coFacility]][cfActive] || CrateFacility[CrateOrder[group][coFacility]][cfGroup] == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "The selected facility is unaviliable to take orders!"), PrepOrder(playerid, group);
  1556. if(CrateFacility[CrateOrder[group][coFacility]][cfProdCost] < 1) return SendClientMessageEx(playerid, COLOR_GRAD2, "The facility your trying to select hasn't got a production cost setup!"), PrepOrder(playerid, group);
  1557. //if(CrateFacility[CrateOrder[group][coFacility]][cfGroup] == group) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't order from your own facility; You can deliver them manually."), PrepOrder(playerid, group);
  1558. new cost = (CrateOrder[group][coCrates] * CrateOrder[group][coPerCrate]);
  1559. if(GetGroupBudget(group) < cost) return SendClientMessageEx(playerid, COLOR_RED, "ERROR: Your group can't afford that many crates!"), PrepOrder(playerid, group);
  1560. if(ValidGroup(CrateOrder[group][coFacility])) {
  1561. foreach(new p: Player) {
  1562. if(PlayerInfo[p][pMember] == CrateFacility[CrateOrder[group][coFacility]][cfGroup]) {
  1563. SendClientMessageEx(p, COLOR_LIGHTRED, "%s has placed an order for %d crates! (( /crate orders ))", arrGroupData[group][g_szGroupName], CrateOrder[group][coCrates]);
  1564. }
  1565. if(PlayerInfo[p][pLeader] == group) {
  1566. SendClientMessageEx(p, COLOR_LIGHTRED, "%s %s has placed an order for %d crates at %s.", arrGroupRanks[group][PlayerInfo[playerid][pRank]], GetPlayerNameEx(playerid), CrateOrder[group][coCrates], CrateFacility[CrateOrder[group][coFacility]][cfName]);
  1567. }
  1568. }
  1569. }
  1570. CrateOrder[group][coOrderBy] = GetPlayerNameEx(playerid);
  1571. CrateOrder[group][coStatus] = 1;
  1572. SaveOrder(group);
  1573. SetGroupBudget(group, -cost);
  1574. SaveGroup(group);
  1575. SendClientMessageEx(playerid, COLOR_WHITE, "You have placed an order for %d crates at %s costing $%s", CrateOrder[group][coCrates], CrateFacility[CrateOrder[group][coFacility]][cfName], number_format(cost));
  1576. SendClientMessageEx(playerid, COLOR_WHITE, "$%s has been deducted from your group vault in preparation for the order.", number_format(cost));
  1577. SendClientMessageEx(playerid, COLOR_YELLOW, "INFO: You can manage your order via the /ordercrates again.");
  1578. format(szMiscArray, sizeof(szMiscArray), "%s %s has placed order for %d crates at %s costing $%s", arrGroupRanks[group][PlayerInfo[playerid][pRank]], GetPlayerNameEx(playerid), CrateOrder[group][coCrates], CrateFacility[CrateOrder[group][coFacility]][cfName], number_format(cost));
  1579. GroupPayLog(group, szMiscArray);
  1580. }
  1581. }
  1582. }
  1583. return 1;
  1584. }
  1585. stock ListFacility(playerid) {
  1586. if(!IsGroupLeader(playerid)) return 1;
  1587. szMiscArray[0] = 0;
  1588. format(szMiscArray, sizeof(szMiscArray), "Facility\tCost per crate\tActive\n");
  1589. for(new f = 0; f < MAX_CRATE_FACILITY; f++) {
  1590. format(szMiscArray, sizeof(szMiscArray), "%s%s\t$%s\t%s\n", szMiscArray, CrateFacility[f][cfName], number_format(CrateFacility[f][cfProdCost]), (CrateFacility[f][cfActive]) ? ("Yes") : ("No"));
  1591. }
  1592. return Dialog_Show(playerid, select_facility, DIALOG_STYLE_TABLIST_HEADERS, "Which Facility to use?", szMiscArray, "Select", "Go Back");
  1593. }
  1594. Dialog:select_facility(playerid, response, listitem, inputtext[]) {
  1595. if(!IsGroupLeader(playerid)) return 1;
  1596. new group = PlayerInfo[playerid][pMember];
  1597. if(response) {
  1598. if(!(0 <= listitem < MAX_CRATE_FACILITY)) return SendClientMessageEx(playerid, COLOR_RED, "ERROR - Something went wrong; Please try again!"), ListFacility(playerid);
  1599. if(!CrateFacility[listitem][cfActive] || CrateFacility[listitem][cfGroup] == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "The facility your trying to select isn't available to take orders!"), ListFacility(playerid);
  1600. if(CrateFacility[listitem][cfProdCost] < 1) return SendClientMessageEx(playerid, COLOR_GRAD2, "The facility your trying to select hasn't got a production cost setup!"), ListFacility(playerid);
  1601. //if(CrateFacility[listitem][cfGroup] == group) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't order from your own facility; You can deliver them manually."), ListFacility(playerid);
  1602. CrateOrder[group][coFacility] = listitem;
  1603. CrateOrder[group][coCrates] = 0;
  1604. CrateOrder[group][coPerCrate] = 0;
  1605. SendClientMessageEx(playerid, COLOR_WHITE, "You have selected to order crates from %s.", CrateFacility[listitem][cfName]);
  1606. SaveOrder(group);
  1607. PrepOrder(playerid, group);
  1608. } else {
  1609. PrepOrder(playerid, group);
  1610. }
  1611. return 1;
  1612. }
  1613. Dialog:crate_total(playerid, response, listitem, inputtext[]) {
  1614. if(!IsGroupLeader(playerid)) return 1;
  1615. new group = PlayerInfo[playerid][pMember];
  1616. szMiscArray[0] = 0;
  1617. if(response) {
  1618. new total = strval(inputtext);
  1619. if(!(0 < total < 51)) {
  1620. format(szMiscArray, sizeof(szMiscArray), "{FFFFFF}Please specify how many crates you'd like to order.\n\nPrice per crate: $%s\n\n{FF0000}ERROR: You can only order between 1 to 50 crates at once!", number_format(CrateFacility[CrateOrder[group][coFacility]][cfProdCost]));
  1621. Dialog_Show(playerid, crate_total, DIALOG_STYLE_INPUT, "How many Crates would you like?", szMiscArray, "Ok", "Go Back");
  1622. return 1;
  1623. }
  1624. if(GetGroupBudget(group) < (CrateFacility[CrateOrder[group][coFacility]][cfProdCost] * total)) {
  1625. format(szMiscArray, sizeof(szMiscArray), "{FFFFFF}Please specify how many crates you'd like to order.\n\nPrice per crate: $%s\n\n{FF0000}ERROR: Your group can't afford %s crates!\n{FFFFFF}Budget: $%s | Cost Amount: $%s", number_format(CrateFacility[CrateOrder[group][coFacility]][cfProdCost]), number_format(total), number_format(GetGroupBudget(group)), number_format(CrateFacility[CrateOrder[group][coFacility]][cfProdCost] * total));
  1626. Dialog_Show(playerid, crate_total, DIALOG_STYLE_INPUT, "How many Crates would you like?", szMiscArray, "Ok", "Go Back");
  1627. return 1;
  1628. }
  1629. CrateOrder[group][coCrates] = total;
  1630. CrateOrder[group][coPerCrate] = CrateFacility[CrateOrder[group][coFacility]][cfProdCost];
  1631. SaveOrder(group);
  1632. SendClientMessageEx(playerid, COLOR_WHITE, "You have selected to order %d crates from %s.", total, CrateFacility[CrateOrder[group][coFacility]][cfName]);
  1633. PrepOrder(playerid, group);
  1634. } else {
  1635. PrepOrder(playerid, group);
  1636. }
  1637. return 1;
  1638. }
  1639. Dialog:how_crates_work(playerid, response, listitem, inputtext[]) {
  1640. if(!IsGroupLeader(playerid)) return 1;
  1641. return PrepOrder(playerid, PlayerInfo[playerid][pMember]);
  1642. }
  1643. stock GetFacility(group, &fac) {
  1644. fac = -1;
  1645. for(new f = 0; f < MAX_CRATE_FACILITY; f++)
  1646. {
  1647. if(group == CrateFacility[f][cfGroup])
  1648. {
  1649. fac = f;
  1650. break;
  1651. }
  1652. }
  1653. }
  1654. stock ResetOrder(group) {
  1655. if(!ValidGroup(group)) return 1;
  1656. CrateOrder[group][coFacility] = -1;
  1657. CrateOrder[group][coCrates] = 0;
  1658. CrateOrder[group][coPerCrate] = 0;
  1659. CrateOrder[group][coDelivered] = 0;
  1660. CrateOrder[group][coStatus] = 0;
  1661. CrateOrder[group][coTime] = 0;
  1662. SaveOrder(group);
  1663. return 1;
  1664. }
  1665. stock GetDeliverPoint(playerid, &point, Float:range)
  1666. {
  1667. point = -1;
  1668. for(new d = 0; d < MAX_GROUPS; d++)
  1669. {
  1670. if(IsPlayerInRangeOfPoint(playerid, range, arrGroupData[d][g_fCratePos][0], arrGroupData[d][g_fCratePos][1], arrGroupData[d][g_fCratePos][2]))
  1671. {
  1672. point = d;
  1673. break;
  1674. }
  1675. }
  1676. }
  1677. CMD:delivercrate(playerid, params[]) {
  1678. new fac, veh, crates, point;
  1679. if(!ValidGroup(PlayerInfo[playerid][pMember])) return SendClientMessage(playerid, COLOR_GRAD2, "You need to be apart of a group to use this command!");
  1680. GetDeliverPoint(playerid, point, 6);
  1681. GetFacility(PlayerInfo[playerid][pMember], fac);
  1682. if(fac == -1) return SendClientMessage(playerid, COLOR_GRAD2, "You group doesn't own a crate facility, you can't process orders!");
  1683. if((veh = IsDynamicCrateVehicle(GetPlayerVehicleID(playerid))) == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "You're not in the designated vehicle for this operation!");
  1684. if(point == -1) return SendClientMessageEx(playerid, COLOR_GRAD2, "You're not near any crate delivery points!");
  1685. if(CrateBeingDelivered[point]) return SendClientMessageEx(playerid, COLOR_GRAD2, "Someone else is currently delivering crates! - Please Wait.");
  1686. if(CrateOrder[point][coFacility] != fac) return SendClientMessageEx(playerid, COLOR_GRAD2, "%s hasn't made any crate orders at your facility.", arrGroupData[point][g_szGroupName]);
  1687. for(new c = 0; c < MAX_CRATES; c++) {
  1688. if(CrateBox[c][cbActive]) {
  1689. if(CrateBox[c][cbFacility] == fac && CrateBox[c][cbInVeh] == veh) {
  1690. ++crates;
  1691. }
  1692. }
  1693. }
  1694. if(!crates) return SendClientMessageEx(playerid, COLOR_GRAD2, "There are no crates from your facility in this vehicle to deliver!");
  1695. CrateBeingDelivered[point] = 1;
  1696. VehDelivering[veh] = 1;
  1697. SetPVarInt(playerid, "DeliverCrateTime", 8);
  1698. SetTimerEx("DeliverCrate", 1000, 0, "iiiii", playerid, fac, veh, point, crates);
  1699. GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~n~~n~~n~~n~~w~8 seconds left", 1100, 3);
  1700. TogglePlayerControllable(playerid, 0);
  1701. return 1;
  1702. }
  1703. forward DeliverCrate(playerid, fac, veh, point, crates);
  1704. public DeliverCrate(playerid, fac, veh, point, crates) {
  1705. szMiscArray[0] = 0;
  1706. new string[128];
  1707. SetPVarInt(playerid, "DeliverCrateTime", GetPVarInt(playerid, "DeliverCrateTime")-1);
  1708. format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~w~%d seconds left", GetPVarInt(playerid, "DeliverCrateTime"));
  1709. GameTextForPlayer(playerid, string, 1100, 3);
  1710. if(GetPVarInt(playerid, "DeliverCrateTime") > 0) SetTimerEx("DeliverCrate", 1000, 0, "iiiii", playerid, fac, veh, point, crates);
  1711. if(GetPVarInt(playerid, "DeliverCrateTime") < 1) {
  1712. DeletePVar(playerid, "DeliverCrateTime");
  1713. TogglePlayerControllable(playerid, 1);
  1714. CrateBeingDelivered[point] = 0;
  1715. VehDelivering[veh] = 0;
  1716. if(!ValidGroup(PlayerInfo[playerid][pMember])) {
  1717. SendClientMessageEx(playerid, COLOR_GRAD2, "You failed to deliver any crates. You're no longer apart of a group!");
  1718. return 1;
  1719. }
  1720. if(IsDynamicCrateVehicle(GetPlayerVehicleID(playerid)) != veh) {
  1721. SendClientMessageEx(playerid, COLOR_GRAD2, "You failed to deliver any crates, You're no longer in the vehicle that you were delivering from!");
  1722. return 1;
  1723. }
  1724. if(PlayerInfo[playerid][pMember] != CrateFacility[fac][cfGroup]) {
  1725. SendClientMessageEx(playerid, COLOR_GRAD2, "You failed to deliver any crates, Your group no longer owns the facility!");
  1726. return 1;
  1727. }
  1728. if(!IsPlayerInRangeOfPoint(playerid, 6.0, arrGroupData[point][g_fCratePos][0], arrGroupData[point][g_fCratePos][1], arrGroupData[point][g_fCratePos][2])) {
  1729. SendClientMessageEx(playerid, COLOR_GRAD2, "You failed to deliver any crates, You're no longer at the delivery point!");
  1730. return 1;
  1731. }
  1732. if(playerTabbed[playerid] != 0) {
  1733. SendClientMessageEx(playerid, COLOR_GRAD2, "You failed to deliver any crates, you were alt-tabbed.");
  1734. return 1;
  1735. }
  1736. if(CrateOrder[point][coFacility] != fac) {
  1737. SendClientMessageEx(playerid, COLOR_GRAD2, "You failed to deliver any crates, %s has canceled their order.", arrGroupData[point][g_szGroupName]);
  1738. return 1;
  1739. }
  1740. CrateOrder[point][coDelivered] += crates;
  1741. if(CrateOrder[point][coDelivered] > CrateOrder[point][coCrates]) {
  1742. crates = ((CrateOrder[point][coCrates] + crates) - CrateOrder[point][coDelivered]);
  1743. CrateOrder[point][coDelivered] = CrateOrder[point][coCrates];
  1744. }
  1745. if(CrateOrder[point][coDelivered] >= CrateOrder[point][coCrates]) {
  1746. if(point == PlayerInfo[playerid][pMember]) {
  1747. new type = (arrGroupData[PlayerInfo[playerid][pMember]][g_iAllegiance] == 2) ? 8 : 5;
  1748. foreach(new p: Player) {
  1749. if(PlayerInfo[p][pMember] == type) {
  1750. SendClientMessageEx(p, COLOR_LIGHTRED, "* %s's own crate order has been completed; %d crates were delivered earning: $%s.", arrGroupData[point][g_szGroupName], CrateOrder[point][coCrates], number_format(CrateOrder[point][coCrates] * CrateOrder[point][coPerCrate]));
  1751. }
  1752. if(PlayerInfo[p][pLeader] == point) {
  1753. SendClientMessageEx(p, COLOR_LIGHTRED, "* %s facility has completed your crate order; You can now submit a new order.", CrateFacility[fac][cfName]);
  1754. }
  1755. }
  1756. SetGroupBudget(type, (CrateOrder[point][coCrates] * CrateOrder[point][coPerCrate]));
  1757. format(szMiscArray, sizeof(szMiscArray), "%s's own crate order was sucesfully completed %d crates were delivered adding: $%s.", arrGroupData[point][g_szGroupName], CrateOrder[point][coCrates], number_format(CrateOrder[point][coCrates] * CrateOrder[point][coPerCrate]));
  1758. GroupPayLog(type, szMiscArray);
  1759. format(szMiscArray, sizeof(szMiscArray), "%s facility has successfully delivered all %d crates to your locker.", CrateFacility[fac][cfName], CrateOrder[point][coCrates]);
  1760. CrateLog(point, szMiscArray);
  1761. } else {
  1762. foreach(new p: Player) {
  1763. if(PlayerInfo[p][pMember] == CrateFacility[CrateOrder[point][coFacility]][cfGroup]) {
  1764. SendClientMessageEx(p, COLOR_LIGHTRED, "* %s's crate order has been completed; %d crates were delivered earning: $%s.", arrGroupData[point][g_szGroupName], CrateOrder[point][coCrates], number_format(CrateOrder[point][coCrates] * CrateOrder[point][coPerCrate]));
  1765. }
  1766. if(PlayerInfo[p][pLeader] == point) {
  1767. SendClientMessageEx(p, COLOR_LIGHTRED, "* %s facility has completed your crate order; You can now submit a new order.", CrateFacility[fac][cfName]);
  1768. }
  1769. }
  1770. SetGroupBudget(CrateFacility[CrateOrder[point][coFacility]][cfGroup], (CrateOrder[point][coCrates] * CrateOrder[point][coPerCrate]));
  1771. format(szMiscArray, sizeof(szMiscArray), "%s's crate order was sucesfully completed %d crates were delivered adding: $%s.", arrGroupData[point][g_szGroupName], CrateOrder[point][coCrates], number_format(CrateOrder[point][coCrates] * CrateOrder[point][coPerCrate]));
  1772. GroupPayLog(CrateFacility[CrateOrder[point][coFacility]][cfGroup], szMiscArray);
  1773. format(szMiscArray, sizeof(szMiscArray), "%s facility has successfully delivered all %d crates to your locker.", CrateFacility[fac][cfName], CrateOrder[point][coCrates]);
  1774. CrateLog(point, szMiscArray);
  1775. }
  1776. SaveGroup(CrateFacility[CrateOrder[point][coFacility]][cfGroup]);
  1777. ResetOrder(point);
  1778. } else {
  1779. format(szMiscArray, sizeof(szMiscArray), "%s has delivered %d crates to %s (Total delivered: %d/%d)", GetPlayerNameEx(playerid), crates, arrGroupData[point][g_szGroupName], CrateOrder[point][coDelivered], CrateOrder[point][coCrates]);
  1780. CrateLog(CrateFacility[CrateOrder[point][coFacility]][cfGroup], szMiscArray);
  1781. SendClientMessageEx(playerid, COLOR_LIGHTRED, "* You have delivered %d crates to %s; Total delivered: %d/%d", crates, arrGroupData[point][g_szGroupName], CrateOrder[point][coDelivered], CrateOrder[point][coCrates]);
  1782. }
  1783. SaveOrder(point);
  1784. for(new c = 0; c < MAX_CRATES; c++) {
  1785. if(CrateBox[c][cbFacility] == fac && CrateBox[c][cbInVeh] == veh) {
  1786. if(crates > 0) {
  1787. arrGroupData[point][g_iLockerStock] += floatround(CrateBox[c][cbMats] * CrateFacility[CrateBox[c][cbFacility]][cfProdMulti]);
  1788. DestroyCrate(c);
  1789. --crates;
  1790. }
  1791. }
  1792. }
  1793. SaveWeapons(point);
  1794. if(CreateCount(veh) > 0) SendClientMessageEx(playerid, COLOR_LIGHTBLUE, "You have %d crate(s) remaining that wasn't used for the delivery.", CreateCount(veh));
  1795. }
  1796. return 1;
  1797. }
  1798. CMD:cgun(playerid, params[]) {
  1799. szMiscArray[0] = 0;
  1800. new box, title[32];
  1801. if(!ValidGroup(PlayerInfo[playerid][pMember])) return SendClientMessageEx(playerid, COLOR_GRAD1, "You need to be apart of a group to use this command!");
  1802. if(PlayerInfo[playerid][pAccountRestricted] != 0) return SendClientMessageEx(playerid, COLOR_GRAD1, "Your account is restricted!");
  1803. if(PlayerInfo[playerid][pWRestricted] > 0) return SendClientMessageEx(playerid, COLOR_GRAD1, "You can't take weapons out as you're currently weapon restricted!");
  1804. if(PlayerBusy(playerid)) return SendClientMessageEx(playerid, COLOR_GRAD2, "You can't do that right now.");
  1805. GetCrateBox(playerid, box, 2.0);
  1806. if(box == -1) return SendClientMessageEx(playerid, COLOR_GREY, "You're not near any crate boxes.");
  1807. if(CrateBox[box][cbGroup] != -1) return SendClientMessageEx(playerid, COLOR_GREY, "This is a transfer crate use \"/crate contents\" instead!");
  1808. if(IsInRangeOfPoint(CrateFacility[CrateBox[box][cbFacility]][cfPos][0], CrateFacility[CrateBox[box][cbFacility]][cfPos][1], CrateFacility[CrateBox[box][cbFacility]][cfPos][2], CrateBox[box][cbPos][0], CrateBox[box][cbPos][1], CrateBox[box][cbPos][2], 500.0))
  1809. return SendClientMessageEx(playerid, COLOR_GRAD2, "ERROR: This crate has been sealed shut by the Crate Island's security system!");
  1810. SetPVarInt(playerid, "Cgunbox", box);
  1811. format(title, sizeof(title), "Crate Box Withdraw - Mats: %d", CrateBox[box][cbMats]);
  1812. format(szMiscArray, sizeof(szMiscArray), "Weapon\tCost\n");
  1813. for(new i = 0; i != MAX_GROUP_WEAPONS; ++i) {
  1814. if(arrGroupData[PlayerInfo[playerid][pMember]][g_iLockerGuns][i]) {
  1815. format(szMiscArray, sizeof szMiscArray, "%s\n%s\t%d", szMiscArray, Weapon_ReturnName(arrGroupData[PlayerInfo[playerid][pMember]][g_iLockerGuns][i]), arrGroupData[PlayerInfo[playerid][pMember]][g_iLockerCost][i]);
  1816. }
  1817. else strcat(szMiscArray, "\nEmpty\t--");
  1818. }
  1819. Dialog_Show(playerid, cgun_take, DIALOG_STYLE_TABLIST_HEADERS, title, szMiscArray, "Select", "Go Back");
  1820. return 1;
  1821. }
  1822. Dialog:cgun_take(playerid, response, listitem, inputtext[]) {
  1823. szMiscArray[0] = 0;
  1824. if(!ValidGroup(PlayerInfo[playerid][pMember])) return 1;
  1825. if(!GetPVarType(playerid, "Cgunbox")) return 1;
  1826. new group = PlayerInfo[playerid][pMember], box;
  1827. if(response) {
  1828. GetCrateBox(playerid, box, 2.0); // Did someone pick it up? or did the player move?
  1829. if(box == -1) return SendClientMessageEx(playerid, COLOR_GREY, "Crate box went out of reach - Please stay close to the crate box.");
  1830. if(box != GetPVarInt(playerid, "Cgunbox")) return SendClientMessageEx(playerid, COLOR_RED, "ERROR: Box ID differs from accessed crate, please try again.");
  1831. new GunID = arrGroupData[group][g_iLockerGuns][listitem];
  1832. if(!GunID) return SendClientMessageEx(playerid, COLOR_WHITE, "Theres no weapon assigned to that slot!");
  1833. if(CrateBox[box][cbMats] < arrGroupData[group][g_iLockerCost][listitem]) return SendClientMessageEx(playerid, COLOR_GRAD2, "There isn't enough materials in the crate for that weapon!");
  1834. if(PlayerInfo[playerid][pGuns][GetWeaponSlot(GunID)] != GunID) {
  1835. GivePlayerValidWeapon(playerid, GunID);
  1836. CrateBox[box][cbMats] -= arrGroupData[group][g_iLockerCost][listitem];
  1837. format(szMiscArray, sizeof(szMiscArray), "* %s reaches into the weapon crate box and takes out a %s.", GetPlayerNameEx(playerid), Weapon_ReturnName(GunID));
  1838. ProxDetector(25.0, playerid, szMiscArray, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
  1839. SaveCrate(box);
  1840. CrateBoxUpdate(box);
  1841. if(CrateBox[box][cbMats] < 1) DestroyCrate(box);
  1842. } else {
  1843. SendClientMessageEx(playerid, COLOR_RED, "You already have a %s on you!", Weapon_ReturnName(GunID));
  1844. }
  1845. }
  1846. DeletePVar(playerid, "Cgunbox");
  1847. return 1;
  1848. }
  1849. // Ignore gate status incase someone is opening a gate at the time of the gate timer.
  1850. stock TriggerGates(fac, status = 1) {
  1851. for(new g = 0; g < MAX_GATES; g++) {
  1852. if(GateInfo[g][gFacility] == fac) {
  1853. if(status) {
  1854. MoveDynamicObject(GateInfo[g][gGATE], GateInfo[g][gPosXM], GateInfo[g][gPosYM], GateInfo[g][gPosZM], GateInfo[g][gSpeed], GateInfo[g][gRotXM], GateInfo[g][gRotYM], GateInfo[g][gRotZM]);
  1855. GateInfo[g][gStatus] = 1;
  1856. } else {
  1857. MoveDynamicObject(GateInfo[g][gGATE], GateInfo[g][gPosX], GateInfo[g][gPosY], GateInfo[g][gPosZ], GateInfo[g][gSpeed], GateInfo[g][gRotX], GateInfo[g][gRotY], GateInfo[g][gRotZ]);
  1858. GateInfo[g][gStatus] = 0;
  1859. }
  1860. }
  1861. }
  1862. return 1;
  1863. }