Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- connection = nil
- --[[
- Jak to wszystko ma wyglądać w tabeli:
- Serial|ID wozu|X|Y|Z|Rotacja Z
- ]]
- function onStart()
- connection = mysql_connect("localhost", "USER", "HASLO", "BAZA") -- laczenie
- if ( not connection ) then -- blad polaczenia
- outputDebugString("Błąd podczas łączenia z bazą danych")
- end
- local result = mysql_query(connection, "SELECT * FROM auta") -- pobieranie wozów
- if (not result) then -- blad
- outputDebugString("Bład przy pobieraniu pojazdów (" .. mysql_errno(connection) .. ") " .. mysql_error(connection))
- end
- -- bardzo skomplikowane pobieranie wozow :D
- for i=1,mysql_num_rows(result) do
- mysql_data_seek ( result, i ) -- ustawia offset w wyniku na konkretny wiersz
- local tabela = mysql_fetch_row(result)
- local pojazd = createVehicle(tabela[2],tabela[3],tabela[4],tabela[5], 0,0,tabela[6])
- setElementData(pojazd, "owner", tabela[1]) -- no i finisz
- end
- mysql_free_result(result) -- cleanup plz
- end
- addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart)
- function saveToDB(pojazd, gracz)
- if isElement(pojazd) and isElement(gracz) then
- local serial = getPlayerSerial(gracz)
- local x,y,z = getElementPosition(pojazd)
- local rotX,rotY,rotZ = getElementRotation(pojazd)
- local id = getElementModel (pojazd)
- local result = mysql_query(connection, "INSERT INTO auta VALUES (`"..serial.."`, `"..id.."` ,`"..x.."`,`"..y.."`,`"..z.."`,`"..rotZ.."`)") -- zapis wozu do bazy
- if (not result) then -- blad
- outputDebugString("Bład przy zapisie do bazy (" .. mysql_errno(connection) .. ") " .. mysql_error(connection))
- end
- mysql_free_result(result) -- cleanup plz
- end
- end
- function maszSerialNobie(veh, seat)
- if seat == 0 then
- if getElementData(veh, "owner") ~= getPlayerSerial(source) then
- cancelEvent()
- outputChatBox("Nie jesteś właścicielem pojazdu!", source, 255,0,0)
- end
- end
- end
- addEventHandler("onPlayerVehicleEnter", getRootElement(), maszSerialNobie)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement