1
0

mSelection.inc 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. //
  2. // Model Selection using previews. For SA-MP 0.3x and above.
  3. // - D0erfler 2013
  4. // - Kye 2013
  5. //
  6. // Version 1.1 R2
  7. /*Functions to be used
  8. LoadModelSelectionMenu(f_name[])
  9. HideModelSelectionMenu(playerid)
  10. ShowModelSelectionMenu(playerid, ListID, header_text[], dialogBGcolor = 0x4A5A6BBB, previewBGcolor = 0x88888899 , tdSelectionColor = 0xFFFF00AA)
  11. ShowModelSelectionMenuEx(playerid, items_array[], item_amount, header_text[], extraid, Float:Xrot = 0.0, Float:Yrot = 0.0, Float:Zrot = 0.0, Float:mZoom = 1.0, dialogBGcolor = 0x4A5A6BBB, previewBGcolor = 0x88888899 , tdSelectionColor = 0xFFFF00AA)
  12. */
  13. // Callbacks
  14. forward OnPlayerModelSelection(playerid, response, listid, modelid);
  15. forward OnPlayerModelSelectionEx(playerid, response, extraid, modelid);
  16. new BuyingVeh[MAX_PLAYERS];
  17. new VehicleNames2[212][] = {
  18. "Landstalker", "Bravura", "Buffalo", "Linerunner", "Perennial", "Sentinel",
  19. "Dumper", "Firetruck" , "Trashmaster" , "Stretch", "Manana", "Infernus",
  20. "Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
  21. "Esperanto", "Taxi", "Washington", "Bobcat", "Mr Whoopee", "BF Injection",
  22. "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus",
  23. "Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach", "Cabbie",
  24. "Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
  25. "Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder",
  26. "Reefer", "Tropic", "Flatbed","Yankee", "Caddy", "Solair","Berkley's RC Van",
  27. "Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron","RC Raider","Glendale",
  28. "Oceanic", "Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy",
  29. "Hermes", "Sabre", "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX",
  30. "Burrito", "Camper", "Marquis", "Baggage", "Dozer","Maverick","News Chopper",
  31. "Rancher", "FBI Rancher", "Virgo", "Greenwood","Jetmax","Hotring","Sandking",
  32. "Blista Compact", "Police Maverick", "Boxville", "Benson","Mesa","RC Goblin",
  33. "Hotring Racer", "Hotring Racer", "Bloodring Banger", "Rancher", "Super GT",
  34. "Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropdust", "Stunt",
  35. "Tanker", "RoadTrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
  36. "FCR-900","NRG-500","HPV1000","Cement Truck","Tow Truck","Fortune","Cadrona",
  37. "FBI Truck", "Willard", "Forklift","Tractor","Combine","Feltzer","Remington",
  38. "Slamvan", "Blade", "Freight", "Streak","Vortex","Vincent","Bullet","Clover",
  39. "Sadler", "Firetruck", "Hustler", "Intruder", "Primo", "Cargobob", "Tampa",
  40. "Sunrise", "Merit", "Utility Truck", "Nevada", "Yosemite", "Windsor", "Monster",
  41. "Monster","Uranus","Jester","Sultan","Stratum","Elegy","Raindance","RCTiger",
  42. "Flash","Tahoma","Savanna", "Bandito", "Freight", "Trailer", "Kart", "Mower",
  43. "Dune", "Sweeper", "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley",
  44. "Stafford", "BF-400", "Newsvan","Tug","Trailer","Emperor","Wayfarer","Euros",
  45. "Hotdog", "Club", "Trailer", "Trailer","Andromada","Dodo","RC Cam", "Launch",
  46. "Police Car (LSPD)", "Police Car (SFPD)","Police Car (LVPD)","Police Ranger",
  47. "Picador", "S.W.A.T. Van", "Alpha", "Phoenix", "Glendale", "Sadler",
  48. "Luggage Trailer","Luggage Trailer","Stair Trailer", "Boxville", "Farm Plow",
  49. "Utility Trailer"
  50. };
  51. enum DEALERSHIP
  52. {
  53. cCarModel,
  54. cCarPrice
  55. }
  56. new DonateVehicles[][DEALERSHIP] = {
  57. {481, 12000},
  58. {509, 12000},
  59. {477, 425000},
  60. {468, 55000},
  61. {521, 100000},
  62. {541, 555999},
  63. {429, 560000}
  64. };
  65. new VehiclePrices[][DEALERSHIP] = {
  66. {462, 11999},
  67. {525, 19500},
  68. {543, 21000},
  69. {473, 26000},
  70. {463, 30500},
  71. {440, 31000},
  72. {532, 35500},
  73. {600, 35999},
  74. {491, 35999},
  75. {410, 35999},
  76. {516, 35999},
  77. {418, 36000},
  78. {586, 36000},
  79. {467, 36500},
  80. {547, 39500},
  81. {401, 41500},
  82. {549, 41999},
  83. {436, 41999},
  84. {420, 45500},
  85. {517, 45999},
  86. {589, 45999},
  87. {518, 45999},
  88. {527, 45999},
  89. {551, 45999},
  90. {439, 45999},
  91. {445, 46000},
  92. {478, 46000},
  93. {492, 48999},
  94. {422, 51000},
  95. {529, 51500},
  96. {405, 52500},
  97. {466, 52999},
  98. {546, 53999},
  99. {540, 55500},
  100. {474, 55999},
  101. {526, 55999},
  102. {500, 56000},
  103. {483, 56000},
  104. {545, 56000},
  105. {419, 56781},
  106. {561, 56999},
  107. {459, 61000},
  108. {421, 61500},
  109. {458, 61500},
  110. {550, 61999},
  111. {576, 62500},
  112. {412, 64500},
  113. {438, 65500},
  114. {533, 65999},
  115. {534, 65999},
  116. {585, 65999},
  117. {507, 65999},
  118. {554, 66000},
  119. {567, 66500},
  120. {536, 66500},
  121. {599, 66500},
  122. {575, 66999},
  123. {479, 71400},
  124. {489, 71750},
  125. {431, 76000},
  126. {523, 76000},
  127. {575, 76500},
  128. {542, 76500},
  129. {413, 80000},
  130. {496, 80299},
  131. {535, 80999},
  132. {508, 81800},
  133. {426, 86500},
  134. {404, 86500},
  135. {562, 92999},
  136. {580, 95999},
  137. {482, 96500},
  138. {566, 100500},
  139. {587, 101000},
  140. {423, 101500},
  141. {588, 101500},
  142. {559, 105999},
  143. {579, 106500},
  144. {400, 109999},
  145. {453, 121000},
  146. {402, 126000},
  147. {558, 126000},
  148. {480, 126500},
  149. {408, 126500},
  150. {602, 151000},
  151. {565, 155999},
  152. {555, 186000},
  153. {484, 232200},
  154. {430, 246000},
  155. {409, 251000},
  156. {560, 276000},
  157. {454, 300999},
  158. {603, 345000},
  159. {415, 456999},
  160. {446, 501000},
  161. {563, 1001000},
  162. {417, 1001000},
  163. {487, 2551000},
  164. {593, 3501000},
  165. {481, 12000},
  166. {509, 12000},
  167. {477, 425000},
  168. {468, 55000},
  169. {521, 100000},
  170. {541, 555999},
  171. {429, 560000}
  172. };
  173. // settings static lists
  174. #define mS_TOTAL_ITEMS 1000 // Max amount of items from all lists
  175. #define mS_TOTAL_LISTS 20 // Max amount of lists
  176. #define mS_TOTAL_ROT_ZOOM 100 // Max amount of items using extra information like zoom or rotations
  177. // settings dynamic per player lists
  178. #define mS_CUSTOM_MAX_ITEMS 20
  179. new gCustomList[MAX_PLAYERS][mS_CUSTOM_MAX_ITEMS];
  180. #define mS_INVALID_LISTID mS_TOTAL_LISTS
  181. #define mS_CUSTOM_LISTID (mS_TOTAL_LISTS+1)
  182. #define mS_NEXT_TEXT "Next"
  183. #define mS_PREV_TEXT "Prev"
  184. #define mS_CANCEL_TEXT "Cancel"
  185. #define mS_SELECTION_ITEMS 21
  186. #define mS_ITEMS_PER_LINE 7
  187. #define mS_DIALOG_BASE_X 75.0
  188. #define mS_DIALOG_BASE_Y 130.0
  189. #define mS_DIALOG_WIDTH 550.0
  190. #define mS_DIALOG_HEIGHT 180.0
  191. #define mS_SPRITE_DIM_X 60.0
  192. #define mS_SPRITE_DIM_Y 70.0
  193. new PlayerText:gCurrentPageTextDrawId[MAX_PLAYERS];
  194. new PlayerText:gHeaderTextDrawId[MAX_PLAYERS];
  195. new PlayerText:gBackgroundTextDrawId[MAX_PLAYERS];
  196. new PlayerText:gNextButtonTextDrawId[MAX_PLAYERS];
  197. new PlayerText:gPrevButtonTextDrawId[MAX_PLAYERS];
  198. new PlayerText:gCancelButtonTextDrawId[MAX_PLAYERS];
  199. new PlayerText:gVehicleName[MAX_PLAYERS][mS_SELECTION_ITEMS];
  200. new PlayerText:gSelectionItems[MAX_PLAYERS][mS_SELECTION_ITEMS];
  201. new gSelectionItemsTag[MAX_PLAYERS][mS_SELECTION_ITEMS];
  202. new gItemAt[MAX_PLAYERS];
  203. #define mS_LIST_START 0
  204. #define mS_LIST_END 1
  205. new gLists[mS_TOTAL_LISTS][2]; // list information start/end index
  206. #define mS_ITEM_MODEL 0
  207. #define mS_ITEM_ROT_ZOOM_ID 1
  208. new gItemList[mS_TOTAL_ITEMS][2];
  209. new Float:gRotZoom[mS_TOTAL_ROT_ZOOM][4]; // Array for saving rotation and zoom info
  210. new gItemAmount = 0; // Amount of items used
  211. new gListAmount = 0; // Amount of lists used
  212. new gRotZoomAmount = 0; // Amount of Rotation/Zoom informations used
  213. //------------------------------------------------
  214. stock mS_GetNumberOfPages(ListID)
  215. {
  216. new ItemAmount = mS_GetAmountOfListItems(ListID);
  217. if((ItemAmount >= mS_SELECTION_ITEMS) && (ItemAmount % mS_SELECTION_ITEMS) == 0)
  218. {
  219. return (ItemAmount / mS_SELECTION_ITEMS);
  220. }
  221. else return (ItemAmount / mS_SELECTION_ITEMS) + 1;
  222. }
  223. //------------------------------------------------
  224. stock mS_GetNumberOfPagesEx(playerid)
  225. {
  226. new ItemAmount = mS_GetAmountOfListItemsEx(playerid);
  227. if((ItemAmount >= mS_SELECTION_ITEMS) && (ItemAmount % mS_SELECTION_ITEMS) == 0)
  228. {
  229. return (ItemAmount / mS_SELECTION_ITEMS);
  230. }
  231. else return (ItemAmount / mS_SELECTION_ITEMS) + 1;
  232. }
  233. //------------------------------------------------
  234. stock mS_GetAmountOfListItems(ListID)
  235. {
  236. return (gLists[ListID][mS_LIST_END] - gLists[ListID][mS_LIST_START])+1;
  237. }
  238. //------------------------------------------------
  239. stock mS_GetAmountOfListItemsEx(playerid)
  240. {
  241. return GetPVarInt(playerid, "mS_custom_item_amount");
  242. }
  243. //------------------------------------------------
  244. stock mS_GetPlayerCurrentListID(playerid)
  245. {
  246. if(GetPVarInt(playerid, "mS_list_active") == 1) return GetPVarInt(playerid, "mS_list_id");
  247. else return mS_INVALID_LISTID;
  248. }
  249. //------------------------------------------------
  250. stock PlayerText:mS_CreateCurrentPageTextDraw(playerid, Float:Xpos, Float:Ypos)
  251. {
  252. new PlayerText:txtInit;
  253. txtInit = CreatePlayerTextDraw(playerid, Xpos, Ypos, "0/0");
  254. PlayerTextDrawUseBox(playerid, txtInit, 0);
  255. PlayerTextDrawLetterSize(playerid, txtInit, 0.4, 1.1);
  256. PlayerTextDrawFont(playerid, txtInit, 1);
  257. PlayerTextDrawSetShadow(playerid, txtInit, 0);
  258. PlayerTextDrawSetOutline(playerid, txtInit, 1);
  259. PlayerTextDrawColor(playerid, txtInit, 0xACCBF1FF);
  260. PlayerTextDrawShow(playerid, txtInit);
  261. return txtInit;
  262. }
  263. //------------------------------------------------
  264. // Creates a button textdraw and returns the textdraw ID.
  265. stock PlayerText:mS_CreatePlayerDialogButton(playerid, Float:Xpos, Float:Ypos, Float:Width, Float:Height, button_text[])
  266. {
  267. new PlayerText:txtInit;
  268. txtInit = CreatePlayerTextDraw(playerid, Xpos, Ypos, button_text);
  269. PlayerTextDrawUseBox(playerid, txtInit, 1);
  270. PlayerTextDrawBoxColor(playerid, txtInit, 0x000000FF);
  271. PlayerTextDrawBackgroundColor(playerid, txtInit, 0x000000FF);
  272. PlayerTextDrawLetterSize(playerid, txtInit, 0.4, 1.1);
  273. PlayerTextDrawFont(playerid, txtInit, 1);
  274. PlayerTextDrawSetShadow(playerid, txtInit, 0); // no shadow
  275. PlayerTextDrawSetOutline(playerid, txtInit, 0);
  276. PlayerTextDrawColor(playerid, txtInit, 0x4A5A6BFF);
  277. PlayerTextDrawSetSelectable(playerid, txtInit, 1);
  278. PlayerTextDrawAlignment(playerid, txtInit, 2);
  279. PlayerTextDrawTextSize(playerid, txtInit, Height, Width); // The width and height are reversed for centering.. something the game does <g>
  280. PlayerTextDrawShow(playerid, txtInit);
  281. return txtInit;
  282. }
  283. //------------------------------------------------
  284. forward IsADonateModel(model);
  285. public IsADonateModel(model)
  286. {
  287. for(new i = 0; i < sizeof(DonateVehicles); i++)
  288. if(DonateVehicles[i][cCarModel] == model)
  289. return true;
  290. return false;
  291. }
  292. stock PlayerText:CreateVehicleName(playerid, model, Float:Xpos, Float:Ypos, Float:Width, Float:Height, vehiclename[], vehicleprice)
  293. {
  294. new PlayerText:txtInit;
  295. new str[128];
  296. if(IsADonateModel(model))
  297. format(str, sizeof(str), "%s~n~$%d~n~~n~~n~~n~~n~~y~[SPECIAL]", vehiclename, vehicleprice);
  298. else
  299. format(str, sizeof(str), "%s~n~$%d", vehiclename, vehicleprice);
  300. txtInit = CreatePlayerTextDraw(playerid, Xpos, Ypos, str);
  301. PlayerTextDrawBackgroundColor(playerid, txtInit, 0x000000FF);
  302. PlayerTextDrawLetterSize(playerid, txtInit, 0.3, 1.0);
  303. PlayerTextDrawFont(playerid, txtInit, 1);
  304. PlayerTextDrawSetShadow(playerid, txtInit, 1); // no shadow
  305. PlayerTextDrawSetOutline(playerid, txtInit, 1);
  306. PlayerTextDrawColor(playerid, txtInit, 0xC0C0C0FF);
  307. PlayerTextDrawTextSize(playerid, txtInit, Height, Width); // The width and height are reversed for centering.. something the game does <g>
  308. PlayerTextDrawShow(playerid, txtInit);
  309. return txtInit;
  310. }
  311. //------------------------------------------------
  312. stock PlayerText:mS_CreatePlayerHeaderTextDraw(playerid, Float:Xpos, Float:Ypos, header_text[])
  313. {
  314. new PlayerText:txtInit;
  315. txtInit = CreatePlayerTextDraw(playerid, Xpos, Ypos, header_text);
  316. PlayerTextDrawUseBox(playerid, txtInit, 0);
  317. PlayerTextDrawLetterSize(playerid, txtInit, 1.25, 3.0);
  318. PlayerTextDrawFont(playerid, txtInit, 0);
  319. PlayerTextDrawSetShadow(playerid, txtInit, 0);
  320. PlayerTextDrawSetOutline(playerid, txtInit, 1);
  321. PlayerTextDrawColor(playerid, txtInit, 0xACCBF1FF);
  322. PlayerTextDrawShow(playerid, txtInit);
  323. return txtInit;
  324. }
  325. stock PlayerText:CreateHeaderBuyableText(playerid, Float:Xpos, Float:Ypos, header_text[])
  326. {
  327. new PlayerText:txtInit;
  328. txtInit = CreatePlayerTextDraw(playerid, Xpos, Ypos, header_text);
  329. PlayerTextDrawUseBox(playerid, txtInit, 0);
  330. PlayerTextDrawLetterSize(playerid, txtInit, 1.25, 3.0);
  331. PlayerTextDrawFont(playerid, txtInit, 3);
  332. PlayerTextDrawSetShadow(playerid, txtInit, 1);
  333. PlayerTextDrawSetOutline(playerid, txtInit, 1);
  334. PlayerTextDrawColor(playerid, txtInit, 0x00FF00FF);
  335. PlayerTextDrawShow(playerid, txtInit);
  336. return txtInit;
  337. }
  338. //------------------------------------------------
  339. stock PlayerText:mS_CreatePlayerBGTextDraw(playerid, Float:Xpos, Float:Ypos, Float:Width, Float:Height, bgcolor)
  340. {
  341. new PlayerText:txtBackground = CreatePlayerTextDraw(playerid, Xpos, Ypos," ~n~"); // enough space for everyone
  342. PlayerTextDrawUseBox(playerid, txtBackground, 1);
  343. PlayerTextDrawBoxColor(playerid, txtBackground, bgcolor);
  344. PlayerTextDrawLetterSize(playerid, txtBackground, 5.0, 5.0);
  345. PlayerTextDrawFont(playerid, txtBackground, 0);
  346. PlayerTextDrawSetShadow(playerid, txtBackground, 0);
  347. PlayerTextDrawSetOutline(playerid, txtBackground, 0);
  348. PlayerTextDrawColor(playerid, txtBackground,0x000000FF);
  349. PlayerTextDrawTextSize(playerid, txtBackground, Width, Height);
  350. PlayerTextDrawBackgroundColor(playerid, txtBackground, bgcolor);
  351. PlayerTextDrawShow(playerid, txtBackground);
  352. return txtBackground;
  353. }
  354. //------------------------------------------------
  355. // Creates a model preview sprite
  356. stock PlayerText:mS_CreateMPTextDraw(playerid, modelindex, Float:Xpos, Float:Ypos, Float:Xrot, Float:Yrot, Float:Zrot, Float:mZoom, Float:width, Float:height, bgcolor)
  357. {
  358. new PlayerText:txtPlayerSprite = CreatePlayerTextDraw(playerid, Xpos, Ypos, ""); // it has to be set with SetText later
  359. PlayerTextDrawFont(playerid, txtPlayerSprite, TEXT_DRAW_FONT_MODEL_PREVIEW);
  360. PlayerTextDrawColor(playerid, txtPlayerSprite, 0xFFFFFFFF);
  361. PlayerTextDrawBackgroundColor(playerid, txtPlayerSprite, bgcolor);
  362. PlayerTextDrawTextSize(playerid, txtPlayerSprite, width, height); // Text size is the Width:Height
  363. PlayerTextDrawSetPreviewModel(playerid, txtPlayerSprite, modelindex);
  364. PlayerTextDrawSetPreviewRot(playerid,txtPlayerSprite, Xrot, Yrot, Zrot, mZoom);
  365. PlayerTextDrawSetSelectable(playerid, txtPlayerSprite, 1);
  366. PlayerTextDrawShow(playerid,txtPlayerSprite);
  367. return txtPlayerSprite;
  368. }
  369. //------------------------------------------------
  370. stock mS_DestroyPlayerMPs(playerid)
  371. {
  372. new x=0;
  373. while(x != mS_SELECTION_ITEMS) {
  374. if(gSelectionItems[playerid][x] != PlayerText:INVALID_TEXT_DRAW) {
  375. PlayerTextDrawDestroy(playerid, gSelectionItems[playerid][x]);
  376. gSelectionItems[playerid][x] = PlayerText:INVALID_TEXT_DRAW;
  377. if(BuyingVeh[playerid] == 1)
  378. {
  379. if(gVehicleName[playerid][x] != PlayerText:INVALID_TEXT_DRAW)
  380. {
  381. PlayerTextDrawDestroy(playerid, gVehicleName[playerid][x]);
  382. gVehicleName[playerid][x] = PlayerText:INVALID_TEXT_DRAW;
  383. }
  384. }
  385. }
  386. x++;
  387. }
  388. }
  389. //------------------------------------------------
  390. stock mS_ShowPlayerMPs(playerid)
  391. {
  392. new bgcolor = GetPVarInt(playerid, "mS_previewBGcolor");
  393. new x=0;
  394. new Float:BaseX = mS_DIALOG_BASE_X;
  395. new Float:BaseY = mS_DIALOG_BASE_Y - (mS_SPRITE_DIM_Y * 0.33); // down a bit
  396. new linetracker = 0;
  397. new mS_listID = mS_GetPlayerCurrentListID(playerid);
  398. if(mS_listID == mS_CUSTOM_LISTID)
  399. {
  400. new itemat = (GetPVarInt(playerid, "mS_list_page") * mS_SELECTION_ITEMS);
  401. new Float:rotzoom[4];
  402. rotzoom[0] = GetPVarFloat(playerid, "mS_custom_Xrot");
  403. rotzoom[1] = GetPVarFloat(playerid, "mS_custom_Yrot");
  404. rotzoom[2] = GetPVarFloat(playerid, "mS_custom_Zrot");
  405. rotzoom[3] = GetPVarFloat(playerid, "mS_custom_Zoom");
  406. new itemamount = mS_GetAmountOfListItemsEx(playerid);
  407. // Destroy any previous ones created
  408. mS_DestroyPlayerMPs(playerid);
  409. while(x != mS_SELECTION_ITEMS && itemat < (itemamount)) {
  410. if(linetracker == 0) {
  411. BaseX = mS_DIALOG_BASE_X + 25.0; // in a bit from the box
  412. BaseY += mS_SPRITE_DIM_Y + 1.0; // move on the Y for the next line
  413. }
  414. gSelectionItems[playerid][x] = mS_CreateMPTextDraw(playerid, gCustomList[playerid][itemat], BaseX, BaseY, rotzoom[0], rotzoom[1], rotzoom[2], rotzoom[3], mS_SPRITE_DIM_X, mS_SPRITE_DIM_Y, bgcolor);
  415. gSelectionItemsTag[playerid][x] = gCustomList[playerid][itemat];
  416. BaseX += mS_SPRITE_DIM_X + 1.0; // move on the X for the next sprite
  417. linetracker++;
  418. if(linetracker == mS_ITEMS_PER_LINE) linetracker = 0;
  419. itemat++;
  420. x++;
  421. }
  422. }
  423. else
  424. {
  425. new itemat = (gLists[mS_listID][mS_LIST_START] + (GetPVarInt(playerid, "mS_list_page") * mS_SELECTION_ITEMS));
  426. // Destroy any previous ones created
  427. mS_DestroyPlayerMPs(playerid);
  428. while(x != mS_SELECTION_ITEMS && itemat < (gLists[mS_listID][mS_LIST_END]+1)) {
  429. if(linetracker == 0) {
  430. BaseX = mS_DIALOG_BASE_X + 25.0; // in a bit from the box
  431. BaseY += mS_SPRITE_DIM_Y + 1.0; // move on the Y for the next line
  432. }
  433. new rzID = gItemList[itemat][mS_ITEM_ROT_ZOOM_ID]; // avoid long line
  434. if(rzID > -1) gSelectionItems[playerid][x] = mS_CreateMPTextDraw(playerid, gItemList[itemat][mS_ITEM_MODEL], BaseX, BaseY, gRotZoom[rzID][0], gRotZoom[rzID][1], gRotZoom[rzID][2], gRotZoom[rzID][3], mS_SPRITE_DIM_X, mS_SPRITE_DIM_Y, bgcolor);
  435. else gSelectionItems[playerid][x] = mS_CreateMPTextDraw(playerid, gItemList[itemat][mS_ITEM_MODEL], BaseX, BaseY, 0.0, 0.0, 0.0, 1.0, mS_SPRITE_DIM_X, mS_SPRITE_DIM_Y, bgcolor);
  436. gSelectionItemsTag[playerid][x] = gItemList[itemat][mS_ITEM_MODEL];
  437. BaseX += mS_SPRITE_DIM_X + 1.0; // move on the X for the next sprite
  438. linetracker++;
  439. if(linetracker == mS_ITEMS_PER_LINE) linetracker = 0;
  440. itemat++;
  441. x++;
  442. }
  443. }
  444. }
  445. stock ShowPlayerBuyable(playerid)
  446. {
  447. new bgcolor = GetPVarInt(playerid, "mS_previewBGcolor");
  448. new x=0;
  449. new Float:BaseX = mS_DIALOG_BASE_X;
  450. new Float:BaseY = mS_DIALOG_BASE_Y - (mS_SPRITE_DIM_Y * 0.33); // down a bit
  451. new linetracker = 0;
  452. new mS_listID = mS_GetPlayerCurrentListID(playerid);
  453. if(mS_listID == mS_CUSTOM_LISTID)
  454. {
  455. new itemat = (GetPVarInt(playerid, "mS_list_page") * mS_SELECTION_ITEMS);
  456. new Float:rotzoom[4];
  457. rotzoom[0] = GetPVarFloat(playerid, "mS_custom_Xrot");
  458. rotzoom[1] = GetPVarFloat(playerid, "mS_custom_Yrot");
  459. rotzoom[2] = GetPVarFloat(playerid, "mS_custom_Zrot");
  460. rotzoom[3] = GetPVarFloat(playerid, "mS_custom_Zoom");
  461. new itemamount = mS_GetAmountOfListItemsEx(playerid);
  462. // Destroy any previous ones created
  463. mS_DestroyPlayerMPs(playerid);
  464. while(x != mS_SELECTION_ITEMS && itemat < (itemamount)) {
  465. if(linetracker == 0) {
  466. BaseX = mS_DIALOG_BASE_X + 25.0; // in a bit from the box
  467. BaseY += mS_SPRITE_DIM_Y + 1.0; // move on the Y for the next line
  468. }
  469. gSelectionItems[playerid][x] = mS_CreateMPTextDraw(playerid, gCustomList[playerid][itemat], BaseX, BaseY, rotzoom[0], rotzoom[1], rotzoom[2], rotzoom[3], mS_SPRITE_DIM_X, mS_SPRITE_DIM_Y, bgcolor);
  470. gSelectionItemsTag[playerid][x] = gCustomList[playerid][itemat];
  471. BaseX += mS_SPRITE_DIM_X + 1.0; // move on the X for the next sprite
  472. linetracker++;
  473. if(linetracker == mS_ITEMS_PER_LINE) linetracker = 0;
  474. itemat++;
  475. x++;
  476. }
  477. }
  478. else
  479. {
  480. new itemat = (gLists[mS_listID][mS_LIST_START] + (GetPVarInt(playerid, "mS_list_page") * mS_SELECTION_ITEMS));
  481. // Destroy any previous ones created
  482. mS_DestroyPlayerMPs(playerid);
  483. while(x != mS_SELECTION_ITEMS && itemat < (gLists[mS_listID][mS_LIST_END]+1)) {
  484. if(linetracker == 0) {
  485. BaseX = mS_DIALOG_BASE_X + 25.0; // in a bit from the box
  486. BaseY += mS_SPRITE_DIM_Y + 1.0; // move on the Y for the next line
  487. }
  488. new rzID = gItemList[itemat][mS_ITEM_ROT_ZOOM_ID]; // avoid long line
  489. if(rzID > -1) gSelectionItems[playerid][x] = mS_CreateMPTextDraw(playerid, gItemList[itemat][mS_ITEM_MODEL], BaseX, BaseY, gRotZoom[rzID][0], gRotZoom[rzID][1], gRotZoom[rzID][2], gRotZoom[rzID][3], mS_SPRITE_DIM_X, mS_SPRITE_DIM_Y, bgcolor);
  490. else gSelectionItems[playerid][x] = mS_CreateMPTextDraw(playerid, gItemList[itemat][mS_ITEM_MODEL], BaseX, BaseY, 0.0, 0.0, 0.0, 1.0, mS_SPRITE_DIM_X, mS_SPRITE_DIM_Y, bgcolor);
  491. gVehicleName[playerid][x] = CreateVehicleName(playerid, gItemList[itemat][mS_ITEM_MODEL], BaseX, BaseY, mS_SPRITE_DIM_X, mS_SPRITE_DIM_Y, VehicleNames2[gItemList[itemat][mS_ITEM_MODEL]-400], GetVehiclePrice2(gItemList[itemat][mS_ITEM_MODEL]));
  492. gSelectionItemsTag[playerid][x] = gItemList[itemat][mS_ITEM_MODEL];
  493. BaseX += mS_SPRITE_DIM_X + 1.0; // move on the X for the next sprite
  494. linetracker++;
  495. if(linetracker == mS_ITEMS_PER_LINE) linetracker = 0;
  496. itemat++;
  497. x++;
  498. }
  499. }
  500. }
  501. stock GetVehiclePrice2(model)
  502. {
  503. for(new i = 0; i < sizeof(VehiclePrices); i++)
  504. {
  505. if(model == VehiclePrices[i][cCarModel])
  506. return VehiclePrices[i][cCarPrice];
  507. }
  508. return 0;
  509. }
  510. //------------------------------------------------
  511. stock mS_UpdatePageTextDraw(playerid)
  512. {
  513. new PageText[64+1];
  514. new listID = mS_GetPlayerCurrentListID(playerid);
  515. if(listID == mS_CUSTOM_LISTID)
  516. {
  517. format(PageText, 64, "%d/%d", GetPVarInt(playerid,"mS_list_page") + 1, mS_GetNumberOfPagesEx(playerid));
  518. PlayerTextDrawSetString(playerid, gCurrentPageTextDrawId[playerid], PageText);
  519. }
  520. else
  521. {
  522. format(PageText, 64, "%d/%d", GetPVarInt(playerid,"mS_list_page") + 1, mS_GetNumberOfPages(listID));
  523. PlayerTextDrawSetString(playerid, gCurrentPageTextDrawId[playerid], PageText);
  524. }
  525. }
  526. //------------------------------------------------
  527. stock ShowModelSelectionMenu(playerid, ListID, header_text[], dialogBGcolor = 0x4A5A6BBB, previewBGcolor = 0x88888899 , tdSelectionColor = 0xFFFF00AA)
  528. {
  529. if(!(0 <= ListID < mS_TOTAL_LISTS && gLists[ListID][mS_LIST_START] != gLists[ListID][mS_LIST_END])) return 0;
  530. mS_DestroySelectionMenu(playerid);
  531. SetPVarInt(playerid, "mS_list_page", 0);
  532. SetPVarInt(playerid, "mS_list_id", ListID);
  533. SetPVarInt(playerid, "mS_list_active", 1);
  534. SetPVarInt(playerid, "mS_list_time", GetTickCount());
  535. gBackgroundTextDrawId[playerid] = mS_CreatePlayerBGTextDraw(playerid, mS_DIALOG_BASE_X, mS_DIALOG_BASE_Y + 20.0, mS_DIALOG_WIDTH, mS_DIALOG_HEIGHT, dialogBGcolor);
  536. gHeaderTextDrawId[playerid] = mS_CreatePlayerHeaderTextDraw(playerid, mS_DIALOG_BASE_X, mS_DIALOG_BASE_Y, header_text);
  537. gCurrentPageTextDrawId[playerid] = mS_CreateCurrentPageTextDraw(playerid, mS_DIALOG_WIDTH - 30.0, mS_DIALOG_BASE_Y + 15.0);
  538. gNextButtonTextDrawId[playerid] = mS_CreatePlayerDialogButton(playerid, mS_DIALOG_WIDTH - 30.0, mS_DIALOG_BASE_Y+mS_DIALOG_HEIGHT+100.0, 50.0, 16.0, mS_NEXT_TEXT);
  539. gPrevButtonTextDrawId[playerid] = mS_CreatePlayerDialogButton(playerid, mS_DIALOG_WIDTH - 90.0, mS_DIALOG_BASE_Y+mS_DIALOG_HEIGHT+100.0, 50.0, 16.0, mS_PREV_TEXT);
  540. gCancelButtonTextDrawId[playerid] = mS_CreatePlayerDialogButton(playerid, mS_DIALOG_WIDTH - 150.0, mS_DIALOG_BASE_Y+mS_DIALOG_HEIGHT+100.0, 50.0, 16.0, mS_CANCEL_TEXT);
  541. SetPVarInt(playerid, "mS_previewBGcolor", previewBGcolor);
  542. mS_ShowPlayerMPs(playerid);
  543. mS_UpdatePageTextDraw(playerid);
  544. SelectTextDraw(playerid, tdSelectionColor);
  545. return 1;
  546. }
  547. stock ShowModelSelectionMenu2(playerid, ListID, header_text[], dialogBGcolor = 0x4A5A6BBB, previewBGcolor = 0x88888899 , tdSelectionColor = 0xFFFF00AA)
  548. {
  549. if(!(0 <= ListID < mS_TOTAL_LISTS && gLists[ListID][mS_LIST_START] != gLists[ListID][mS_LIST_END])) return 0;
  550. mS_DestroySelectionMenu(playerid);
  551. SetPVarInt(playerid, "mS_list_page", 0);
  552. SetPVarInt(playerid, "mS_list_id", ListID);
  553. SetPVarInt(playerid, "mS_list_active", 1);
  554. SetPVarInt(playerid, "mS_list_time", GetTickCount());
  555. gBackgroundTextDrawId[playerid] = mS_CreatePlayerBGTextDraw(playerid, mS_DIALOG_BASE_X, mS_DIALOG_BASE_Y + 20.0, mS_DIALOG_WIDTH, mS_DIALOG_HEIGHT, dialogBGcolor);
  556. gHeaderTextDrawId[playerid] = CreateHeaderBuyableText(playerid, mS_DIALOG_BASE_X, mS_DIALOG_BASE_Y, header_text);
  557. gCurrentPageTextDrawId[playerid] = mS_CreateCurrentPageTextDraw(playerid, mS_DIALOG_WIDTH - 30.0, mS_DIALOG_BASE_Y + 15.0);
  558. gNextButtonTextDrawId[playerid] = mS_CreatePlayerDialogButton(playerid, mS_DIALOG_WIDTH - 30.0, mS_DIALOG_BASE_Y+mS_DIALOG_HEIGHT+100.0, 50.0, 16.0, mS_NEXT_TEXT);
  559. gPrevButtonTextDrawId[playerid] = mS_CreatePlayerDialogButton(playerid, mS_DIALOG_WIDTH - 90.0, mS_DIALOG_BASE_Y+mS_DIALOG_HEIGHT+100.0, 50.0, 16.0, mS_PREV_TEXT);
  560. gCancelButtonTextDrawId[playerid] = mS_CreatePlayerDialogButton(playerid, mS_DIALOG_WIDTH - 150.0, mS_DIALOG_BASE_Y+mS_DIALOG_HEIGHT+100.0, 50.0, 16.0, mS_CANCEL_TEXT);
  561. BuyingVeh[playerid] = 1;
  562. SetPVarInt(playerid, "mS_previewBGcolor", previewBGcolor);
  563. ShowPlayerBuyable(playerid);
  564. mS_UpdatePageTextDraw(playerid);
  565. SelectTextDraw(playerid, tdSelectionColor);
  566. return 1;
  567. }
  568. //------------------------------------------------------------
  569. stock ShowModelSelectionMenuEx(playerid, items_array[], item_amount, header_text[], extraid, Float:Xrot = 0.0, Float:Yrot = 0.0, Float:Zrot = 0.0, Float:mZoom = 1.0, dialogBGcolor = 0x4A5A6BBB, previewBGcolor = 0x88888899 , tdSelectionColor = 0xFFFF00AA)
  570. {
  571. mS_DestroySelectionMenu(playerid);
  572. if(item_amount > mS_CUSTOM_MAX_ITEMS)
  573. {
  574. item_amount = mS_CUSTOM_MAX_ITEMS;
  575. print("-mSelection- WARNING: Too many items given to \"ShowModelSelectionMenuEx\", increase \"mS_CUSTOM_MAX_ITEMS\" to fix this");
  576. }
  577. if(item_amount > 0)
  578. {
  579. for(new i=0;i<item_amount;i++)
  580. {
  581. gCustomList[playerid][i] = items_array[i];
  582. }
  583. SetPVarInt(playerid, "mS_list_page", 0);
  584. SetPVarInt(playerid, "mS_list_id", mS_CUSTOM_LISTID);
  585. SetPVarInt(playerid, "mS_list_active", 1);
  586. SetPVarInt(playerid, "mS_list_time", GetTickCount());
  587. SetPVarInt(playerid, "mS_custom_item_amount", item_amount);
  588. SetPVarFloat(playerid, "mS_custom_Xrot", Xrot);
  589. SetPVarFloat(playerid, "mS_custom_Yrot", Yrot);
  590. SetPVarFloat(playerid, "mS_custom_Zrot", Zrot);
  591. SetPVarFloat(playerid, "mS_custom_Zoom", mZoom);
  592. SetPVarInt(playerid, "mS_custom_extraid", extraid);
  593. gBackgroundTextDrawId[playerid] = mS_CreatePlayerBGTextDraw(playerid, mS_DIALOG_BASE_X, mS_DIALOG_BASE_Y + 20.0, mS_DIALOG_WIDTH, mS_DIALOG_HEIGHT, dialogBGcolor);
  594. gHeaderTextDrawId[playerid] = mS_CreatePlayerHeaderTextDraw(playerid, mS_DIALOG_BASE_X, mS_DIALOG_BASE_Y, header_text);
  595. gCurrentPageTextDrawId[playerid] = mS_CreateCurrentPageTextDraw(playerid, mS_DIALOG_WIDTH - 30.0, mS_DIALOG_BASE_Y + 15.0);
  596. gNextButtonTextDrawId[playerid] = mS_CreatePlayerDialogButton(playerid, mS_DIALOG_WIDTH - 30.0, mS_DIALOG_BASE_Y+mS_DIALOG_HEIGHT+100.0, 50.0, 16.0, mS_NEXT_TEXT);
  597. gPrevButtonTextDrawId[playerid] = mS_CreatePlayerDialogButton(playerid, mS_DIALOG_WIDTH - 90.0, mS_DIALOG_BASE_Y+mS_DIALOG_HEIGHT+100.0, 50.0, 16.0, mS_PREV_TEXT);
  598. gCancelButtonTextDrawId[playerid] = mS_CreatePlayerDialogButton(playerid, mS_DIALOG_WIDTH - 150.0, mS_DIALOG_BASE_Y+mS_DIALOG_HEIGHT+100.0, 50.0, 16.0, mS_CANCEL_TEXT);
  599. SetPVarInt(playerid, "mS_previewBGcolor", previewBGcolor);
  600. mS_ShowPlayerMPs(playerid);
  601. mS_UpdatePageTextDraw(playerid);
  602. SelectTextDraw(playerid, tdSelectionColor);
  603. return 1;
  604. }
  605. return 0;
  606. }
  607. //------------------------------------------------
  608. stock HideModelSelectionMenu(playerid)
  609. {
  610. mS_DestroySelectionMenu(playerid);
  611. SetPVarInt(playerid, "mS_ignore_next_esc", 1);
  612. CancelSelectTextDraw(playerid);
  613. return 1;
  614. }
  615. //------------------------------------------------
  616. stock mS_DestroySelectionMenu(playerid)
  617. {
  618. if(GetPVarInt(playerid, "mS_list_active") == 1)
  619. {
  620. if(mS_GetPlayerCurrentListID(playerid) == mS_CUSTOM_LISTID)
  621. {
  622. DeletePVar(playerid, "mS_custom_Xrot");
  623. DeletePVar(playerid, "mS_custom_Yrot");
  624. DeletePVar(playerid, "mS_custom_Zrot");
  625. DeletePVar(playerid, "mS_custom_Zoom");
  626. DeletePVar(playerid, "mS_custom_extraid");
  627. DeletePVar(playerid, "mS_custom_item_amount");
  628. }
  629. DeletePVar(playerid, "mS_list_time");
  630. SetPVarInt(playerid, "mS_list_active", 0);
  631. mS_DestroyPlayerMPs(playerid);
  632. PlayerTextDrawDestroy(playerid, gHeaderTextDrawId[playerid]);
  633. PlayerTextDrawDestroy(playerid, gBackgroundTextDrawId[playerid]);
  634. PlayerTextDrawDestroy(playerid, gCurrentPageTextDrawId[playerid]);
  635. PlayerTextDrawDestroy(playerid, gNextButtonTextDrawId[playerid]);
  636. PlayerTextDrawDestroy(playerid, gPrevButtonTextDrawId[playerid]);
  637. PlayerTextDrawDestroy(playerid, gCancelButtonTextDrawId[playerid]);
  638. gHeaderTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  639. gBackgroundTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  640. gCurrentPageTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  641. gNextButtonTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  642. gPrevButtonTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  643. gCancelButtonTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  644. }
  645. }
  646. //------------------------------------------------
  647. public OnPlayerConnect(playerid)
  648. {
  649. // Init all of the textdraw related globals
  650. gHeaderTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  651. gBackgroundTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  652. gCurrentPageTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  653. gNextButtonTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  654. gPrevButtonTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  655. gCancelButtonTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  656. for(new x=0; x < mS_SELECTION_ITEMS; x++) {
  657. gSelectionItems[playerid][x] = PlayerText:INVALID_TEXT_DRAW;
  658. }
  659. for(new x=0; x < mS_SELECTION_ITEMS; x++) {
  660. gVehicleName[playerid][x] = PlayerText:INVALID_TEXT_DRAW;
  661. }
  662. gItemAt[playerid] = 0;
  663. return CallLocalFunction("MP_OPC", "i", playerid);
  664. }
  665. #if defined _ALS_OnPlayerConnect
  666. #undef OnPlayerConnect
  667. #else
  668. #define _ALS_OnPlayerConnect
  669. #endif
  670. #define OnPlayerConnect MP_OPC
  671. forward MP_OPC(playerid);
  672. //-------------------------------------------
  673. // Even though only Player* textdraws are used in this script,
  674. // OnPlayerClickTextDraw is still required to handle ESC
  675. public OnPlayerClickTextDraw(playerid, Text:clickedid)
  676. {
  677. if(GetPVarInt(playerid, "mS_ignore_next_esc") == 1) {
  678. SetPVarInt(playerid, "mS_ignore_next_esc", 0);
  679. return CallLocalFunction("MP_OPCTD", "ii", playerid, _:clickedid);
  680. }
  681. if(GetPVarInt(playerid, "mS_list_active") == 0) return CallLocalFunction("MP_OPCTD", "ii", playerid, _:clickedid);
  682. // Handle: They cancelled (with ESC)
  683. if(clickedid == Text:INVALID_TEXT_DRAW) {
  684. new listid = mS_GetPlayerCurrentListID(playerid);
  685. if(listid == mS_CUSTOM_LISTID)
  686. {
  687. new extraid = GetPVarInt(playerid, "mS_custom_extraid");
  688. mS_DestroySelectionMenu(playerid);
  689. CallLocalFunction("OnPlayerModelSelectionEx", "dddd", playerid, 0, extraid, -1);
  690. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  691. }
  692. else
  693. {
  694. mS_DestroySelectionMenu(playerid);
  695. CallLocalFunction("OnPlayerModelSelection", "dddd", playerid, 0, listid, -1);
  696. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  697. }
  698. return 1;
  699. }
  700. return CallLocalFunction("MP_OPCTD", "ii", playerid, _:clickedid);
  701. }
  702. #if defined _ALS_OnPlayerClickTextDraw
  703. #undef OnPlayerClickTextDraw
  704. #else
  705. #define _ALS_OnPlayerClickTextDraw
  706. #endif
  707. #define OnPlayerClickTextDraw MP_OPCTD
  708. forward MP_OPCTD(playerid, Text:clickedid);
  709. //------------------------------------------------
  710. public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid)
  711. {
  712. if(GetPVarInt(playerid, "mS_list_active") == 0 || (GetTickCount()-GetPVarInt(playerid, "mS_list_time")) < 200 /* Disable instant selection */) return CallLocalFunction("MP_OPCPTD", "ii", playerid, _:playertextid);
  713. new curpage = GetPVarInt(playerid, "mS_list_page");
  714. // Handle: cancel button
  715. if(playertextid == gCancelButtonTextDrawId[playerid]) {
  716. new listID = mS_GetPlayerCurrentListID(playerid);
  717. if(listID == mS_CUSTOM_LISTID)
  718. {
  719. new extraid = GetPVarInt(playerid, "mS_custom_extraid");
  720. HideModelSelectionMenu(playerid);
  721. CallLocalFunction("OnPlayerModelSelectionEx", "dddd", playerid, 0, extraid, -1);
  722. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  723. }
  724. else
  725. {
  726. HideModelSelectionMenu(playerid);
  727. CallLocalFunction("OnPlayerModelSelection", "dddd", playerid, 0, listID, -1);
  728. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  729. }
  730. return 1;
  731. }
  732. // Handle: next button
  733. if(playertextid == gNextButtonTextDrawId[playerid]) {
  734. new listID = mS_GetPlayerCurrentListID(playerid);
  735. if(listID == mS_CUSTOM_LISTID)
  736. {
  737. if(curpage < (mS_GetNumberOfPagesEx(playerid) - 1)) {
  738. SetPVarInt(playerid, "mS_list_page", curpage + 1);
  739. if(BuyingVeh[playerid] == 1)
  740. {
  741. for(new x=0; x < mS_SELECTION_ITEMS; x++)
  742. {
  743. PlayerTextDrawDestroy(playerid, gVehicleName[playerid][x]);
  744. }
  745. ShowPlayerBuyable(playerid);
  746. }
  747. else
  748. {
  749. mS_ShowPlayerMPs(playerid);
  750. }
  751. mS_UpdatePageTextDraw(playerid);
  752. PlayerPlaySound(playerid, 1083, 0.0, 0.0, 0.0);
  753. } else {
  754. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  755. }
  756. }
  757. else
  758. {
  759. if(curpage < (mS_GetNumberOfPages(listID) - 1)) {
  760. SetPVarInt(playerid, "mS_list_page", curpage + 1);
  761. if(BuyingVeh[playerid] == 1)
  762. {
  763. for(new x=0; x < mS_SELECTION_ITEMS; x++)
  764. {
  765. PlayerTextDrawDestroy(playerid, gVehicleName[playerid][x]);
  766. }
  767. ShowPlayerBuyable(playerid);
  768. }
  769. else
  770. {
  771. mS_ShowPlayerMPs(playerid);
  772. }
  773. mS_UpdatePageTextDraw(playerid);
  774. PlayerPlaySound(playerid, 1083, 0.0, 0.0, 0.0);
  775. } else {
  776. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  777. }
  778. }
  779. return 1;
  780. }
  781. // Handle: previous button
  782. if(playertextid == gPrevButtonTextDrawId[playerid]) {
  783. if(curpage > 0) {
  784. SetPVarInt(playerid, "mS_list_page", curpage - 1);
  785. if(BuyingVeh[playerid] == 1)
  786. {
  787. for(new x=0; x < mS_SELECTION_ITEMS; x++)
  788. {
  789. PlayerTextDrawDestroy(playerid, gVehicleName[playerid][x]);
  790. }
  791. ShowPlayerBuyable(playerid);
  792. }
  793. else
  794. {
  795. mS_ShowPlayerMPs(playerid);
  796. }
  797. mS_UpdatePageTextDraw(playerid);
  798. PlayerPlaySound(playerid, 1084, 0.0, 0.0, 0.0);
  799. } else {
  800. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  801. }
  802. return 1;
  803. }
  804. // Search in the array of textdraws used for the items
  805. new x=0;
  806. while(x != mS_SELECTION_ITEMS) {
  807. if(playertextid == gSelectionItems[playerid][x]) {
  808. new listID = mS_GetPlayerCurrentListID(playerid);
  809. if(listID == mS_CUSTOM_LISTID)
  810. {
  811. PlayerPlaySound(playerid, 1083, 0.0, 0.0, 0.0);
  812. new item_id = gSelectionItemsTag[playerid][x];
  813. new extraid = GetPVarInt(playerid, "mS_custom_extraid");
  814. HideModelSelectionMenu(playerid);
  815. CallLocalFunction("OnPlayerModelSelectionEx", "dddd", playerid, 1, extraid, item_id);
  816. return 1;
  817. }
  818. else
  819. {
  820. PlayerPlaySound(playerid, 1083, 0.0, 0.0, 0.0);
  821. new item_id = gSelectionItemsTag[playerid][x];
  822. HideModelSelectionMenu(playerid);
  823. if(BuyingVeh[playerid] == 1)
  824. {
  825. BuyingVeh[playerid] = 0;
  826. }
  827. CallLocalFunction("OnPlayerModelSelection", "dddd", playerid, 1, listID, item_id);
  828. return 1;
  829. }
  830. }
  831. x++;
  832. }
  833. return CallLocalFunction("MP_OPCPTD", "ii", playerid, _:playertextid);
  834. }
  835. #if defined _ALS_OnPlayerClickPlayerTD
  836. #undef OnPlayerClickPlayerTextDraw
  837. #else
  838. #define _ALS_OnPlayerClickPlayerTD
  839. #endif
  840. #define OnPlayerClickPlayerTextDraw MP_OPCPTD
  841. forward MP_OPCPTD(playerid, PlayerText:playertextid);
  842. //------------------------------------------------------------------
  843. stock LoadModelSelectionMenu(f_name[])
  844. {
  845. new File:f, str[75];
  846. format(str, sizeof(str), "%s", f_name);
  847. f = fopen(str, io_read);
  848. if( !f ) {
  849. printf("-mSelection- WARNING: Failed to load list: \"%s\"", f_name);
  850. return mS_INVALID_LISTID;
  851. }
  852. if(gListAmount >= mS_TOTAL_LISTS)
  853. {
  854. printf("-mSelection- WARNING: Reached maximum amount of lists, increase \"mS_TOTAL_LISTS\"", f_name);
  855. return mS_INVALID_LISTID;
  856. }
  857. new tmp_ItemAmount = gItemAmount; // copy value if loading fails
  858. new line[128], idxx;
  859. while(fread(f,line,sizeof(line),false))
  860. {
  861. if(tmp_ItemAmount >= mS_TOTAL_ITEMS)
  862. {
  863. printf("-mSelection- WARNING: Reached maximum amount of items, increase \"mS_TOTAL_ITEMS\"", f_name);
  864. break;
  865. }
  866. idxx = 0;
  867. if(!line[0]) continue;
  868. new mID = strval( mS_strtok(line,idxx) );
  869. if(0 <= mID < 20000)
  870. {
  871. gItemList[tmp_ItemAmount][mS_ITEM_MODEL] = mID;
  872. new tmp_mS_strtok[20];
  873. new Float:mRotation[3], Float:mZoom = 1.0;
  874. new bool:useRotation = false;
  875. tmp_mS_strtok = mS_strtok(line,idxx);
  876. if(tmp_mS_strtok[0]) {
  877. useRotation = true;
  878. mRotation[0] = floatstr(tmp_mS_strtok);
  879. }
  880. tmp_mS_strtok = mS_strtok(line,idxx);
  881. if(tmp_mS_strtok[0]) {
  882. useRotation = true;
  883. mRotation[1] = floatstr(tmp_mS_strtok);
  884. }
  885. tmp_mS_strtok = mS_strtok(line,idxx);
  886. if(tmp_mS_strtok[0]) {
  887. useRotation = true;
  888. mRotation[2] = floatstr(tmp_mS_strtok);
  889. }
  890. tmp_mS_strtok = mS_strtok(line,idxx);
  891. if(tmp_mS_strtok[0]) {
  892. useRotation = true;
  893. mZoom = floatstr(tmp_mS_strtok);
  894. }
  895. if(useRotation)
  896. {
  897. new bool:foundRotZoom = false;
  898. for(new i=0; i < gRotZoomAmount; i++)
  899. {
  900. if(gRotZoom[i][0] == mRotation[0] && gRotZoom[i][1] == mRotation[1] && gRotZoom[i][2] == mRotation[2] && gRotZoom[i][3] == mZoom)
  901. {
  902. foundRotZoom = true;
  903. gItemList[tmp_ItemAmount][mS_ITEM_ROT_ZOOM_ID] = i;
  904. break;
  905. }
  906. }
  907. if(gRotZoomAmount < mS_TOTAL_ROT_ZOOM)
  908. {
  909. if(!foundRotZoom)
  910. {
  911. gRotZoom[gRotZoomAmount][0] = mRotation[0];
  912. gRotZoom[gRotZoomAmount][1] = mRotation[1];
  913. gRotZoom[gRotZoomAmount][2] = mRotation[2];
  914. gRotZoom[gRotZoomAmount][3] = mZoom;
  915. gItemList[tmp_ItemAmount][mS_ITEM_ROT_ZOOM_ID] = gRotZoomAmount;
  916. gRotZoomAmount++;
  917. }
  918. }
  919. else print("-mSelection- WARNING: Not able to save rotation/zoom information. Reached maximum rotation/zoom information count. Increase '#define mS_TOTAL_ROT_ZOOM' to fix the issue");
  920. }
  921. else gItemList[tmp_ItemAmount][mS_ITEM_ROT_ZOOM_ID] = -1;
  922. tmp_ItemAmount++;
  923. }
  924. }
  925. if(tmp_ItemAmount > gItemAmount) // any models loaded ?
  926. {
  927. gLists[gListAmount][mS_LIST_START] = gItemAmount;
  928. gItemAmount = tmp_ItemAmount; // copy back
  929. gLists[gListAmount][mS_LIST_END] = (gItemAmount-1);
  930. gListAmount++;
  931. return (gListAmount-1);
  932. }
  933. printf("-mSelection- WARNING: No Items found in file: %s", f_name);
  934. return mS_INVALID_LISTID;
  935. }
  936. stock mS_strtok(const string[], &index)
  937. {
  938. new length = strlen(string);
  939. while ((index < length) && (string[index] <= ' '))
  940. {
  941. index++;
  942. }
  943. new offset = index;
  944. new result[20];
  945. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  946. {
  947. result[index - offset] = string[index];
  948. index++;
  949. }
  950. result[index - offset] = EOS;
  951. return result;
  952. }