Advertisement
Guest User

Untitled

a guest
Feb 14th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.71 KB | None | 0 0
  1. //Credits to Y_Less, Dracoblue and Kush.
  2.  
  3. #include <a_samp>
  4. #include <YSI\y_ini>
  5. #include <zcmd>
  6. #include <sscanf>
  7.  
  8. #define DIALOG_REGISTER 1
  9. #define DIALOG_LOGIN 2
  10. #define DIALOG_SUCCESS_1 3
  11. #define DIALOG_SUCCESS_2 4
  12.  
  13. #define PATH "/Players/%s.ini"
  14.  
  15. #define COL_WHITE "{FFFFFF}"
  16. #define COL_RED "{F81414}"
  17. #define COL_GREEN "{00FF22}"
  18. #define COL_LIGHTBLUE "{00CED1}"
  19. #define COLOR_WHITE 0xFFFFFFAA
  20. #define COLOR_DBLUE 0x2641FEAA
  21. #define COLOR_GREEN 0x00FF00FF
  22. #define COLOR_GREY 0xAFAFAFAA
  23. #define COLOR_RED 0xFF4646FF
  24.  
  25. enum pInfo
  26. {
  27. pPass,
  28. pCash,
  29. pAdmin,
  30. pKills,
  31. pDeaths,
  32. pMute
  33. }
  34. new PlayerInfo[MAX_PLAYERS][pInfo];
  35.  
  36. forward LoadUser_data(playerid,name[],value[]);
  37. public LoadUser_data(playerid,name[],value[])
  38. {
  39. INI_Int("Password",PlayerInfo[playerid][pPass]);
  40. INI_Int("Cash",PlayerInfo[playerid][pCash]);
  41. INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
  42. INI_Int("Kills",PlayerInfo[playerid][pKills]);
  43. INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
  44. INI_Int("Mute",PlayerInfo[playerid][pMute]);
  45. return 1;
  46. }
  47.  
  48. stock UserPath(playerid)
  49. {
  50. new string[128],playername[MAX_PLAYER_NAME];
  51. GetPlayerName(playerid,playername,sizeof(playername));
  52. format(string,sizeof(string),PATH,playername);
  53. return string;
  54. }
  55.  
  56. /*Credits to Dracoblue*/
  57. stock udb_hash(buf[]) {
  58. new length=strlen(buf);
  59. new s1 = 1;
  60. new s2 = 0;
  61. new n;
  62. for (n=0; n<length; n++)
  63. {
  64. s1 = (s1 + buf[n]) % 65521;
  65. s2 = (s2 + s1) % 65521;
  66. }
  67. return (s2 << 16) + s1;
  68. }
  69.  
  70. public OnGameModeInit()
  71. {
  72. return 1;
  73. }
  74.  
  75. public OnGameModeExit()
  76. {
  77. return 1;
  78. }
  79.  
  80. public OnPlayerRequestClass(playerid, classid)
  81. {
  82. return 1;
  83. }
  84.  
  85. public OnPlayerConnect(playerid)
  86. {
  87. if(fexist(UserPath(playerid)))
  88. {
  89. INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  90. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
  91. }
  92. else
  93. {
  94. ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
  95. }
  96. return 1;
  97. }
  98.  
  99. public OnPlayerDisconnect(playerid, reason)
  100. {
  101. new INI:File = INI_Open(UserPath(playerid));
  102. INI_SetTag(File,"data");
  103. INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
  104. INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
  105. INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
  106. INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
  107. INI_WriteInt(File,"Mute",PlayerInfo[playerid][pMute]);
  108. INI_Close(File);
  109. return 1;
  110. }
  111.  
  112. public OnPlayerSpawn(playerid)
  113. {
  114. return 1;
  115. }
  116.  
  117. public OnPlayerDeath(playerid, killerid, reason)
  118. {
  119. PlayerInfo[killerid][pKills]++;
  120. PlayerInfo[playerid][pDeaths]++;
  121. return 1;
  122. }
  123.  
  124. public OnVehicleSpawn(vehicleid)
  125. {
  126. return 1;
  127. }
  128.  
  129. public OnVehicleDeath(vehicleid, killerid)
  130. {
  131. return 1;
  132. }
  133.  
  134. public OnPlayerText(playerid, text[])
  135. {
  136. return 1;
  137. }
  138.  
  139. public OnPlayerCommandText(playerid, cmdtext[])
  140. {
  141. return SendClientMessage(playerid,COLOR_RED,"[ERROR] This command is not in use!");
  142. }
  143.  
  144. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  145. {
  146. return 1;
  147. }
  148.  
  149. public OnPlayerExitVehicle(playerid, vehicleid)
  150. {
  151. return 1;
  152. }
  153.  
  154. public OnPlayerStateChange(playerid, newstate, oldstate)
  155. {
  156. return 1;
  157. }
  158.  
  159. public OnPlayerEnterCheckpoint(playerid)
  160. {
  161. return 1;
  162. }
  163.  
  164. public OnPlayerLeaveCheckpoint(playerid)
  165. {
  166. return 1;
  167. }
  168.  
  169. public OnPlayerEnterRaceCheckpoint(playerid)
  170. {
  171. return 1;
  172. }
  173.  
  174. public OnPlayerLeaveRaceCheckpoint(playerid)
  175. {
  176. return 1;
  177. }
  178.  
  179. public OnRconCommand(cmd[])
  180. {
  181. return 1;
  182. }
  183.  
  184. public OnPlayerRequestSpawn(playerid)
  185. {
  186. return 1;
  187. }
  188.  
  189. public OnObjectMoved(objectid)
  190. {
  191. return 1;
  192. }
  193.  
  194. public OnPlayerObjectMoved(playerid, objectid)
  195. {
  196. return 1;
  197. }
  198.  
  199. public OnPlayerPickUpPickup(playerid, pickupid)
  200. {
  201. return 1;
  202. }
  203.  
  204. public OnVehicleMod(playerid, vehicleid, componentid)
  205. {
  206. return 1;
  207. }
  208.  
  209. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  210. {
  211. return 1;
  212. }
  213.  
  214. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  215. {
  216. return 1;
  217. }
  218.  
  219. public OnPlayerSelectedMenuRow(playerid, row)
  220. {
  221. return 1;
  222. }
  223.  
  224. public OnPlayerExitedMenu(playerid)
  225. {
  226. return 1;
  227. }
  228.  
  229. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  230. {
  231. return 1;
  232. }
  233.  
  234. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  235. {
  236. return 1;
  237. }
  238.  
  239. public OnRconLoginAttempt(ip[], password[], success)
  240. {
  241. return 1;
  242. }
  243.  
  244. public OnPlayerUpdate(playerid)
  245. {
  246. return 1;
  247. }
  248.  
  249. public OnPlayerStreamIn(playerid, forplayerid)
  250. {
  251. return 1;
  252. }
  253.  
  254. public OnPlayerStreamOut(playerid, forplayerid)
  255. {
  256. return 1;
  257. }
  258.  
  259. public OnVehicleStreamIn(vehicleid, forplayerid)
  260. {
  261. return 1;
  262. }
  263.  
  264. public OnVehicleStreamOut(vehicleid, forplayerid)
  265. {
  266. return 1;
  267. }
  268.  
  269. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  270. {
  271. switch( dialogid )
  272. {
  273. case DIALOG_REGISTER:
  274. {
  275. if (!response) return Kick(playerid);
  276. if(response)
  277. {
  278. if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
  279. new INI:File = INI_Open(UserPath(playerid));
  280. INI_SetTag(File,"data");
  281. INI_WriteInt(File,"Password",udb_hash(inputtext));
  282. INI_WriteInt(File,"Cash",0);
  283. INI_WriteInt(File,"Admin",0);
  284. INI_WriteInt(File,"Kills",0);
  285. INI_WriteInt(File,"Deaths",0);
  286. INI_WriteInt(File,"Mute",0);
  287. INI_Close(File);
  288.  
  289. ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Great! Your Y_INI system works perfectly. Relog to save your stats!","Ok","");
  290. }
  291. }
  292.  
  293. case DIALOG_LOGIN:
  294. {
  295. if ( !response ) return Kick ( playerid );
  296. if( response )
  297. {
  298. if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
  299. {
  300. INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  301. GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
  302. ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
  303. }
  304. else
  305. {
  306. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
  307. }
  308. return 1;
  309. }
  310. }
  311. }
  312. return 1;
  313. }
  314.  
  315. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  316. {
  317. return 1;
  318. }
  319. //==============================================================================
  320. CMD:kick(playerid, params[])
  321. {
  322. new targetid, reason[64], string[128];
  323. if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR] You are not authorised to use this command");
  324. if(sscanf(params, "us[64]", targetid, reason)) return SendClientMessage(playerid, COLOR_RED, "[USAGE] /kick [Player ID] [Reason]");
  325. if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR] Player is not connected");
  326. format(string, sizeof(string), "You Have Been kicked by Admin %s Reason: %s", GetName(playerid), reason);
  327. SendClientMessage(targetid, COLOR_RED, string);
  328. Kick(targetid);
  329. return 1;
  330. }
  331. CMD:gethere(playerid, params[])
  332. {
  333. new targetid, Float:X, Float:Y, Float:Z;
  334. if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR] You are not authorised to use this command");
  335. if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "[USAGE] /gethere [Player ID]");
  336. if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR] Player is not connected");
  337. GetPlayerPos(playerid, X, Y, Z);
  338. SetPlayerPos(targetid, X, Y+2, Z);
  339. return 1;
  340. }
  341. CMD:goto(playerid, params[])
  342. {
  343. new targetid, Float:X, Float:Y, Float:Z;
  344. if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR] You are not authorised to use this command");
  345. if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "[USAGE] /goto [Player ID]");
  346. if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR] Player is not connected");
  347. GetPlayerPos(targetid, X, Y, Z);
  348. SetPlayerPos(playerid, X, Y+2, Z);
  349. return 1;
  350. }
  351. CMD:mute(playerid, params[])
  352. {
  353. new targetid, string[100];
  354. if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR] You are not authorised to use this command");
  355. if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "[USAGE] /mute [Player ID]");
  356. if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR] Player is not connected");
  357. PlayerInfo[targetid][pMute] = 1;
  358. format(string, sizeof(string), "[SERVER] You have been muted by admin %s", GetName(playerid));
  359. SendClientMessage(targetid, COLOR_RED, string);
  360. return 1;
  361. }
  362. CMD:unmute(playerid, params[])
  363. {
  364. new targetid, string[100];
  365. if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR] You are not authorised to use this command");
  366. if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "[USAGE] /unmute [Player ID]");
  367. if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR] Player is not connected");
  368. PlayerInfo[targetid][pMute] = 0;
  369. format(string, sizeof(string), "[SERVER] You have been unmuted by admin %s", GetName(playerid));
  370. SendClientMessage(targetid, COLOR_RED, string);
  371. return 1;
  372. }
  373. CMD:slap(playerid, params[])
  374. {
  375. new targetid, Float:Health, string[64];
  376. if(PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR] You are not authorised to use this command");
  377. if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_RED, "[USAGE] /slap [Player ID]");
  378. if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "[ERROR] Player is not connected");
  379. GetPlayerHealth(targetid, Health);
  380. SetPlayerHealth(targetid, Health-20);
  381. format(string, sizeof(string), "Admin %s(%d) has slapped you", GetName(playerid), playerid);
  382. SendClientMessage(targetid, COLOR_DBLUE, string);
  383. return 1;
  384. }
  385. CMD:admins(playerid, params[])
  386. {
  387. new string[128];
  388. SendClientMessage(playerid, -1, "");
  389. SendClientMessage(playerid, COLOR_GREEN, "-------------------------ONLINE ADMINS-------------------------");
  390. SendClientMessage(playerid, -1, "");
  391. for(new i=0;i<MAX_PLAYERS;i++)
  392. {
  393. if(IsPlayerConnected(i))
  394. {
  395. if(PlayerInfo[i][pAdmin] > 0)
  396. {
  397. new name[MAX_PLAYER_NAME];
  398. GetPlayerName(i, name, sizeof(name));
  399. format(string, sizeof(string), "Name : %s Level : %d", name, PlayerInfo[i][pAdmin]);
  400. SendClientMessage(playerid, COLOR_GREEN, string);
  401. }
  402. }
  403. }
  404. return 1;
  405. }
  406. //==============================================================================
  407. stock GetName(playerid)
  408. {
  409. new pName[MAX_PLAYER_NAME];
  410. GetPlayerName(playerid, pName, sizeof(pName));
  411. return pName;
  412. }
  413. //==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement