Guest User

Untitled

a guest
Jul 20th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.55 KB | None | 0 0
  1. //
  2. // Admin player skin changer using previews. For SA-MP 0.3x and above.
  3. // - Kye 2012
  4. //
  5.  
  6. #include <a_samp>
  7. #include "../include/gl_common.inc"
  8.  
  9. #define TOTAL_ITEMS 312
  10. #define SELECTION_ITEMS 21
  11. #define ITEMS_PER_LINE 7
  12.  
  13. #define HEADER_TEXT "Skins"
  14. #define NEXT_TEXT "Next"
  15. #define PREV_TEXT "Prev"
  16.  
  17. #define DIALOG_BASE_X 75.0
  18. #define DIALOG_BASE_Y 130.0
  19. #define DIALOG_WIDTH 550.0
  20. #define DIALOG_HEIGHT 180.0
  21. #define SPRITE_DIM_X 60.0
  22. #define SPRITE_DIM_Y 70.0
  23.  
  24. new gTotalItems = TOTAL_ITEMS;
  25. new PlayerText:gCurrentPageTextDrawId[MAX_PLAYERS];
  26. new PlayerText:gHeaderTextDrawId[MAX_PLAYERS];
  27. new PlayerText:gBackgroundTextDrawId[MAX_PLAYERS];
  28. new PlayerText:gNextButtonTextDrawId[MAX_PLAYERS];
  29. new PlayerText:gPrevButtonTextDrawId[MAX_PLAYERS];
  30. new PlayerText:gSelectionItems[MAX_PLAYERS][SELECTION_ITEMS];
  31. new gSelectionItemsTag[MAX_PLAYERS][SELECTION_ITEMS];
  32. new gItemAt[MAX_PLAYERS];
  33.  
  34. new gItemList[TOTAL_ITEMS] = {
  35. 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,
  36. 50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,
  37. 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,
  38. 132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,
  39. 167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,
  40. 202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,
  41. 237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,
  42. 272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,
  43. 300,301,302,303,304,305,306,307,308,309,310,311
  44. };
  45.  
  46. //------------------------------------------------
  47.  
  48. public OnFilterScriptInit()
  49. {
  50. print("\n--Admin Player Skin Changer Loaded\n");
  51. return 1;
  52. }
  53.  
  54. //------------------------------------------------
  55.  
  56. GetNumberOfPages()
  57. {
  58. if((gTotalItems >= SELECTION_ITEMS) && (gTotalItems % SELECTION_ITEMS) == 0)
  59. {
  60. return (gTotalItems / SELECTION_ITEMS);
  61. }
  62. else return (gTotalItems / SELECTION_ITEMS) + 1;
  63. }
  64.  
  65. //------------------------------------------------
  66.  
  67. PlayerText:CreateCurrentPageTextDraw(playerid, Float:Xpos, Float:Ypos)
  68. {
  69. new PlayerText:txtInit;
  70. txtInit = CreatePlayerTextDraw(playerid, Xpos, Ypos, "0/0");
  71. PlayerTextDrawUseBox(playerid, txtInit, 0);
  72. PlayerTextDrawLetterSize(playerid, txtInit, 0.4, 1.1);
  73. PlayerTextDrawFont(playerid, txtInit, 1);
  74. PlayerTextDrawSetShadow(playerid, txtInit, 0);
  75. PlayerTextDrawSetOutline(playerid, txtInit, 1);
  76. PlayerTextDrawColor(playerid, txtInit, 0xACCBF1FF);
  77. PlayerTextDrawShow(playerid, txtInit);
  78. return txtInit;
  79. }
  80.  
  81. //------------------------------------------------
  82. // Creates a button textdraw and returns the textdraw ID.
  83.  
  84. PlayerText:CreatePlayerDialogButton(playerid, Float:Xpos, Float:Ypos, Float:Width, Float:Height, button_text[])
  85. {
  86. new PlayerText:txtInit;
  87. txtInit = CreatePlayerTextDraw(playerid, Xpos, Ypos, button_text);
  88. PlayerTextDrawUseBox(playerid, txtInit, 1);
  89. PlayerTextDrawBoxColor(playerid, txtInit, 0x000000FF);
  90. PlayerTextDrawBackgroundColor(playerid, txtInit, 0x000000FF);
  91. PlayerTextDrawLetterSize(playerid, txtInit, 0.4, 1.1);
  92. PlayerTextDrawFont(playerid, txtInit, 1);
  93. PlayerTextDrawSetShadow(playerid, txtInit, 0); // no shadow
  94. PlayerTextDrawSetOutline(playerid, txtInit, 0);
  95. PlayerTextDrawColor(playerid, txtInit, 0x4A5A6BFF);
  96. PlayerTextDrawSetSelectable(playerid, txtInit, 1);
  97. PlayerTextDrawAlignment(playerid, txtInit, 2);
  98. PlayerTextDrawTextSize(playerid, txtInit, Height, Width); // The width and height are reversed for centering.. something the game does <g>
  99. PlayerTextDrawShow(playerid, txtInit);
  100. return txtInit;
  101. }
  102.  
  103. //------------------------------------------------
  104.  
  105. PlayerText:CreatePlayerHeaderTextDraw(playerid, Float:Xpos, Float:Ypos, header_text[])
  106. {
  107. new PlayerText:txtInit;
  108. txtInit = CreatePlayerTextDraw(playerid, Xpos, Ypos, header_text);
  109. PlayerTextDrawUseBox(playerid, txtInit, 0);
  110. PlayerTextDrawLetterSize(playerid, txtInit, 1.25, 3.0);
  111. PlayerTextDrawFont(playerid, txtInit, 0);
  112. PlayerTextDrawSetShadow(playerid, txtInit, 0);
  113. PlayerTextDrawSetOutline(playerid, txtInit, 1);
  114. PlayerTextDrawColor(playerid, txtInit, 0xACCBF1FF);
  115. PlayerTextDrawShow(playerid, txtInit);
  116. return txtInit;
  117. }
  118.  
  119. //------------------------------------------------
  120.  
  121. PlayerText:CreatePlayerBackgroundTextDraw(playerid, Float:Xpos, Float:Ypos, Float:Width, Float:Height)
  122. {
  123. new PlayerText:txtBackground = CreatePlayerTextDraw(playerid, Xpos, Ypos,
  124. " ~n~"); // enough space for everyone
  125. PlayerTextDrawUseBox(playerid, txtBackground, 1);
  126. PlayerTextDrawBoxColor(playerid, txtBackground, 0x4A5A6BBB);
  127. PlayerTextDrawLetterSize(playerid, txtBackground, 5.0, 5.0);
  128. PlayerTextDrawFont(playerid, txtBackground, 0);
  129. PlayerTextDrawSetShadow(playerid, txtBackground, 0);
  130. PlayerTextDrawSetOutline(playerid, txtBackground, 0);
  131. PlayerTextDrawColor(playerid, txtBackground,0x000000FF);
  132. PlayerTextDrawTextSize(playerid, txtBackground, Width, Height);
  133. PlayerTextDrawBackgroundColor(playerid, txtBackground, 0x4A5A6BBB);
  134. PlayerTextDrawShow(playerid, txtBackground);
  135. return txtBackground;
  136. }
  137.  
  138. //------------------------------------------------
  139. // Creates a model preview sprite
  140.  
  141. PlayerText:CreateModelPreviewTextDraw(playerid, modelindex, Float:Xpos, Float:Ypos, Float:width, Float:height)
  142. {
  143. new PlayerText:txtPlayerSprite = CreatePlayerTextDraw(playerid, Xpos, Ypos, ""); // it has to be set with SetText later
  144. PlayerTextDrawFont(playerid, txtPlayerSprite, TEXT_DRAW_FONT_MODEL_PREVIEW);
  145. PlayerTextDrawColor(playerid, txtPlayerSprite, 0xFFFFFFFF);
  146. PlayerTextDrawBackgroundColor(playerid, txtPlayerSprite, 0x88888899);
  147. PlayerTextDrawTextSize(playerid, txtPlayerSprite, width, height); // Text size is the Width:Height
  148. PlayerTextDrawSetPreviewModel(playerid, txtPlayerSprite, modelindex);
  149. PlayerTextDrawSetSelectable(playerid, txtPlayerSprite, 1);
  150. PlayerTextDrawShow(playerid,txtPlayerSprite);
  151. return txtPlayerSprite;
  152. }
  153.  
  154. //------------------------------------------------
  155.  
  156. DestroyPlayerModelPreviews(playerid)
  157. {
  158. new x=0;
  159. while(x != SELECTION_ITEMS) {
  160. if(gSelectionItems[playerid][x] != PlayerText:INVALID_TEXT_DRAW) {
  161. PlayerTextDrawDestroy(playerid, gSelectionItems[playerid][x]);
  162. gSelectionItems[playerid][x] = PlayerText:INVALID_TEXT_DRAW;
  163. }
  164. x++;
  165. }
  166. }
  167.  
  168. //------------------------------------------------
  169.  
  170. ShowPlayerModelPreviews(playerid)
  171. {
  172. new x=0;
  173. new Float:BaseX = DIALOG_BASE_X;
  174. new Float:BaseY = DIALOG_BASE_Y - (SPRITE_DIM_Y * 0.33); // down a bit
  175. new linetracker = 0;
  176.  
  177. new itemat = GetPVarInt(playerid, "skinc_page") * SELECTION_ITEMS;
  178.  
  179. // Destroy any previous ones created
  180. DestroyPlayerModelPreviews(playerid);
  181.  
  182. while(x != SELECTION_ITEMS && itemat < gTotalItems) {
  183. if(linetracker == 0) {
  184. BaseX = DIALOG_BASE_X + 25.0; // in a bit from the box
  185. BaseY += SPRITE_DIM_Y + 1.0; // move on the Y for the next line
  186. }
  187. gSelectionItems[playerid][x] = CreateModelPreviewTextDraw(playerid, gItemList[itemat], BaseX, BaseY, SPRITE_DIM_X, SPRITE_DIM_Y);
  188. gSelectionItemsTag[playerid][x] = gItemList[itemat];
  189. BaseX += SPRITE_DIM_X + 1.0; // move on the X for the next sprite
  190. linetracker++;
  191. if(linetracker == ITEMS_PER_LINE) linetracker = 0;
  192. itemat++;
  193. x++;
  194. }
  195. }
  196.  
  197. //------------------------------------------------
  198.  
  199. UpdatePageTextDraw(playerid)
  200. {
  201. new PageText[64+1];
  202. format(PageText, 64, "%d/%d", GetPVarInt(playerid,"skinc_page") + 1, GetNumberOfPages());
  203. PlayerTextDrawSetString(playerid, gCurrentPageTextDrawId[playerid], PageText);
  204. }
  205.  
  206. //------------------------------------------------
  207.  
  208. CreateSelectionMenu(playerid)
  209. {
  210. gBackgroundTextDrawId[playerid] = CreatePlayerBackgroundTextDraw(playerid, DIALOG_BASE_X, DIALOG_BASE_Y + 20.0, DIALOG_WIDTH, DIALOG_HEIGHT);
  211. gHeaderTextDrawId[playerid] = CreatePlayerHeaderTextDraw(playerid, DIALOG_BASE_X, DIALOG_BASE_Y, HEADER_TEXT);
  212. gCurrentPageTextDrawId[playerid] = CreateCurrentPageTextDraw(playerid, DIALOG_WIDTH - 30.0, DIALOG_BASE_Y + 15.0);
  213. gNextButtonTextDrawId[playerid] = CreatePlayerDialogButton(playerid, DIALOG_WIDTH - 30.0, DIALOG_BASE_Y+DIALOG_HEIGHT+100.0, 50.0, 16.0, NEXT_TEXT);
  214. gPrevButtonTextDrawId[playerid] = CreatePlayerDialogButton(playerid, DIALOG_WIDTH - 90.0, DIALOG_BASE_Y+DIALOG_HEIGHT+100.0, 50.0, 16.0, PREV_TEXT);
  215.  
  216. ShowPlayerModelPreviews(playerid);
  217. UpdatePageTextDraw(playerid);
  218. }
  219.  
  220. //------------------------------------------------
  221.  
  222. DestroySelectionMenu(playerid)
  223. {
  224. DestroyPlayerModelPreviews(playerid);
  225.  
  226. PlayerTextDrawDestroy(playerid, gHeaderTextDrawId[playerid]);
  227. PlayerTextDrawDestroy(playerid, gBackgroundTextDrawId[playerid]);
  228. PlayerTextDrawDestroy(playerid, gCurrentPageTextDrawId[playerid]);
  229. PlayerTextDrawDestroy(playerid, gNextButtonTextDrawId[playerid]);
  230. PlayerTextDrawDestroy(playerid, gPrevButtonTextDrawId[playerid]);
  231.  
  232. gHeaderTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  233. gBackgroundTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  234. gCurrentPageTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  235. gNextButtonTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  236. gPrevButtonTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  237. }
  238.  
  239. //------------------------------------------------
  240.  
  241. HandlePlayerItemSelection(playerid, selecteditem)
  242. {
  243. // In this case we change the player's skin
  244. if(gSelectionItemsTag[playerid][selecteditem] >= 0 && gSelectionItemsTag[playerid][selecteditem] < 319) {
  245. SetPlayerSkin(playerid, gSelectionItemsTag[playerid][selecteditem]);
  246. return;
  247. }
  248. }
  249.  
  250. //------------------------------------------------
  251.  
  252. public OnPlayerConnect(playerid)
  253. {
  254. // Init all of the textdraw related globals
  255. gHeaderTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  256. gBackgroundTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  257. gCurrentPageTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  258. gNextButtonTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  259. gPrevButtonTextDrawId[playerid] = PlayerText:INVALID_TEXT_DRAW;
  260.  
  261. for(new x=0; x < SELECTION_ITEMS; x++) {
  262. gSelectionItems[playerid][x] = PlayerText:INVALID_TEXT_DRAW;
  263. }
  264.  
  265. gItemAt[playerid] = 0;
  266.  
  267. return 1; // Allow other scripts to keep processing OnPlayerConnect
  268. }
  269.  
  270. //-------------------------------------------
  271. // Even though only Player* textdraws are used in this script,
  272. // OnPlayerClickTextDraw is still required to handle ESC
  273.  
  274. public OnPlayerClickTextDraw(playerid, Text:clickedid)
  275. {
  276. if(GetPVarInt(playerid, "skinc_active") == 0) return 0;
  277.  
  278. // Handle: They cancelled (with ESC)
  279. if(clickedid == Text:INVALID_TEXT_DRAW) {
  280. DestroySelectionMenu(playerid);
  281. SetPVarInt(playerid, "skinc_active", 0);
  282. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  283. return 1;
  284. }
  285.  
  286. return 0;
  287. }
  288.  
  289. //------------------------------------------------
  290.  
  291. public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid)
  292. {
  293. if(GetPVarInt(playerid, "skinc_active") == 0) return 0;
  294.  
  295. new curpage = GetPVarInt(playerid, "skinc_page");
  296.  
  297. // Handle: next button
  298. if(playertextid == gNextButtonTextDrawId[playerid]) {
  299. if(curpage < (GetNumberOfPages() - 1)) {
  300. SetPVarInt(playerid, "skinc_page", curpage + 1);
  301. ShowPlayerModelPreviews(playerid);
  302. UpdatePageTextDraw(playerid);
  303. PlayerPlaySound(playerid, 1083, 0.0, 0.0, 0.0);
  304. } else {
  305. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  306. }
  307. return 1;
  308. }
  309.  
  310. // Handle: previous button
  311. if(playertextid == gPrevButtonTextDrawId[playerid]) {
  312. if(curpage > 0) {
  313. SetPVarInt(playerid, "skinc_page", curpage - 1);
  314. ShowPlayerModelPreviews(playerid);
  315. UpdatePageTextDraw(playerid);
  316. PlayerPlaySound(playerid, 1084, 0.0, 0.0, 0.0);
  317. } else {
  318. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  319. }
  320. return 1;
  321. }
  322.  
  323. // Search in the array of textdraws used for the items
  324. new x=0;
  325. while(x != SELECTION_ITEMS) {
  326. if(playertextid == gSelectionItems[playerid][x]) {
  327. HandlePlayerItemSelection(playerid, x);
  328. PlayerPlaySound(playerid, 1083, 0.0, 0.0, 0.0);
  329. DestroySelectionMenu(playerid);
  330. CancelSelectTextDraw(playerid);
  331. SetPVarInt(playerid, "skinc_active", 0);
  332. return 1;
  333. }
  334. x++;
  335. }
  336.  
  337. return 0;
  338. }
  339.  
  340. //------------------------------------------------
  341.  
  342. public OnPlayerCommandText(playerid, cmdtext[])
  343. {
  344. new cmd[256+1];
  345. new idx;
  346.  
  347. if(!IsPlayerAdmin(playerid)) return 0;
  348.  
  349. cmd = strtok(cmdtext, idx);
  350.  
  351. if(strcmp("/skinchange", cmd, true) == 0)
  352. {
  353. // If there was a previously created selection menu, destroy it
  354. DestroySelectionMenu(playerid);
  355.  
  356. SetPVarInt(playerid, "skinc_active", 1);
  357. //SetPVarInt(playerid, "skinc_page", 0); // will reset the page back to the first
  358.  
  359. CreateSelectionMenu(playerid);
  360. SelectTextDraw(playerid, 0xACCBF1FF);
  361. return 1;
  362. }
  363.  
  364. return 0;
  365. }
  366. //------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment