Jochemd

Untitled

Dec 29th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.38 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3.  
  4. #define DIALOG_REGISTER     1
  5. #define DIALOG_LOGIN        2
  6.  
  7. forward LoadPlayerAccount_DBData(playerid);
  8.  
  9. enum pInfo
  10. {
  11.     Password[128],
  12.     Score,
  13.     Money,
  14.     bool:IsLogged
  15. }
  16.  
  17. new QueryString[500]; // We need a string to format queries. I always put it at the top so I do not need to recreate it all the time
  18. new PlayerInfo[MAX_PLAYERS][pInfo];
  19.  
  20. main()
  21. {
  22.     print("Loaded the best deathmatch script ever");
  23. }
  24.  
  25. stock PlayerName(playerid)
  26. {
  27.     new name[MAX_PLAYER_NAME];
  28.     GetPlayerName(playerid,name,sizeof(name));
  29.     return name;
  30. }
  31.  
  32. public OnGameModeInit()
  33. {
  34.     mysql_connect("fr1.volt-host.com","7959_kol","7959_kol","hallo5",3306); // Connect to the MySQL Database. "Host - Database - User - Password - Port (always 3306)
  35.     SetGameModeText("Best DM ever");
  36.     AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  37.     return 1;
  38. }
  39.  
  40. public OnPlayerConnect(playerid)
  41. {
  42.     mysql_format(1,QueryString,"SELECT * FROM `PlayerInfo` WHERE `PlayerName` = '%s' LIMIT 1",PlayerName(playerid)); // Select TABLE PlayerInfo, FIELD PlayerName and only the ONE that matches to your name
  43.     mysql_function_query(1,QueryString,true,"LoadPlayerAccount_DBData","i",playerid); // The 1 is connection handle (dunno what it means). The "True" comes from cache. We want to use the cache functions, otherwise we could also use the easy R6 if we didnt =D
  44.     return 1;
  45. }
  46.  
  47. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  48. {
  49.     if(dialogid == DIALOG_LOGIN)
  50.     {
  51.         if(!strcmp(inputtext,PlayerInfo[playerid][Password],false))
  52.         {
  53.             SendClientMessage(playerid,-1,"Congratulations, you have successfully logged in! Welcome back!");
  54.             PlayerInfo[playerid][IsLogged] = true;
  55.         }
  56.         else
  57.         {
  58.             printf("%s does not match to %s",inputtext,PlayerInfo[playerid][Password]);
  59.             SendClientMessage(playerid,-1,"Lozur, you failed to login! Cya =D");
  60.             Kick(playerid);
  61.             return 1;
  62.         }
  63.     }
  64.     else if(dialogid == DIALOG_REGISTER)
  65.     {
  66.         mysql_format(1,QueryString,"INSERT INTO `PlayerInfo` (`PlayerName`, `Password`, `Money`, `Score`) VALUES ('%s', '%s', %d, %d)",PlayerName(playerid),inputtext,5000,0); // suppose 5000 is start cash
  67.         mysql_function_query(1,QueryString,false,"SomeNotExistingCallback","",""); // You dont have to call a callback when you UPDATE or INSERT
  68.         PlayerInfo[playerid][IsLogged] = true;
  69.         PlayerInfo[playerid][Money] = 5000;
  70.         format(PlayerInfo[playerid][Password],128,"%s",inputtext);
  71.         SendClientMessage(playerid,-1,"Congratulations, you have successfully registered a cool account at this shit server!");
  72.         return 1;
  73.     }
  74.     return 1;
  75. }
  76.  
  77. public LoadPlayerAccount_DBData(playerid)
  78. {
  79.     new rows, fields;
  80.     cache_get_data(rows,fields); // Get the amount of rows & fields matching to the query, i.o.w if rows is 1, there is one row having the field 'PlayerName' filled with your nick
  81.     if(rows)
  82.     {
  83.         new temp[10];
  84.         ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login","Welcome back, pass plz.","Login","Quit");
  85.         cache_get_field_content(0,"Password",PlayerInfo[playerid][Password]);
  86.         cache_get_field_content(0,"Money",temp);
  87.         PlayerInfo[playerid][Money] = strval(temp);
  88.         cache_get_field_content(0,"Score",temp);
  89.         PlayerInfo[playerid][Score] = strval(temp);
  90.         return 1;
  91.     }      
  92.     else return ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,"Register","Welcome, plz insert pass to make acc","Register","Quit");
  93. }
Advertisement
Add Comment
Please, Sign In to add comment