Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.60 KB | None | 0 0
  1. /*------------- DoesPlayerExist ----------------*/
  2. Server:DoesPlayerExist(playerid)
  3. {
  4.     new query[128];
  5.     mysql_format(sqlConnection, query, sizeof(query), "SELECT id FROM users WHERE Name = '%e' LIMIT 1", GetName(playerid));
  6.     mysql_pquery(sqlConnection, query, "SQL_DoesPlayerExist", "i", playerid);
  7.     return true;
  8. }
  9.  
  10. Server:SQL_DoesPlayerExist(playerid)
  11. {
  12.     if(cache_get_row_count(sqlConnection) != 0) // Player Exists
  13.     {
  14.         ShowLoginDialog(playerid, "");
  15.         return true;
  16.     }
  17.     else // Player Doesn't Exist
  18.     {
  19.         ShowRegisterDialog(playerid, "");
  20.         return false;
  21.     }
  22. }
  23.  
  24. /*------------- ShowRegisterDialog ----------------*/
  25. Server:ShowRegisterDialog(playerid, error[])
  26. {
  27.     if(LoggedIn[playerid]) return true;
  28.  
  29.     if(!strmatch(error, "")) {
  30.         SendClientMessage(playerid, COLOR_WHITE, error);
  31.     }
  32.  
  33.     SendClientMessage(playerid, COLOR_PINK, "You are playing on a practice RP script that is most likely incomplete with loads of bugs.");
  34.     ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Matt's RP - Register", "Please enter a password to register an account.", "Register", "Quit");
  35.     return true;
  36. }
  37. /*------------- ShowLoginDialog ------------------*/
  38. Server:ShowLoginDialog(playerid, error[])
  39. {
  40.     if(LoggedIn[playerid]) return true;
  41.  
  42.     if(!strmatch(error, "")) {
  43.         SendClientMessage(playerid, COLOR_WHITE, error);
  44.     }
  45.  
  46.     ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "Matt's RP - Login", "Please enter a password to login to your account.", "Login", "Quit");
  47.     return true;
  48. }
  49.  
  50. /*------------- AccountRegistered ------------------*/
  51. Server:SQL_AccountRegistered(playerid)
  52. {
  53.     // Set unique player id
  54.     pInfo[playerid][pSQLID] = cache_insert_id();
  55.  
  56.     // Send message.
  57.     SendClientMessage(playerid, COLOR_WHITE, "You have successfully registered with the server. All statistics will be saved under this username!");
  58.  
  59.     // Clear the previous data values.
  60.     LoadDefaultValues(playerid);
  61.  
  62.     // Load the player info.
  63.     LoadPlayerInfo(playerid);
  64.  
  65.     return true;
  66. }
  67.  
  68. /*------------- AccountLogin ------------------*/
  69. Server:SQL_AccountLogin(playerid)
  70. {
  71.     if(cache_num_rows() == 0) {
  72.         ShowLoginDialog(playerid, "Incorrect password.");
  73.         return true;
  74.     }
  75.  
  76.     // Send message
  77.     SendClientMessage(playerid, COLOR_WHITE, "You have successfully logged into the server. All statistics will be saved under this username!");
  78.  
  79.     // Clear the previous data values.
  80.     LoadDefaultValues(playerid);
  81.  
  82.     pInfo[playerid][pSQLID] = cache_get_field_content_int(0, "id", sqlConnection);
  83.     // Load the players information.
  84.     LoadPlayerInfo(playerid);
  85.  
  86.     return true;
  87. }
  88.  
  89. /*------------- LoadPlayerInfo ------------------*/
  90. Server:LoadPlayerInfo(playerid)
  91. {
  92.     new query[128];
  93.     mysql_format(sqlConnection, query, sizeof(query), "SELECT * FROM users WHERE id = %d LIMIT 1", pInfo[playerid][pSQLID]);
  94.     mysql_pquery(sqlConnection, query, "LoadPlayerInfo_", "i", playerid);  
  95.     return true;
  96. }
  97.  
  98. Server:LoadPlayerInfo_(playerid)
  99. {
  100.     LoggedIn[playerid] = true;
  101.  
  102.     pInfo[playerid][pAdminLevel] = cache_get_field_content_int(0, "AdminLevel", sqlConnection);     // Get Admin Level
  103.     pInfo[playerid][pMoney] = cache_get_field_content_int(0, "Money", sqlConnection);               // Get Money
  104.  
  105.     pInfo[playerid][pLastPos][0] = cache_get_field_content_float(0, "LastX", sqlConnection);
  106.     pInfo[playerid][pLastPos][1] = cache_get_field_content_float(0, "LastY", sqlConnection);
  107.     pInfo[playerid][pLastPos][2] = cache_get_field_content_float(0, "LastZ", sqlConnection);
  108.     pInfo[playerid][pLastPos][3] = cache_get_field_content_float(0, "LastRot", sqlConnection);
  109.  
  110.     pInfo[playerid][pLastInt] = cache_get_field_content_int(0, "Interior", sqlConnection);
  111.     pInfo[playerid][pLastWorld] = cache_get_field_content_int(0, "World", sqlConnection);
  112.  
  113.     pInfo[playerid][pSkin] = cache_get_field_content_int(0, "Skin", sqlConnection);
  114.  
  115.     ResetPlayerMoney(playerid);
  116.     GivePlayerMoney(playerid, pInfo[playerid][pMoney]);
  117.     SetPlayerSpawn(playerid);
  118.     return true;
  119. }
  120.  
  121. Server:TIMER_OneSecondTimer()
  122. {
  123.     foreach(Player, i) {
  124.         if(LoggedIn[i]) {
  125.             LastSaveTime++;
  126.  
  127.             if(LastSaveTime < 5) {
  128.                 SavePlayerPos(i, false);
  129.             } else {
  130.                 SavePlayerPos(i, true);
  131.                 LastSaveTime = 0;
  132.             }
  133.         }
  134.     }
  135.     return true;
  136. }
  137.  
  138. Server:SavePlayerPos(playerid, bool:save)
  139. {
  140.     GetPlayerPos(playerid, pInfo[playerid][pLastPos][0], pInfo[playerid][pLastPos][1], pInfo[playerid][pLastPos][2]);
  141.     GetPlayerFacingAngle(playerid, pInfo[playerid][pLastPos][3]);
  142.  
  143.     pInfo[playerid][pLastInt] = GetPlayerInterior(playerid);
  144.     pInfo[playerid][pLastWorld] = GetPlayerVirtualWorld(playerid);
  145.  
  146.     if(save) {
  147.         new query[128];
  148.         mysql_format(sqlConnection, query, sizeof(query), "UPDATE users SET LastX = %f, LastY = %f, LastZ = %f, LastRot = %f, Interior = %i, World = %i WHERE id = %i LIMIT 1",
  149.         pInfo[playerid][pLastPos][0], pInfo[playerid][pLastPos][1], pInfo[playerid][pLastPos][2], pInfo[playerid][pLastPos][3], pInfo[playerid][pLastInt], pInfo[playerid][pLastWorld], pInfo[playerid][pSQLID]);
  150.         mysql_pquery(sqlConnection, query);
  151.     }
  152.     return true;
  153. }
  154. /*------------- SetPlayerSpawn ------------------*/
  155. Server:SetPlayerSpawn(playerid)
  156. {
  157.     SetSpawnInfo(playerid, 0, DEFAULT_SKIN, pInfo[playerid][pLastPos][0], pInfo[playerid][pLastPos][1], pInfo[playerid][pLastPos][2], pInfo[playerid][pLastPos][3], 0, 0, 0, 0, 0, 0);
  158.     SpawnPlayer(playerid);
  159.  
  160.     SetPlayerVirtualWorld(playerid, pInfo[playerid][pLastWorld]);
  161.     SetPlayerInterior(playerid, pInfo[playerid][pLastInt]);
  162.     return true;
  163. }
  164.  
  165.  
  166. /*------------- LoadDefaultValues ------------------*/
  167. Server:LoadDefaultValues(playerid)
  168. {
  169.     pInfo[playerid][pSQLID] = 0;
  170.     pInfo[playerid][pAdminLevel] = 0;
  171.     pInfo[playerid][pMoney] = 0;
  172. }
  173.  
  174. /*------------- Send Local Message ------------------*/
  175. Server:SendLocalMessage(playerid, color, msg[])
  176. {
  177.     if(!LoggedIn[playerid])return true;
  178.  
  179.     new Float:x, Float:y, Float:z;
  180.     GetPlayerPos(playerid, x, y, z);
  181.  
  182.     foreach(Player, i) {
  183.         if(LoggedIn[i]){
  184.             if(IsPlayerInRangeOfPoint(i, 15.0, x, y, z) && GetPlayerInterior(i) == GetPlayerInterior(playerid) && GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid)) {
  185.                 SendClientMessage(i, color, msg);
  186.                 return true;
  187.             }
  188.         }
  189.     }
  190.     return true;
  191. }
  192.  
  193. /*------------- Send Local Message Distance ------------------*/
  194. Server:SendLocalMessageDist(playerid, color, msg[], Float:distance)
  195. {
  196.     if(!LoggedIn[playerid])return true;
  197.     new Float:x, Float:y, Float:z;
  198.     GetPlayerPos(playerid, x, y, z);
  199.     foreach(Player, i) {
  200.         if(LoggedIn[i]){
  201.             if(IsPlayerInRangeOfPoint(i, distance, x, y, z) && GetPlayerInterior(i) == GetPlayerInterior(playerid) && GetPlayerVirtualWorld(i) == GetPlayerVirtualWorld(playerid)) {
  202.                 SendClientMessage(i, color, msg);
  203.                 return true;
  204.             }
  205.         }
  206.     }
  207.     return true;
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement