Guest User

Skin Changer With Checkpoint [Same As 0.3x]

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