Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. connection = nil
  2.  
  3. --[[
  4. Jak to wszystko ma wyglądać w tabeli:
  5.  
  6. Serial|ID wozu|X|Y|Z|Rotacja Z
  7.  
  8. ]]
  9.  
  10. function onStart()
  11.     connection = mysql_connect("localhost", "USER", "HASLO", "BAZA") -- laczenie
  12.     if ( not connection ) then -- blad polaczenia
  13.         outputDebugString("Błąd podczas łączenia z bazą danych")
  14.     end
  15.    
  16.     local result = mysql_query(connection, "SELECT * FROM auta") -- pobieranie wozów
  17.    
  18.     if (not result) then -- blad
  19.     outputDebugString("Bład przy pobieraniu pojazdów (" .. mysql_errno(connection) .. ") " .. mysql_error(connection))
  20.     end
  21.    
  22.     -- bardzo skomplikowane pobieranie wozow :D
  23.     for i=1,mysql_num_rows(result) do
  24.         mysql_data_seek ( result, i ) -- ustawia offset w wyniku na konkretny wiersz
  25.         local tabela = mysql_fetch_row(result)
  26.         local pojazd = createVehicle(tabela[2],tabela[3],tabela[4],tabela[5], 0,0,tabela[6])
  27.         setElementData(pojazd, "owner", tabela[1]) -- no i finisz
  28.     end
  29.      mysql_free_result(result) -- cleanup plz
  30. end
  31.  
  32. addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart)
  33.  
  34. function onResourceStart
  35.  
  36.  
  37. function saveToDB(pojazd, gracz)
  38.    
  39.     if isElement(pojazd) and isElement(gracz) then
  40.         local serial = getPlayerSerial(gracz)
  41.         local x,y,z = getElementPosition(pojazd)
  42.         local rotX,rotY,rotZ = getElementRotation(pojazd)
  43.         local id = getElementModel (pojazd)
  44.         local result = mysql_query(connection, "INSERT INTO auta VALUES (`"..serial.."`, `"..id.."` ,`"..x.."`,`"..y.."`,`"..z.."`,`"..rotZ.."`)") -- zapis wozu do bazy
  45.        
  46.         if (not result) then -- blad
  47.             outputDebugString("Bład przy zapisie do bazy (" .. mysql_errno(connection) .. ") " .. mysql_error(connection))
  48.        
  49.         end
  50.         mysql_free_result(result) -- cleanup plz
  51.     end
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement