Guest User

Untitled

a guest
Aug 10th, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. /*Admin saving/loading script using DOF2*/
  2.  
  3. #include <a_samp>
  4. #include <DOF2>
  5. #include <zcmd>
  6. #include <sscanf2>
  7.  
  8. /*Defines for writing faster*/
  9. #define SCM SendClientMessage
  10.  
  11.  
  12. /*Colors defined*/
  13. #define COLOR_RED 0xFF0000FF
  14.  
  15.  
  16. main()
  17. {
  18. print("Admin System + Commands using DOF2, ZCMD, SSCANF2 - by OxigEN.(Ox1gEN)");
  19. print("Credits for the include owners are above");
  20.  
  21. }
  22.  
  23.  
  24. enum pStats
  25. {
  26. pAdmin
  27. }
  28.  
  29. new pInfo[MAX_PLAYERS][pStats];
  30.  
  31.  
  32. public OnGameModeInit()
  33. {
  34. print("Admin Saving/Loading script by OxigEN (Ox1gEN) using DOF2, sscanf2 && zcmd");
  35. print("Credits to Double-O-Seven for DOF2");
  36. print("Credits to ZeeX for zcmd");
  37. print("Credits to Y_Less for sscanf2");
  38. return 1;
  39. }
  40.  
  41. public OnPlayerRequestClass(playerid, classid)
  42. {
  43. SetSpawnInfo(playerid, 0, 2, -851.9666,1555.6249,24.2900,260.1801, 0, 0, 0, 0, 0, 0);
  44. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  45. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  46. return 1;
  47. }
  48.  
  49.  
  50. public OnPlayerConnect(playerid)
  51. {
  52. if(DOF2_FileExists(pFile(playerid)))
  53. {
  54. SpawnPlayer(playerid);
  55. LoadPstats(playerid);
  56. }
  57. else //It is suggested to create a login/register system in order to keep people's player safe and no one could hack it (unless they have the password ofcourse).
  58. {
  59. DOF2_CreateFile(pFile(playerid));
  60. DOF2_SetInt(pFile(playerid), "AdminLevel", 0);
  61. DOF2_SaveFile();
  62. SpawnPlayer(playerid);
  63. }
  64. return 1;
  65. }
  66.  
  67.  
  68. /*Setting someone an admin*/
  69.  
  70. CMD:setadmin(playerid, params[])
  71. {
  72. new id, string[128], levels;
  73.  
  74. if(!IsPlayerAdmin(playerid)) return SCM(playerid, -1, "You're not an admin! Therefore you may not use this command"); //Admin RCON only.
  75. else if(sscanf(params, "ud", id, levels)) return SCM(playerid, -1, "USAGE: /setadmin [ID] [AdminLevel]");
  76. else if(id == INVALID_PLAYER_ID) return SCM(playerid, -1, "The id you've entered is either incorrect or invalid");
  77. else if(levels > 5) return SCM(playerid, COLOR_RED, "There are only FIVE availiable admin levels!");
  78. if(levels <= 5)
  79. {
  80. format(string, sizeof(string), "Lead Admin %s(%d) has set your admin level %d. Congratulations!", GetName(playerid), playerid, levels);
  81. SCM(id, COLOR_RED, string);
  82. pInfo[id][pAdmin] = levels;
  83. DOF2_SetInt(pFile(id), "AdminLevel", levels);
  84.  
  85. format(string, sizeof(string), "You have set %s(%d) admin level of %d.", GetName2(id), id, levels);
  86. SCM(playerid, COLOR_RED, string);
  87. DOF2_SaveFile();
  88. }
  89. return 1;
  90. }
  91.  
  92. /*Removing someone's admin permissions*/
  93.  
  94. CMD:removeadmin(playerid, params[])
  95. {
  96. new id, string[128], reason[128];
  97. if(DOF2_GetInt(pFile(playerid), "AdminLevel") < 5) return SCM(playerid, -1, "You're not an admin! Therefore you may not use this command");
  98. else if(sscanf(params, "us[50]", id, reason)) return SCM(playerid, -1, "USAGE: /removeadmin [ID] [REASON]");
  99. else if(id == INVALID_PLAYER_ID) return SCM(playerid, -1, "The ID you've entered is either incorrect or invalid!");
  100. else if(pInfo[id][pAdmin] == 0) return SCM(playerid, COLOR_RED, "That player isn't an admin!");
  101. else
  102. {
  103. format(string, sizeof(string), "Lead Admin %s(%d) has removed your admin level - Reason: %s", GetName(playerid), playerid, reason);
  104. SCM(id, COLOR_RED, string);
  105.  
  106. format(string, sizeof(string), "You have removed %s(%d)'s administrator position! Reason: %s", GetName2(id), id, reason);
  107. SCM(playerid, COLOR_RED, string);
  108.  
  109. pInfo[id][pAdmin] = 0;
  110. DOF2_SetInt(pFile(id), "AdminLevel", 0);
  111. DOF2_SaveFile();
  112. }
  113. return 1;
  114. }
  115.  
  116.  
  117.  
  118. /*Simple adming commands*/
  119.  
  120. CMD:kick(playerid, params[])
  121. {
  122. new id, reason[126], string[128];
  123. if(!DOF2_GetInt(pFile(playerid), "AdminLevel")) return SCM(playerid, -1, "You're not an admin! Therefore you may not use this command");
  124. else if(sscanf(params, "us[50]", id, reason)) return SCM(playerid, -1, "USAGE: /kick [ID] [REASON]");
  125. else if(id == INVALID_PLAYER_ID) return SCM(playerid, -1, "The id you've entered is either incorrect or invalid");
  126. else
  127. {
  128. format(string, sizeof(string), "[KICK]: %s(%d) has been kicked by %s(%d) - Reason: %s", GetName2(id), id, GetName(playerid), playerid, reason);
  129. SendClientMessageToAll(COLOR_RED, string);
  130. Kick(id);
  131. }
  132. return 1;
  133. }
  134.  
  135. CMD:ban(playerid, params[])
  136. {
  137. new id, reason[126], string[128];
  138. if(!DOF2_GetInt(pFile(playerid), "AdminLevel")) return SCM(playerid, -1, "You're not an admin! Therefore you may not use this command");
  139. else if(sscanf(params, "us[50]", id, reason)) return SCM(playerid, -1, "USAGE: /ban [ID] [REASON]");
  140. else if(id == INVALID_PLAYER_ID) return SCM(playerid, -1, "The id you've entered is either incorrect or invalid");
  141. else
  142. {
  143. format(string, sizeof(string), "[BAN]: %s(%d) has been banned by %s(%d) - Reason: %s", GetName2(id), id, GetName(playerid), id, reason);
  144. SendClientMessageToAll(COLOR_RED, string);
  145. Ban(id);
  146. }
  147. return 1;
  148. }
  149.  
  150.  
  151.  
  152. public OnPlayerDisconnect(playerid, reason)
  153. {
  154. DOF2_SetInt(pFile(playerid), "AdminLevel",pInfo[playerid][pAdmin]);
  155. DOF2_SaveFile();
  156. return 1;
  157. }
  158.  
  159. public OnGameModeExit()
  160. {
  161. DOF2_SaveFile(); /* Here you must DOF2_SaveFile(); in order to save the file */
  162. DOF2_Exit(); /* Here you must DOF2_Exit(); in order to close DOF2 */
  163. }
  164.  
  165. /*Useful stocks*/
  166.  
  167. stock pFile(playerid)
  168. {
  169. new pName[MAX_PLAYER_NAME +1];
  170. new File[50];
  171. GetPlayerName(playerid,pName,MAX_PLAYER_NAME);
  172. format(File,sizeof(File),"%s.ini",pName);
  173. return File;
  174. }
  175.  
  176. stock LoadPstats(playerid)
  177. {
  178. pInfo[playerid][pAdmin] = DOF2_GetInt(pFile(playerid), "AdminLevel");
  179. }
  180.  
  181. stock GetName(playerid)
  182. {
  183. new pName[MAX_PLAYER_NAME];
  184.  
  185. GetPlayerName(playerid, pName, sizeof(pName));
  186. return pName;
  187. }
  188.  
  189. stock GetName2(playerid)
  190. {
  191. new pName2[MAX_PLAYER_NAME];
  192.  
  193. GetPlayerName(playerid, pName2, sizeof(pName2));
  194. return pName2;
  195. }
Advertisement
Add Comment
Please, Sign In to add comment