Guest User

Untitled

a guest
Feb 7th, 2016
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.69 KB | None | 0 0
  1. database = mysql_connect("хостинг", "пользователь", "пароль", "название базы данных")
  2.  
  3. addEvent('onPlayerLoginEx', true)
  4. addEventHandler("onPlayerLoginEx", getRootElement(), function(name, password)
  5.     local result = mysql_query(database, "SELECT * FROM players WHERE Name = '"..name.."' AND Password = '"..password.."';")
  6.     if(result and mysql_num_rows(result) > 0) then
  7.         triggerClientEvent(source, "destroyGui", source)
  8.         setPlayerName(source, name)
  9.         local row = mysql_fetch_assoc(result)
  10.         setElementData(source, "posX", (row['X']))
  11.         setElementData(source, "posY", (row['Y']))
  12.         setElementData(source, "posZ", (row['Z']))
  13.         spawnPlayer(source, getElementData(source, "posX"), getElementData(source, "posY"), getElementData(source, "posZ"))
  14.         fadeCamera(source, true)
  15.         setCameraTarget(source, source)
  16.         outputChatBox("Вы успешно авторизировались на сервере!", source, 0, 255, 0)
  17.     else
  18.         outputChatBox("Введенный вами пароль неверный, или аккаунт не существует.", source, 255, 0, 0)
  19.    end
  20. end)
  21.  
  22. addEvent("onPlayerRegisterEx", true)
  23. addEventHandler("onPlayerRegisterEx", getRootElement(), function(name, password)
  24.     local result = mysql_query(database, "SELECT Name FROM players WHERE Name = '"..tostring(name).."';")
  25.     if(result) then
  26.         if(mysql_num_rows(result) > 0) then
  27.             outputChatBox("Аккаунт с указанным вами логином уже зарегистрирован, используйте другой!", source)
  28.         else
  29.             result = mysql_query(database, "INSERT INTO players (Name, Password) VALUES ('"..tostring(name).."', '"..tostring(password).."');")
  30.             if(result) then
  31.                 triggerClientEvent(source, "destroyGui", source)
  32.                 setPlayerName(source, name)
  33.                 spawnPlayer(source, 1714.96875, -1913.5341796875, 13.566567420959)
  34.                 setCameraTarget(source, source)
  35.                 fadeCamera(source, true)
  36.                 outputChatBox("Вы успешно зарегистрировались на сервере!", source, 0, 255, 0)
  37.             else
  38.                 outputChatBox("При регистрации аккаунта возникла ошибка.", source, 255, 0, 0)
  39.             end
  40.         end
  41.     end
  42. end)
  43.  
  44. addEventHandler ("onPlayerQuit", getRootElement(), function(quitType)
  45.     local x, y, z = getElementPosition(source)
  46.     mysql_query(database, "UPDATE players SET X = '"..x.."', Y = '"..y.."', Z = '"..z.."' WHERE NAME = '"..getPlayerName(source).."';")
  47. end)
Add Comment
Please, Sign In to add comment