Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2015-07-22, 19:07


THEGizmo

Modeler/Uczeń Lua






Wiek: 27
Na forum: 4141 dni
Posty: 255
Nick w MP: THEGizmo

Piwa: 3072

Respekt: 200
Respekt: 200Respekt: 200

Witam mam o tuz taki problem bo chcia?em zrobi? zapis Interior i Dimension Pojazdu kt?ry si? znajduje w tym Interior i Dimension tylko nie wiem jak :look:
za pomoc stawiam :piwo:

handler dbConnect("sqlite""pojazdy.db") 

--pojazdy
dbExec(handler"CREATE TABLE IF NOT EXISTS pojazdy (id INTEGER PRIMARY KEY AUTOINCREMENT, wlasciciel TEXT, model INTEGER, x FLOAT, y FLOAT, z FLOAT, rot FLOAT, ca INTEGER, cb INTEGER, cc INTEGER, przebieg FLOAT, paliwo FLOAT)")
dbExec(handler"CREATE UNIQUE INDEX IF NOT EXISTS IDX_id on pojazdy(id)")

--tuning
dbExec(handler"CREATE TABLE IF NOT EXISTS tuning (id INTEGER, t0 INTEGER, t1 INTEGER, t2 INTEGER, t3 INTEGER, t4 INTEGER, t5 INTEGER, t6 INTEGER, t7 INTEGER, t8 INTEGER, t9 INTEGER, t10 INTEGER, t11 INTEGER, t12 INTEGER, t13 INTEGER, t14 INTEGER, t15 INTEGER, t16 INTEGER, paintjob INTEGER, hr INTEGER, hg INTEGER, hb INTEGER)")
dbExec(handler"CREATE UNIQUE INDEX IF NOT EXISTS IDX_id on tuning(id)")


function onStartLoadVehicles()
local query dbQuery(handler"SELECT * FROM pojazdy")
local resultnum_rowserrormsg dbPoll (query, -1)
    for i,v in pairs(result) do
    local veh createVehicle(v["model"], v["x"], v["y"], v["z"])
    setElementRotation(veh00v["rot"])
    setVehicleColor(vehv["ca"], v["cb"], v["cc"])
    ustawDanePojazdu(vehv["id"], v["wlasciciel"])
    
    --ustawiam paliwo i przebieg
    setElementData(veh"pojazd_paliwo"v["paliwo"] or 50)
    setElementData(veh"pojazd_przebieg"v["przebieg"] or 0)
    --<< na koncu -->>
    local query dbQuery(handler"SELECT * FROM tuning WHERE id='"..v["id"].."'")
    local resultnum_rowserrormsg dbPoll (query, -1)
    setVehiclePaintjob(vehresult[1].paintjob)
    setVehicleHeadLightColor(vehresult[1].hrresult[1].hgresult[1].hb)
        for i,v in pairs(result) do
            for iivv in pairs(v) do
                if (ii ~= "id" and ii ~= "paintjob" and ii ~= "hr" and ii ~= "hg" and ii ~= "hb"then
                local vv tonumber(vv)
                    if vv ~= 0 then
                    addVehicleUpgrade(vehvv)
                    end
                end
            end
        end
    end
end
addEventHandler("onResourceStart"getResourceRootElement(getThisResource()), onStartLoadVehicles)

function ustawDanePojazdu(vehidwlasciciel) --id INTwlasciciel STRING
setElementData(veh"car_id"id)
setElementData(veh"car_owner"wlasciciel)
end

function onVehicleStartEnter(playerseatjacked)
  if seat == 0 then
  local car_owner getElementData(source"car_owner")
    if car_owner then
    local account getPlayerAccount(player)
        if account then
        local name getAccountName(account)
            if car_owner == name then
            --mamy prawo wejscia do auta
            prawo_ true
            end
        end
    
        if prawo_ then
        --wchodzim
        prawo_ false
        else
        --sio
        outputChatBox("Nie masz kluczyk?w do tego pojazdu."player255255255true)
        cancelEvent()
        end
    end
  end
end
addEventHandler ("onVehicleStartEnter"resourceRootonVehicleStartEnter)

--<<ZAPIS POJAZDU-->>

function zapiszPojazdy()
    for i,v in pairs(getElementsByType("vehicle")) do
    local id getElementData(v"car_id")
        if id then
        local owner getElementData(v"car_owner")
        local xygetElementPosition(v)
        local __rot getElementRotation(v)
        local color1color2color3color4 getVehicleColor(vtrue)
        local paliwo getElementData(v"pojazd_paliwo")
        local przebieg getElementData(v"pojazd_przebieg")
        dbExec(handler"UPDATE pojazdy SET x='"..x.."', y='"..y.."', z='"..z.."', rot='"..rot.."', ca='"..color1.."', cb='"..color2.."', cc='"..color3.."', przebieg='"..przebieg.."', paliwo='"..paliwo.."' WHERE id='"..id.."'")
        
        local paintjob getVehiclePaintjob(v)
        local rggetVehicleHeadLightColor(v)
        sav = {}
            for i=016 do
            local upgrade getVehicleUpgradeOnSlot(vi)
            sav[i] = upgrade or 0
            end
        dbExec(handler"UPDATE tuning SET t0='"..sav[0].."', t1='"..sav[1].."', t2='"..sav[2].."', t3='"..sav[3].."', t4='"..sav[4].."', t5='"..sav[5].."', t6='"..sav[6].."', t7='"..sav[7].."', t8='"..sav[8].."', t9='"..sav[9].."', t10='"..sav[10].."', t11='"..sav[11].."', t12='"..sav[12].."', t13='"..sav[13].."', t14='"..sav[14].."', t15='"..sav[15].."', t16='"..sav[16].."', paintjob='"..paintjob.."', hr='"..r.."', hg='"..g.."', hb='"..b.."' WHERE id="..id.."")
        sav nil
        end
    end
end
setTimer(zapiszPojazdy9000000)

function zapiszKomenda(player)
local acc getAccountName (getPlayerAccount(player))
    if isObjectInACLGroup ("user."..accaclGetGroup ("Admin")) then
    zapiszPojazdy()
    outputChatBox("** Zapisano pojazdy."player255255255true)
    end
end
addCommandHandler("zapiszpojazdy"zapiszKomenda)

-- mapaf11
addEvent("pobierzPojazdyGracza"true)
addEventHandler("pobierzPojazdyGracza"getRootElement(),
function()
local account getPlayerAccount(source)
    if account then
    local name getAccountName(account)
    local vehs getVehiclesByOwner(name)
    triggerClientEvent(source"zwrocPojazdyGracza"rootvehs)
    end
end)

--
--zwraca pojazd o danym ID
function getVehicleByID(poszukiwane_id)
    for i,v in pairs(getElementsByType("vehicle")) do
    local id getElementData(v"car_id")
        if id then
        local id tonumber(id)
        local poszukiwane_id tonumber(poszukiwane_id)
            if id == poszukiwane_id then
            return v
            end
        end
    end
    return false
end

--zwraca pojazdy ktore posiada dany login
function getVehiclesByOwner(szukany)
tab = {}
    for i,v in pairs(getElementsByType("vehicle")) do
    local owner getElementData(v"car_owner")
        if owner then
            if owner == szukany then
            table.insert(tabv)
            end
        end
    end
    return tab
end

--zwraca liczbe pojazdow jaka ma dany login
function getYourVehicleCount(login)
local vehs getVehiclesByOwner(login)
return #vehs
end


Podpis
Modeler Corporation Sp. Z.O.O

Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-22, 19:55


Fanciak

BOT






Wiek: 25
Na forum: 4446 dni
Posty: 728
Nick w MP: Fanciak

Piwa: 1572

Respekt: 500
Respekt: 500

handler dbConnect("sqlite""pojazdy.db") 

--pojazdy
dbExec(handler"CREATE TABLE IF NOT EXISTS pojazdy (id INTEGER PRIMARY KEY AUTOINCREMENT, wlasciciel TEXT, model INTEGER, x FLOAT, y FLOAT, z FLOAT, rot FLOAT, ca INTEGER, cb INTEGER, cc INTEGER, przebieg FLOAT, paliwo FLOAT)")
dbExec(handler"CREATE UNIQUE INDEX IF NOT EXISTS IDX_id on pojazdy(id)")

--tuning
dbExec(handler"CREATE TABLE IF NOT EXISTS tuning (id INTEGER, t0 INTEGER, t1 INTEGER, t2 INTEGER, t3 INTEGER, t4 INTEGER, t5 INTEGER, t6 INTEGER, t7 INTEGER, t8 INTEGER, t9 INTEGER, t10 INTEGER, t11 INTEGER, t12 INTEGER, t13 INTEGER, t14 INTEGER, t15 INTEGER, t16 INTEGER, paintjob INTEGER, hr INTEGER, hg INTEGER, hb INTEGER)")
dbExec(handler"CREATE UNIQUE INDEX IF NOT EXISTS IDX_id on tuning(id)")


function onStartLoadVehicles()
local query dbQuery(handler"SELECT * FROM pojazdy")
local resultnum_rowserrormsg dbPoll (query, -1)
    for i,v in pairs(result) do
    local veh createVehicle(v["model"], v["x"], v["y"], v["z"])
    setElementRotation(veh00v["rot"])
    setVehicleColor(vehv["ca"], v["cb"], v["cc"])
    ustawDanePojazdu(vehv["id"], v["wlasciciel"])
    
    --ustawiam paliwo i przebieg
    setElementData(veh"pojazd_paliwo"v["paliwo"] or 50)
    setElementData(veh"pojazd_przebieg"v["przebieg"] or 0)
    --<< na koncu -->>
    local query dbQuery(handler"SELECT * FROM tuning WHERE id='"..v["id"].."'")
    local resultnum_rowserrormsg dbPoll (query, -1)
    setVehiclePaintjob(vehresult[1].paintjob)
    setVehicleHeadLightColor(vehresult[1].hrresult[1].hgresult[1].hb)
        for i,v in pairs(result) do
            for iivv in pairs(v) do
                if (ii ~= "id" and ii ~= "paintjob" and ii ~= "hr" and ii ~= "hg" and ii ~= "hb"then
                local vv tonumber(vv)
                    if vv ~= 0 then
                    addVehicleUpgrade(vehvv)
                    end
                end
            end
        end
    end
end
addEventHandler("onResourceStart"getResourceRootElement(getThisResource()), onStartLoadVehicles)

function ustawDanePojazdu(vehidwlasciciel) --id INTwlasciciel STRING
setElementData(veh"car_id"id)
setElementData(veh"car_owner"wlasciciel)
end

function onVehicleStartEnter(playerseatjacked)
  if seat == 0 then
  local car_owner getElementData(source"car_owner")
    if car_owner then
    local account getPlayerAccount(player)
        if account then
        local name getAccountName(account)
            if car_owner == name then
            --mamy prawo wejscia do auta
            prawo_ true
            end
        end
    
        if prawo_ then
        --wchodzim
        prawo_ false
        else
        --sio
        outputChatBox("Nie masz kluczyk?w do tego pojazdu."player255255255true)
        cancelEvent()
        end
    end
  end
end
addEventHandler ("onVehicleStartEnter"resourceRootonVehicleStartEnter)

--<<ZAPIS POJAZDU-->>

function zapiszPojazdy()
    for i,v in pairs(getElementsByType("vehicle")) do
    local id getElementData(v"car_id")
        if id then
        local owner getElementData(v"car_owner")
        local xygetElementPosition(v)
        local __rot getElementRotation(v)
        local dim getElementDimension(v)
        local int getElementInterior(v)
        local color1color2color3color4 getVehicleColor(vtrue)
        local paliwo getElementData(v"pojazd_paliwo")
        local przebieg getElementData(v"pojazd_przebieg")
        dbExec(handler"UPDATE pojazdy SET x='"..x.."', y='"..y.."', z='"..z.."', rot='"..rot.."', ca='"..color1.."', cb='"..color2.."', cc='"..color3.."', dim="..dimension..", int="..interior..", przebieg='"..przebieg.."', paliwo='"..paliwo.."' WHERE id='"..id.."'")
        
        local paintjob getVehiclePaintjob(v)
        local rggetVehicleHeadLightColor(v)
        sav = {}
            for i=016 do
            local upgrade getVehicleUpgradeOnSlot(vi)
            sav[i] = upgrade or 0
            end
        dbExec(handler"UPDATE tuning SET t0='"..sav[0].."', t1='"..sav[1].."', t2='"..sav[2].."', t3='"..sav[3].."', t4='"..sav[4].."', t5='"..sav[5].."', t6='"..sav[6].."', t7='"..sav[7].."', t8='"..sav[8].."', t9='"..sav[9].."', t10='"..sav[10].."', t11='"..sav[11].."', t12='"..sav[12].."', t13='"..sav[13].."', t14='"..sav[14].."', t15='"..sav[15].."', t16='"..sav[16].."', paintjob='"..paintjob.."', hr='"..r.."', hg='"..g.."', hb='"..b.."' WHERE id="..id.."")
        sav nil
        end
    end
end
setTimer(zapiszPojazdy9000000)

function zapiszKomenda(player)
local acc getAccountName (getPlayerAccount(player))
    if isObjectInACLGroup ("user."..accaclGetGroup ("Admin")) then
    zapiszPojazdy()
    outputChatBox("** Zapisano pojazdy."player255255255true)
    end
end
addCommandHandler("zapiszpojazdy"zapiszKomenda)

-- mapaf11
addEvent("pobierzPojazdyGracza"true)
addEventHandler("pobierzPojazdyGracza"getRootElement(),
function()
local account getPlayerAccount(source)
    if account then
    local name getAccountName(account)
    local vehs getVehiclesByOwner(name)
    triggerClientEvent(source"zwrocPojazdyGracza"rootvehs)
    end
end)

--
--zwraca pojazd o danym ID
function getVehicleByID(poszukiwane_id)
    for i,v in pairs(getElementsByType("vehicle")) do
    local id getElementData(v"car_id")
        if id then
        local id tonumber(id)
        local poszukiwane_id tonumber(poszukiwane_id)
            if id == poszukiwane_id then
            return v
            end
        end
    end
    return false
end

--zwraca pojazdy ktore posiada dany login
function getVehiclesByOwner(szukany)
tab = {}
    for i,v in pairs(getElementsByType("vehicle")) do
    local owner getElementData(v"car_owner")
        if owner then
            if owner == szukany then
            table.insert(tabv)
            end
        end
    end
    return tab
end

--zwraca liczbe pojazdow jaka ma dany login
function getYourVehicleCount(login)
local vehs getVehiclesByOwner(login)
return #vehs
end


Dodaj do pliku .db tabelk? o nazwie int i dim

Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-22, 20:29


THEGizmo

Modeler/Uczeń Lua






Wiek: 27
Na forum: 4141 dni
Posty: 255
Nick w MP: THEGizmo

Piwa: 3072

Respekt: 200
Respekt: 200Respekt: 200

Fanciak, niestety ja tego DB nie bardzo ogarniam.
ten kod jest z systemu prywatnych pojazd?w panaprezesa.

Podpis
Modeler Corporation Sp. Z.O.O

Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-23, 08:19


Fanciak

BOT






Wiek: 25
Na forum: 4446 dni
Posty: 728
Nick w MP: Fanciak

Piwa: 1572

Respekt: 500
Respekt: 500

?ci?gasz program DB for SQLite i otwierasz tym plik .db i tam tylko dodajesz tabelk?, wystarczy angielski.

Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-23, 20:22


THEGizmo

Modeler/Uczeń Lua






Wiek: 27
Na forum: 4141 dni
Posty: 255
Nick w MP: THEGizmo

Piwa: 3072

Respekt: 200
Respekt: 200Respekt: 200

Fanciak, a nie da si? w kodzie tego zrobi? z?by tworzy?o tabele ? :/ nie chce si? bawi? jaki? programem ...

Podpis
Modeler Corporation Sp. Z.O.O

Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-24, 11:20


Loop

Inspektor






Wiek: 27
Na forum: 4289 dni
Posty: 311
Nick w MP: Inspektor

Piwa: 201

Respekt: 130
Respekt: 130

da sie inaczej ale tak jest pro?ciej.

Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-24, 11:46


Maximerr

Programmer PHP, LUA






Wiek: 25
Na forum: 4427 dni
Posty: 548

Piwa: 1051

Respekt: 365,3
Respekt: 365,3Respekt: 365,3Respekt: 365,3Respekt: 365,3

 dbExec(handler,?"CREATE?TABLE?IF?NOT?EXISTS?pojazdy?(id?INTEGER?PRIMARY?KEY?AUTOINCREMENT,?wlasciciel?TEXT,?model?INTEGER,?x?FLOAT,?y?FLOAT,?z?FLOAT,?rot?FLOAT,?ca?INTEGER,?cb?INTEGER,?cc?INTEGER,?przebieg?FLOAT,?paliwo?FLOAT, dim INTEGER, int INTEGER)")


Postaw piwo autorowi tego posta
 

 
Wysłany: 2015-07-24, 20:30


THEGizmo

Modeler/Uczeń Lua






Wiek: 27
Na forum: 4141 dni
Posty: 255
Nick w MP: THEGizmo

Piwa: 3072

Respekt: 200
Respekt: 200Respekt: 200

I zn?w mi bardzo pomog?e? Maximerr, ?ap :piwo: a ty Fanciak, tez ?ap :piwo:

Do zamkni?cia

PS: nie wiem jak ale da?em jako? Fanciakowi 2 piwa :| mo?liwe ze przez m?j net co? si? zbugowa?o ...

Podpis
Modeler Corporation Sp. Z.O.O

Postaw piwo autorowi tego posta
 

 
Tagi: zapis :: pojazdu :: interior :: dimension
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA Ten temat jest zablokowany bez możliwości zmiany postów lub pisania odpowiedzi

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku