Advertisement
Guest User

Untitled

a guest
Aug 11th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.99 KB | None | 0 0
  1. // This is a comment
  2. // uncomment the line below if you want to write a filterscript
  3. //#define FILTERSCRIPT
  4.  
  5. #include <a_samp>
  6. #include <YSI\y_ini>
  7. #include <zcmd>
  8. #include <sscanf>
  9.  
  10. #define dregister 2011 //Defining register dialog so it won't mixed up with other dialog
  11. #define dlogin 2012 //Defining login dialog so it won't mixed up with other dialog
  12. #define UserPath "Users/%s.ini" //Will define user account path. In this case, will store in Scriptfiles/Users. So create a file inside of your Scriptfiles folder called Users
  13.  
  14. #define COLOR_PINK 0xFF80FFC8
  15. #define COLOR_UNEMD 0x99CEFFFF
  16. #define COLOR_ORANGE 0xffcc00FF
  17. #define COLOR_GRAD1 0xB4B5B7FF
  18. #define COLOR_GREEN 0x33AA33AA
  19. #define COLOR_USAGE 0xEFEFF7AA
  20. #define COLOR_YELLOW 0xFFFF00C8
  21.  
  22.  
  23. native WP_Hash(buffer[],len,const str[]); // Whirlpool native, add it at the top of your script under includes
  24. enum pInfo
  25. {
  26. Pass[129],
  27. pAdmin,
  28. pMoney,
  29. pScores,
  30. pKills,
  31. pDeaths,
  32. }
  33. new PlayerInfo[MAX_PLAYERS][pInfo];
  34. new str[256],levels,ID,Nam[MAX_PLAYER_NAME], pname[MAX_PLAYER_NAME];
  35.  
  36. stock Path(playerid) //Will create a new stock so we can easily use it later to load/save user's data in user's path
  37. {
  38. new str[128],name[MAX_PLAYER_NAME];
  39. GetPlayerName(playerid,name,sizeof(name));
  40. format(str,sizeof(str),UserPath,name);
  41. return str;
  42. }
  43.  
  44. forward loadaccount_user(playerid, name[], value[]); //forwarding a new function to load user's data
  45. //Now we will use our own function that we have created above
  46. public loadaccount_user(playerid, name[], value[])
  47. {
  48. INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
  49. ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length or hashed user's password. Whirlpool will hash 128 characters + NULL*/
  50. INI_Int("AdminLevel",pInfo[playerid][pAdmin]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
  51. INI_Int("Money",pInfo[playerid][pMoney]); //As explained above
  52. INI_Int("Scores",pInfo[playerid][pScores]);//As explained above
  53. INI_Int("Kills",pInfo[playerid][pKills]);//As explained above
  54. INI_Int("Deaths",pInfo[playerid][pDeaths]);//As explained above
  55. return 1;
  56. }
  57. CMD:setadmin(playerid, params[])
  58. {
  59. if(!IsPlayerAdmin(playerid))return 0; //This command only works for rcon
  60. if(sscanf(params,"ui",ID,levels)) return SendClientMessage(playerid,0xFF9900AA, "USAGE: /setadmin [ID] [Level 1-4]");//it will show this if you dont use the format properly
  61. if(levels > 6) return SendClientMessage(playerid,0xFF0000FF,"LEVELS AVAILABLE 1-4!");//Available levels
  62. if(!IsPlayerConnected(ID))return SendClientMessage(playerid,0x99CEFFFF,"That user is not connected.");//Detect if the id/partofname is connected
  63. if(PlayerInfo[ID][pAdmin] == levels) return SendClientMessage(playerid,0xFF0000FF, "ERROR: That person is already this admin level!");//Detect if the guy is already the level you setted
  64. GetPlayerName(playerid,Nam, MAX_PLAYER_NAME);//define the playerid name
  65. GetPlayerName(ID,pname,MAX_PLAYER_NAME);//define the other person name
  66. if(levels == 0)
  67. {
  68. format(str, sizeof(str),"%s has your Admin level to %d on the server. *cry *cry",Nam,levels);
  69. SendClientMessage(ID,0xFF9900AA,str);
  70. format(str, sizeof(str),"You had set %s Admin level to %d!",pname,levels);
  71. SendClientMessage(playerid,0xFF9900AA,str);
  72. PlayerInfo[ID][pAdmin] = levels;//this sets the player level
  73. return 1;
  74. }
  75. format(str, sizeof(str),"%s has your Admin level to %d on the server.",Nam,levels);
  76. SendClientMessage(ID,0xFF9900AA,str);
  77. format(str, sizeof(str),"You had set %s Admin level to %d!",pname,levels);
  78. SendClientMessage(playerid,0xFF9900AA,str);
  79. PlayerInfo[ID][pAdmin] = levels;
  80. return 1;
  81. }
  82.  
  83.  
  84.  
  85. CMD:heal(playerid, params[])
  86. {
  87. new Player;
  88. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFFFF00C8, "ERROR: You are not a RCON Admin!");
  89. else if (sscanf(params, "u", Player)) return SendClientMessage(playerid, 0xFFFF00C8, "Usage: /heal [PlayerID]");
  90. else if (Player == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFFFF00C8, "Player not found");
  91. else
  92. {
  93. SetPlayerHealth(Player, 100.0);
  94. SendClientMessage(Player, 0x00FF00AA, "You have been healed");
  95. SendClientMessage(playerid, 0x00FF00AA, "Player healed");
  96. }
  97. return 1;
  98. }
  99.  
  100. COMMAND:veh(playerid, params[])
  101. {
  102. if(IsPlayerAdmin(playerid))
  103. {
  104. new
  105. toplayerid, // the player we want to give money to
  106. vehid;
  107. // extracting player's ID and amount from params
  108. if (!sscanf(params, "ii", toplayerid, vehid))
  109. {
  110. if (toplayerid != INVALID_PLAYER_ID)
  111. {
  112. new
  113. message[40];
  114. new Float:x, Float:y, Float:z;
  115. GetPlayerPos(playerid, x, y, z);
  116. CreateVehicle(vehid, x +3, y, z, 0, 0,0, -1);
  117. format(message, sizeof(message), "Admin has gave you a %d Vehicle!!", vehid);
  118. SendClientMessage(toplayerid, 0xFFFF00C8, message);
  119. }
  120. else SendClientMessage(playerid, 0xFFFF00C8, "That player is not connected");
  121. }
  122. else SendClientMessage(playerid, 0xFFFF00C8, "Usage: /veh <playerid> <vehicleid>");
  123. }
  124. else SendClientMessage(playerid, 0xFFFF00C8, "Only admins can use this command!");
  125. return 1;
  126. }
  127.  
  128.  
  129. CMD:pm(playerid, params[])
  130. {
  131. new str[256], str2[256], id, Name1[MAX_PLAYER_NAME], Name2[MAX_PLAYER_NAME];
  132. if(sscanf(params, "us", id, str2))
  133. {
  134. SendClientMessage(playerid, 0xFFFF00C8, "Usage: /pm <id> <message>");
  135. return 1;
  136. }
  137. if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFFFF00C8, "ERROR: Player not connected");
  138. if(playerid == id) return SendClientMessage(playerid, 0xFFFF00C8, "ERROR: You cannot pm yourself!");
  139. {
  140. GetPlayerName(playerid, Name1, sizeof(Name1));
  141. GetPlayerName(id, Name2, sizeof(Name2));
  142. format(str, sizeof(str), "PM To %s(ID %d): %s", Name2, id, str2);
  143. SendClientMessage(playerid, 0xFFFF00C8, str);
  144. format(str, sizeof(str), "PM From %s(ID %d): %s", Name1, playerid, str2);
  145. SendClientMessage(id, 0xFFFF00C8, str);
  146. }
  147. return 1;
  148. }
  149.  
  150.  
  151. main()
  152. {
  153. print("\n----------------------------------");
  154. print(" RolePlay");
  155. print("----------------------------------\n");
  156. }
  157.  
  158. public OnGameModeInit()
  159. {
  160. // Don't use these lines if it's a filterscript
  161. SetGameModeText("RolePlay");
  162. AddPlayerClass(281,1380.9154,-1088.9073,27.3844,272.3928,0,0,0,0,0,0); //
  163. return 1;
  164. }
  165.  
  166. public OnGameModeExit()
  167. {
  168. return 1;
  169. }
  170.  
  171. public OnPlayerRequestClass(playerid, classid)
  172. {
  173. SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  174. SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  175. SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  176. return 1;
  177. }
  178.  
  179. public OnPlayerConnect(playerid)
  180. {
  181. new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
  182. GetPlayerName(playerid,name,sizeof(name)); //Get player's name
  183. if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
  184. {// then
  185. INI_ParseFile(Path(playerid),"loadaccount_user", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
  186. ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
  187. }
  188. else //If the connected user is not registered,
  189. {//then we will 'force' him to register :)
  190. ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
  191. return 1;
  192. }
  193. return 1;
  194. }
  195.  
  196. public OnPlayerDisconnect(playerid, reason)
  197. {
  198. //Same as OnDialogResponse, we will save their stats inside of their user's account
  199. if(fexist(Path(playerid)))//Will check if the file is exit or not inside of User's folder that we have created.
  200. {
  201. new INI:file = INI_Open(Path(playerid)); //will open their their file
  202. INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
  203. INI_WriteInt(file,"AdminLevel",pInfo[playerid][pAdmin]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
  204. INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his score inside of his account
  205. INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//As explained above
  206. INI_WriteInt(file,"Kills",pInfo[playerid][pKills]);//As explained above
  207. INI_WriteInt(file,"Deaths",pInfo[playerid][pDeaths]);//As explained above
  208. INI_Close(file);//Now after we've done saving their data, we now need to close the file
  209. return 1;
  210. }
  211. return 1;
  212. }
  213.  
  214. public OnPlayerSpawn(playerid)
  215. {
  216. return 1;
  217. }
  218.  
  219. public OnPlayerDeath(playerid, killerid, reason)
  220. {
  221. pInfo[killerid][Kills]++;//Will give 1 score to killer and it will be saved inside of his/her account
  222. pInfo[playerid][Deaths]++;//Will give 1 deaths each time they die and it will be saved inside of his/her account
  223. return 1;
  224. }
  225.  
  226. public OnVehicleSpawn(vehicleid)
  227. {
  228. return 1;
  229. }
  230.  
  231. public OnVehicleDeath(vehicleid, killerid)
  232. {
  233. return 1;
  234. }
  235.  
  236. public OnPlayerText(playerid, text[])
  237. {
  238. return 1;
  239. }
  240.  
  241. public OnPlayerCommandText(playerid, cmdtext[])
  242. {
  243. if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  244. {
  245. // Do something here
  246. return 1;
  247. }
  248. return 0;
  249. }
  250.  
  251. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  252. {
  253. return 1;
  254. }
  255.  
  256. public OnPlayerExitVehicle(playerid, vehicleid)
  257. {
  258. return 1;
  259. }
  260.  
  261. public OnPlayerStateChange(playerid, newstate, oldstate)
  262. {
  263. return 1;
  264. }
  265.  
  266. public OnPlayerEnterCheckpoint(playerid)
  267. {
  268. return 1;
  269. }
  270.  
  271. public OnPlayerLeaveCheckpoint(playerid)
  272. {
  273. return 1;
  274. }
  275.  
  276. public OnPlayerEnterRaceCheckpoint(playerid)
  277. {
  278. return 1;
  279. }
  280.  
  281. public OnPlayerLeaveRaceCheckpoint(playerid)
  282. {
  283. return 1;
  284. }
  285.  
  286. public OnRconCommand(cmd[])
  287. {
  288. return 1;
  289. }
  290.  
  291. public OnPlayerRequestSpawn(playerid)
  292. {
  293. return 1;
  294. }
  295.  
  296. public OnObjectMoved(objectid)
  297. {
  298. return 1;
  299. }
  300.  
  301. public OnPlayerObjectMoved(playerid, objectid)
  302. {
  303. return 1;
  304. }
  305.  
  306. public OnPlayerPickUpPickup(playerid, pickupid)
  307. {
  308. return 1;
  309. }
  310.  
  311. public OnVehicleMod(playerid, vehicleid, componentid)
  312. {
  313. return 1;
  314. }
  315.  
  316. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  317. {
  318. return 1;
  319. }
  320.  
  321. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  322. {
  323. return 1;
  324. }
  325.  
  326. public OnPlayerSelectedMenuRow(playerid, row)
  327. {
  328. return 1;
  329. }
  330.  
  331. public OnPlayerExitedMenu(playerid)
  332. {
  333. return 1;
  334. }
  335.  
  336. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  337. {
  338. return 1;
  339. }
  340.  
  341. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  342. {
  343. return 1;
  344. }
  345.  
  346. public OnRconLoginAttempt(ip[], password[], success)
  347. {
  348. return 1;
  349. }
  350.  
  351. public OnPlayerUpdate(playerid)
  352. {
  353. return 1;
  354. }
  355.  
  356. public OnPlayerStreamIn(playerid, forplayerid)
  357. {
  358. return 1;
  359. }
  360.  
  361. public OnPlayerStreamOut(playerid, forplayerid)
  362. {
  363. return 1;
  364. }
  365.  
  366. public OnVehicleStreamIn(vehicleid, forplayerid)
  367. {
  368. return 1;
  369. }
  370.  
  371. public OnVehicleStreamOut(vehicleid, forplayerid)
  372. {
  373. return 1;
  374. }
  375.  
  376. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  377. {
  378. if(dialogid == dregister) //If dialog id is a register dialog
  379. {//then
  380. if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
  381. if(response) //if they clicked the first button "Register"
  382. {//then
  383. if(!strlen(inputtext)) //If they didn't enter any password
  384. {// then we will tell to them to enter the password to register
  385. ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
  386. return 1;
  387. }
  388. //If they has entered a password for his account...
  389. new hashpass[129]; //Now we will create a new variable to hash his/her password
  390. WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to has their password
  391. new INI:file = INI_Open(Path(playerid)); //will create a new variable to register their acount inside of Scriptfiles/Users folder
  392. INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
  393. INI_WriteString(file,"Password",hashpass);//This will write a hashed password in of user's account
  394. INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
  395. INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
  396. INI_WriteInt(file,"Scores",0);//As explained above
  397. INI_WriteInt(file,"Kills",0);//As explained above
  398. INI_WriteInt(file,"Deaths",0);//As explained above
  399. INI_Close(file);//Now after we've done saving their data, we now need to close the file
  400. SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
  401. return 1;
  402. }
  403. }
  404. if(dialogid == dlogin) //If dialog id is a login dialog
  405. {//then
  406. if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
  407. if(response) //if they clicked the first button "Register"
  408. {//then
  409. new hashpass[129]; //Will create a new variable to hash his/her password
  410. WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
  411. if(!strcmp(hashpass,pInfo[playerid][Pass])) //If they have entered a correct password
  412. {//then
  413. INI_ParseFile(Path(playerid),"loadaccount_user",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
  414. SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
  415. GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
  416. SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
  417. }
  418. else //If they've entered an incorrect password
  419. {//then
  420. ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
  421. return 1;
  422. }
  423. }
  424. }
  425. return 1;
  426. }
  427.  
  428. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  429. {
  430. return 1;
  431. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement