Advertisement
Kartik_Sharma

Untitled

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