Advertisement
Private200

Skin changer with saving system by Private200

Aug 6th, 2013
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <y_ini>
  4.  
  5. /* Skin Dialog + SAVING INI
  6. by
  7. Private200 */
  8.  
  9. // Defining the path where the user accounts will go
  10.  
  11. #define PATH "/Skin/%s.ini"
  12.  
  13.  
  14. // Defining the user Information script-related
  15.  
  16. enum pInfo
  17. {
  18. pSkin
  19. }
  20.  
  21. //=======================[Colors]====================
  22.  
  23. #define COLOR_LIGHTBLUE 0x33CCFFAA
  24.  
  25. //=======================[Shortcuts]====================
  26.  
  27. #define SCM SendClientMessage
  28.  
  29. //=======================[Defines]====================
  30.  
  31. new CanChangeSkin[MAX_PLAYERS];
  32.  
  33. new PlayerInfo[MAX_PLAYERS][pInfo];
  34.  
  35. forward LoadUser_data(playerid,name[],value[]);
  36. public LoadUser_data(playerid,name[],value[])
  37. {
  38. INI_Int("UserSkin",PlayerInfo[playerid][pSkin]);
  39. return 1;
  40. }
  41.  
  42. stock UserPath(playerid)
  43. {
  44. new string[128],playername[MAX_PLAYER_NAME];
  45. GetPlayerName(playerid, playername, sizeof(playername));
  46. format(string, sizeof(string), PATH, playername);
  47. return string;
  48. }
  49.  
  50. /*Credits to Dracoblue*/
  51. stock udb_hash(buf[]) {
  52. new length=strlen(buf);
  53. new s1 = 1;
  54. new s2 = 0;
  55. new n;
  56. for (n=0; n<length; n++)
  57. {
  58. s1 = (s1 + buf[n]) % 65521;
  59. s2 = (s2 + s1) % 65521;
  60. }
  61. return (s2 << 16) + s1;
  62. }
  63.  
  64. public OnFilterScriptInit()
  65. {
  66. print("\n--------------------------------------");
  67. print(" Skin FS by Private200");
  68. print("--------------------------------------\n");
  69. return 1;
  70. }
  71.  
  72. COMMAND:changeskin(playerid, cmdtext[])
  73. {
  74. if(!IsPlayerAdmin(playerid)) return SCM(playerid, COLOR_LIGHTBLUE, "You must be an admin to use this command.");
  75. if(CanChangeSkin[playerid] == 0)
  76. {
  77. ShowPlayerDialog(playerid, 5000, DIALOG_STYLE_INPUT, "{33CCFF}Skins", "{FFFFFF}We allow you to change your skin by\n{FFFFFF}typing below the skin ID you want.\n{FF0000}(AVAILABLE ARE FROM 0-299):", "Request", "Close");
  78. }
  79. else
  80. {
  81. SendClientMessage(playerid, COLOR_LIGHTBLUE, "You've changed your skin already in these last 10 seconds. Please wait some more time.");
  82. return 0;
  83. }
  84. return 1;
  85. }
  86.  
  87. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  88. {
  89. if(dialogid == 5000)
  90. {
  91. if(response)
  92. {
  93. new skinid, message[64];
  94. skinid = strval(inputtext);
  95. if(skinid < 0 || skinid > 299)
  96. {
  97. SendClientMessage(playerid, 0xFFFFFFFF, "The skin ID entered is not from 0 to 299");
  98. }
  99. else
  100. {
  101. SetPlayerSkin(playerid, skinid);
  102. format(message, sizeof(message), "We've provided you with the skin ID %d.", skinid);
  103. PlayerInfo[playerid][pSkin] = skinid;
  104. ChangingSkin(playerid);
  105. SendClientMessage(playerid, 0xFFFFFFFF, message);
  106. }
  107. }
  108. return 1;
  109. }
  110. return 0;
  111. }
  112.  
  113. stock ChangingSkin(playerid)
  114. {
  115. SetTimer("SkinChangerTimer", 10000, false);
  116. CanChangeSkin[playerid] = 1;
  117. return 1;
  118. }
  119.  
  120. public OnPlayerConnect(playerid)
  121. {
  122. if(fexist(UserPath(playerid)))
  123. {
  124. INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  125. }
  126. else
  127. {
  128. new INI:File = INI_Open(UserPath(playerid));
  129. INI_SetTag(File,"data");
  130. INI_WriteInt(File,"UserSkin", 0);
  131. INI_Close(File);
  132. }
  133. return 1;
  134. }
  135.  
  136. public OnPlayerDisconnect(playerid, reason)
  137. {
  138. new INI:File = INI_Open(UserPath(playerid));
  139. INI_SetTag(File,"data");
  140. INI_WriteInt(File,"UserSkin",PlayerInfo[playerid][pSkin]);
  141. INI_Close(File);
  142. return 1;
  143. }
  144.  
  145. forward SkinChangerTimer(playerid);
  146. public SkinChangerTimer(playerid)
  147. {
  148. SendClientMessage(playerid, COLOR_LIGHTBLUE, "You're now available to change your skin again.");
  149. CanChangeSkin[playerid] = 0;
  150. return 1;
  151. }
  152.  
  153. public OnPlayerSpawn(playerid)
  154. {
  155. SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
  156. return 1;
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement