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

Wysłany: 2016-09-23, 16:28


ZZiomek

..::LUA::..






Wiek: 26
Na forum: 3867 dni
Posty: 134
Nick w MP: NexBoy

Piwa: 5961

Respekt: 155,3
Respekt: 155,3Respekt: 155,3

Witam chcia?bym pod?oczy? do sql takom w?a?nie element dat? ale nw jak to zrobi? bo nie bardzo ogarniam sql

Element data:
setElementData(pojazd"Turbo""1")



a tu kod zapisu aut:
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, lighthp INTEGER)")
dbExec(handler"CREATE UNIQUE INDEX IF NOT EXISTS IDX_id on tuning(id)")

local function getVehicle(id)
    if id then
        id=tonumber(id)
        for _,v in ipairs(getElementsByType("vehicle"))do
            if getElementData(v,"car_id"then
                if getElementData(v,"car_id")==id then
                    return v
                end
            end
        end
    end
    return false
end

addCommandHandler("fix",function(plr,cmd,id) 
if id then 
id=tonumber(idlocal veh=getVehicle(id) 
if veh then 
local acc getAccountName (getPlayerAccount(plr)) 
if isObjectInACLGroup ("user."..accaclGetGroup ("Admin")) then 
fixVehicle(vehend 
end 
end
end )


addCommandHandler("warp",function(plr,cmd,id)
        if id then
                id=tonumber(id)
                local veh=getVehicle(id)
                if veh then
                    local x,y,z=getElementPosition(plr)
                    local int=getElementInterior(plr)
                    local dim=getElementDimension(plr)
                    setElementPosition(veh,x,y,z)
                    setElementPosition(plr,x,y,z+2)
                    setElementDimension(veh,dim)
                    setElementInterior(veh,int)
                    warpPedIntoVehicle(plrveh)
                    outputChatBox("Przenios?e? do Siebie "..getVehicleName(veh).." ( ID : "..getElementData(veh,"car_id").." )",plr,255,255,255)
                end
            end

end)



--dbExec(handler"ALTER TABLE tuning ADD COLUMN lighthp INTEGER");

function onStartLoadVehicles()
local query dbQuery(handler"SELECT * FROM pojazdy")
local resultnum_rowserrormsg dbPoll (query, -1)
    for i,v in pairs(result) do
    local check exports.przechoEL:czyPojazdJestWPrzechowywalni(v["id"])
        if not check then
        local veh createVehicle(v["model"], v["x"], v["y"], v["z"], 000"LS "..v["id"])
        setElementRotation(veh00v["rot"])
        ustawDanePojazdu(vehv["id"], v["wlasciciel"], v["ca"], v["cb"], v["cc"],v["paliwo"], v["przebieg"])
        loadTuning(vehv["id"])
        end
    end
end
addEventHandler("onResourceStart"getResourceRootElement(getThisResource()), onStartLoadVehicles)

function stworzPojazd(idxyz)
local query dbQuery(handler"SELECT * FROM pojazdy WHERE id='"..id.."'")
local resultnum_rowserrormsg dbPoll (query, -1)
    if #result > 0 then
    local v result[1]
    local veh createVehicle(v["model"], xyz000"LS "..v["id"])
    setElementRotation(veh000)
    ustawDanePojazdu(vehidv["wlasciciel"], v["ca"], v["cb"], v["cc"], v["paliwo"], v["przebieg"])
    loadTuning(vehid)
    setElementData(veh"pojazdy_paliwo"v["paliwo"])
    setElementData(veh"pojazdy_przebieg"v["przebieg"])
    return veh
    else
    return false
    end    
end

function ustawDanePojazdu(vehidwlascicielrgbpaliwoprzebieg) --id INTwlasciciel STRING
setElementData(veh"car_id"id)
setElementData(veh"car_owner"wlasciciel)
    if and and b then
    setVehicleColor(vehrgb)
    end
    
    if paliwo then
    setElementData(veh"pojazdy_paliwo"paliwo)
    end
    
    if przebieg then
    setElementData(veh"pojazdy_przebieg"przebieg)
    end
end

function loadTuning(veh,id)
local query dbQuery(handler"SELECT * FROM tuning WHERE id='"..id.."'")
local resultnum_rowserrormsg dbPoll (query, -1)
    if #result > 0 then
    setVehiclePaintjob(vehresult[1].paintjob)
    setVehicleHeadLightColor(vehresult[1].hrresult[1].hgresult[1].hb)
    setElementData(veh"swiatla-uszkodzenia"result[1].lighthp or false)
        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" and ii ~= "lighthp"then
                local vv tonumber(vv)
                    if vv ~= 0 then
                    addVehicleUpgrade(vehvv)
                    end
                end
            end
        end
    end
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
        exports.Powiadomienia:showBox(player"error","* Nie Posiadasz Kluczyk?w Do Tego Pojazdu!")
        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"pojazdy_paliwo") or 10
        local przebieg getElementData(v"pojazdy_przebieg") or 0
        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)
        local hp getElementData(v"swiatla-uszkodzenia") or 0
        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.."', lighthp='"..hp.."' WHERE id="..id.."")
        sav nil
        end
        
    --no explode
    local hp getElementHealth(v)
        if 400 hp then
        setVehicleDamageProof(vtrue)
        else
        setVehicleDamageProof(vfalse)
        end
    end    
end
setTimer(zapiszPojazdy10000)

function zapiszKomenda(player)
local acc getAccountName (getPlayerAccount(player))
    if isObjectInACLGroup ("user."..accaclGetGroup ("RCON")) 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

Dodaj na Steam: Kod: 1093365219
Discord: NoOne#3644

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-09-23, 18:47


_Haze

Peace Yo!






Wiek: 24
Na forum: 4184 dni
Posty: 1648
Nick w MP: Haze

Piwa: 2628

Respekt: 1020
Respekt: 1020

Dodajesz do
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)")

turbo TEXT czyli
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, turbo TEXT)")

tutaj daje element date
function onStartLoadVehicles()
local query dbQuery(handler"SELECT * FROM pojazdy")
local resultnum_rowserrormsg dbPoll (query, -1)
    for i,v in pairs(result) do
    local check exports.przechoEL:czyPojazdJestWPrzechowywalni(v["id"])
        if not check then
        local veh createVehicle(v["model"], v["x"], v["y"], v["z"], 000"LS "..v["id"])
        setElementRotation(veh00v["rot"])
        ustawDanePojazdu(vehv["id"], v["wlasciciel"], v["ca"], v["cb"], v["cc"],v["paliwo"], v["przebieg"])
        setElementData(veh"Turbo"v.turbo) -- TUTAJ DAJE TURBO 
        loadTuning(vehv["id"])
        end
    end
end
addEventHandler("onResourceStart"getResourceRootElement(getThisResource()), onStartLoadVehicles)

Da?em tam turbo TEXT poniewa? da?e? ' "1" zamiast 1'

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-09-23, 19:43


ZZiomek

..::LUA::..






Wiek: 26
Na forum: 3867 dni
Posty: 134
Nick w MP: NexBoy

Piwa: 5961

Respekt: 155,3
Respekt: 155,3Respekt: 155,3

Hazmudex, dalej nie zapisuje zadnych b??d?w w DB

[ Dodano: 2016-09-23, 20:07 ]
gdy resetne skrypt na zapis auto to jest zapisane ale gdy dam do przecho to nie zapisuje. :/

Podpis

Dodaj na Steam: Kod: 1093365219
Discord: NoOne#3644

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-09-23, 20:34


Jurandovsky

Kurdebele






Wiek: 17
Na forum: 4838 dni
Posty: 915

Piwa: 2697

Respekt: 955,3
Respekt: 955,3Respekt: 955,3

Bo albo nie widze, albo nie dodales 'dbExec' z UPDATE'm lub INSERTE'm tej warto?ci, podczas wk?adania pojazdu do przechowalni.

Podpis
Jedyny kontakt ze mną to PW forum

Kod:


local noobs = getElementsByTitle("player", "Programista LUA")
for k, v in ipairs(noobs) do
outputChatBox("Bez mózgu jest użytkownik o nicku: "..getPlayerName(v), root)
destroyElement(v)
end
Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-09-23, 20:34


ZZiomek

..::LUA::..






Wiek: 26
Na forum: 3867 dni
Posty: 134
Nick w MP: NexBoy

Piwa: 5961

Respekt: 155,3
Respekt: 155,3Respekt: 155,3

Dobra zrobi?em to dzi?ki Hazmudex, temat do zamkni?cia

Podpis

Dodaj na Steam: Kod: 1093365219
Discord: NoOne#3644

Postaw piwo autorowi tego posta
 

 
Tagi: sqlite :: elementdata
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA » Sqlite ElementData 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