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

Wysłany: 2016-01-19, 22:38


sebik2303

Mapper :)






Wiek: 25
Na forum: 4301 dni
Posty: 298
Nick w MP: sebik2303

Piwa: 899

Respekt: 55,3

Witam, chcia?bym zrobi? zapis tuningu engineAcceleration. Jak to zrobi? ? :)


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 result, num_rows, errormsg = dbPoll (query, -1)
    for i,v in pairs(result) do
    local veh = createVehicle(v["model"], v["x"], v["y"], v["z"])
    setElementRotation(veh, 0, 0, v["rot"])
    setVehicleColor(veh, v["ca"], v["cb"], v["cc"])
    ustawDanePojazdu(veh, v["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 result, num_rows, errormsg = dbPoll (query, -1)
    setVehiclePaintjob(veh, result[1].paintjob)
    setVehicleHeadLightColor(veh, result[1].hr, result[1].hg, result[1].hb)
        for i,v in pairs(result) do
            for ii, vv 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(veh, vv)
                    end
                end
            end
        end
    end
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStartLoadVehicles)

function ustawDanePojazdu(veh, id, wlasciciel) --id = INT, wlasciciel = STRING
setElementData(veh, "car_id", id)
setElementData(veh, "car_owner", wlasciciel)
end

function onVehicleStartEnter(player, seat, jacked)
  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.", player, 255, 255, 255, true)
        cancelEvent()
        end
    end
  end
end
addEventHandler ("onVehicleStartEnter", resourceRoot, onVehicleStartEnter)

--<<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 x, y, z = getElementPosition(v)
        local _, _, rot = getElementRotation(v)
        local color1, color2, color3, color4 = getVehicleColor(v, true)
        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 r, g, b = getVehicleHeadLightColor(v)
        sav = {}
            for i=0, 16 do
            local upgrade = getVehicleUpgradeOnSlot(v, i)
            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(zapiszPojazdy, 5000, 0)

function zapiszKomenda(player)
local acc = getAccountName (getPlayerAccount(player))
    if isObjectInACLGroup ("user."..acc, aclGetGroup ("Admin")) then
    zapiszPojazdy()
    outputChatBox("** Zapisano pojazdy.", player, 255, 255, 255, true)
    end
end
addCommandHandler("zapiszpojazdy", zapiszKomenda)

-- mapa, f11
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", root, vehs)
    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(tab, v)
            end
        end
    end
    return tab
end

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


Za pomoc daje :piwo: :piwo: :piwo:

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-01-19, 23:24


Kronix.Cooder







Wiek: 36
Na forum: 5040 dni
Posty: 26

Piwa: 15

Respekt: 90


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, ea FLOAT)")
dbExec(handler, "CREATE UNIQUE INDEX IF NOT EXISTS IDX_id on tuning(id)")


function onStartLoadVehicles()
local query = dbQuery(handler, "SELECT * FROM pojazdy")
local result, num_rows, errormsg = dbPoll (query, -1)
    for i,v in pairs(result) do
    local veh = createVehicle(v["model"], v["x"], v["y"], v["z"])
    setElementRotation(veh, 0, 0, v["rot"])
    setVehicleColor(veh, v["ca"], v["cb"], v["cc"])
    ustawDanePojazdu(veh, v["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 result, num_rows, errormsg = dbPoll (query, -1)
    setVehiclePaintjob(veh, result[1].paintjob)
    setVehicleHeadLightColor(veh, result[1].hr, result[1].hg, result[1].hb)
    
    --ustawienie eA
    setVehicleHandling(veh, "engineAcceleration", result[1].ea )
    
        for i,v in pairs(result) do
            for ii, vv 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(veh, vv)
                    end
                end
            end
        end
    end
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStartLoadVehicles)

function ustawDanePojazdu(veh, id, wlasciciel) --id = INT, wlasciciel = STRING
setElementData(veh, "car_id", id)
setElementData(veh, "car_owner", wlasciciel)
end

function onVehicleStartEnter(player, seat, jacked)
  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.", player, 255, 255, 255, true)
        cancelEvent()
        end
    end
  end
end
addEventHandler ("onVehicleStartEnter", resourceRoot, onVehicleStartEnter)

--<<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 x, y, z = getElementPosition(v)
        local _, _, rot = getElementRotation(v)
        local color1, color2, color3, color4 = getVehicleColor(v, true)
        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 r, g, b = getVehicleHeadLightColor(v)
        sav = {}
            for i=0, 16 do
            local upgrade = getVehicleUpgradeOnSlot(v, i)
            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.."', ea='"..getVehicleHandling(v).engineAcceleration.."' WHERE id="..id.."")
        sav = nil
        end
    end
end
setTimer(zapiszPojazdy, 5000, 0)

function zapiszKomenda(player)
local acc = getAccountName (getPlayerAccount(player))
    if isObjectInACLGroup ("user."..acc, aclGetGroup ("Admin")) then
    zapiszPojazdy()
    outputChatBox("** Zapisano pojazdy.", player, 255, 255, 255, true)
    end
end
addCommandHandler("zapiszpojazdy", zapiszKomenda)

-- mapa, f11
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", root, vehs)
    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(tab, v)
            end
        end
    end
    return tab
end

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


nie zapomnij doda? w tabeli tuning kolumny `ea` typu FLOAT albo usu? plik pojazdy.db aby si? utworzy?o na nowo. (uwaga: usuni?cie pliku spowoduje utrat? zapisanych danych)

Oraz dodaj sobie tam gdzie masz INSERT INTO ...
getVehicleHandling(vehicle).engineAcceleration

vehicle - to oczywi?cie pojazd

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-01-20, 00:01


sebik2303

Mapper :)






Wiek: 25
Na forum: 4301 dni
Posty: 298
Nick w MP: sebik2303

Piwa: 899

Respekt: 55,3

Kronix.Cooder, W sensie pod INSERT INTO ? :) w SQL nie czaje ;)

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-01-20, 00:06


Kronix.Cooder







Wiek: 36
Na forum: 5040 dni
Posty: 26

Piwa: 15

Respekt: 90

nie, do??cz jako argument,
podpatrz sobie co zmieni?em w twoim kodzie tam gdzie jest UPDATE tuning

albo pode?lij linie gdzie jest u ciebie INSERT INTO to ci zmienie

edit:
chyba ?e pojazdy do tabeli w sql dodajesz poza tym skryptem?
nie wiem jak to u ciebie jest

chodzi o fragment skryptu gdzie dodajesz nowy pojazd do sql

Ostatnio zmieniony przez Kronix.Cooder 2016-01-20, 00:22, w całości zmieniany 1 raz  
Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-01-20, 00:20


sebik2303

Mapper :)






Wiek: 25
Na forum: 4301 dni
Posty: 298
Nick w MP: sebik2303

Piwa: 899

Respekt: 55,3

Kronix.Cooder, chodzi ci o:

dbExec(handler, "INSERT INTO tuning (id, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, paintjob, hr, hg, hb) VALUES (?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", last_insert_id, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "3", r, g, b)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-01-20, 00:28


Kronix.Cooder







Wiek: 36
Na forum: 5040 dni
Posty: 26

Piwa: 15

Respekt: 90

tak, dok?adnie
prawdopodobnie nad tym masz INSERT INTO pojazdy , a nad tym zapewne u?ywasz twojazmienna = createVehicle(...blabla

wi?c podmie? sobie vehicle na nazw? twojej zmiennej.

dbExec(handler, "INSERT INTO tuning (id, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, paintjob, hr, hg, hb,ea) VALUES (?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", last_insert_id, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "3", r, g, b,getVehicleHandling(vehicle).engineAcceleration)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-01-20, 00:32


sebik2303

Mapper :)






Wiek: 25
Na forum: 4301 dni
Posty: 298
Nick w MP: sebik2303

Piwa: 899

Respekt: 55,3

Kronix.Cooder, wi?c m?j kod :

local salon = createMarker(-1948.5, 272.10000610352, 34.6, "cylinder", 1, 255, 0, 0, 100)

function onSalonHit(hitElement, dim)
    if getElementType(hitElement) == "player" then
    triggerClientEvent(hitElement, "pokazGUISalonu", root, salonowePojazdy)
    end
end
addEventHandler("onMarkerHit", salon, onSalonHit)

addEvent("kupPojazdSalon", true)
addEventHandler("kupPojazdSalon", getRootElement(),
function(id)
local cena = salonowePojazdy[id]
    if cena then
        if getPlayerMoney(source) >= cena then
        local account = getPlayerAccount(source)
          if account then
          local wlasciciel = getAccountName(account)
            if 10000 >= getYourVehicleCount(wlasciciel) then
            takePlayerMoney(source, cena)
            triggerClientEvent(source, "potwierdzKupnoPojazduPrywatnego", root)
            fadeCamera(source, false)
                setTimer(function(source)
                local x, y, z, rot = -1987.46, 276.18, 34.86, 270
                local veh = createVehicle(id, x, y, z)
                setElementData(veh, "pojazd_paliwo", 50) --na specjalna prosbe ;)
                setElementData(veh, "pojazd_przebieg", 0)
                local r, g, b = getVehicleColor(veh, true)
                fadeCamera(source, true)
                --<<-->>
                local query = dbQuery(handler, "INSERT INTO pojazdy (wlasciciel, model, x, y, z, rot, ca, cb, cc, przebieg, paliwo) VALUES (?, ?, ?, ?, ?, ?,?,?,?,?,?)", wlasciciel, id, x, y, z, rot, r, g, b, 50, 0)
                local result, num_affected_rows, last_insert_id = dbPoll(query, -1)
                local r, g, b = getVehicleHeadLightColor(veh)
                dbExec(handler, "INSERT INTO tuning (id, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, paintjob, hr, hg, hb) VALUES (?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", last_insert_id, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "3", r, g, b)
                --<<-->>
                setElementRotation(veh, 0, 0, rot)
                ustawDanePojazdu(veh, last_insert_id, wlasciciel)
                warpPedIntoVehicle(source, veh)
                end, 1500, 1, source)
            else
            outputChatBox("Mo?esz posiada? maksymalnie . pojazd?w.", source, 255, 255, 255, true)
            end
          end
        else
        outputChatBox("Potrzebujesz "..cena.."Euro by kupi? ten pojazd.", source, 255, 255, 255, true)
        end
    end
end)

--komenda tworzaca
function stworzPojazdCMD(player, cmd, id, wlasciciel)
local acc = getAccountName (getPlayerAccount(player))
    if acc then
    if isObjectInACLGroup ("user."..acc, aclGetGroup ("RCON")) then
        if id and wlasciciel then
        local id = tonumber(id)
            if id then
                if getVehicleNameFromModel(id) then
                local x, y, z = getElementPosition(player)
                local _, _, rot = getElementRotation(player)
                
                local veh = createVehicle(id, x, y, z)
                    if veh then
                    setElementData(veh, "pojazd_paliwo", 50) --na specjalna prosbe ;)
                    setElementData(veh, "pojazd_przebieg", 0)
                    local r, g, b = getVehicleColor(veh, true)
                    --<<-->>
                    local query = dbQuery(handler, "INSERT INTO pojazdy (wlasciciel, model, x, y, z, rot, ca, cb, cc, przebieg, paliwo) VALUES (?, ?, ?, ?, ?, ?,?,?,?,?,?)", wlasciciel, id, x, y, z, rot, r, g, b, 50, 0)
                    local result, num_affected_rows, last_insert_id = dbPoll(query, -1)
                    local r, g, b = getVehicleHeadLightColor(veh)
                    dbExec(handler, "INSERT INTO tuning (id, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, paintjob, hr, hg, hb) VALUES (?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", last_insert_id, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "3", r, g, b)
                    --<<-->>
                    setElementRotation(veh, 0, 0, rot)
                    ustawDanePojazdu(veh, last_insert_id, wlasciciel)
                    else
                    outputChatBox("Podane ID jest niepoprawne.", player, 255, 255, 255, true)
                    end
                else
                outputChatBox("Podane ID jest niepoprawne.", player, 255, 255, 255, true)
                end
            end
        else
        outputChatBox("Wpisz /stworz [id-pojazdu] [wlasciciel]", player, 255, 255, 255, true)
        end
    end
    end
end
addCommandHandler("stworz", stworzPojazdCMD)

i do ka?dego ?

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-01-20, 00:38


Kronix.Cooder







Wiek: 36
Na forum: 5040 dni
Posty: 26

Piwa: 15

Respekt: 90

local salon = createMarker(-1948.5, 272.10000610352, 34.6, "cylinder", 1, 255, 0, 0, 100)

function onSalonHit(hitElement, dim)
    if getElementType(hitElement) == "player" then
    triggerClientEvent(hitElement, "pokazGUISalonu", root, salonowePojazdy)
    end
end
addEventHandler("onMarkerHit", salon, onSalonHit)

addEvent("kupPojazdSalon", true)
addEventHandler("kupPojazdSalon", getRootElement(),
function(id)
local cena = salonowePojazdy[id]
    if cena then
        if getPlayerMoney(source) >= cena then
        local account = getPlayerAccount(source)
          if account then
          local wlasciciel = getAccountName(account)
            if 10000 >= getYourVehicleCount(wlasciciel) then
            takePlayerMoney(source, cena)
            triggerClientEvent(source, "potwierdzKupnoPojazduPrywatnego", root)
            fadeCamera(source, false)
                setTimer(function(source)
                local x, y, z, rot = -1987.46, 276.18, 34.86, 270
                local veh = createVehicle(id, x, y, z)
                setElementData(veh, "pojazd_paliwo", 50) --na specjalna prosbe ;)
                setElementData(veh, "pojazd_przebieg", 0)
                local r, g, b = getVehicleColor(veh, true)
                fadeCamera(source, true)
                --<<-->>
                local query = dbQuery(handler, "INSERT INTO pojazdy (wlasciciel, model, x, y, z, rot, ca, cb, cc, przebieg, paliwo) VALUES (?, ?, ?, ?, ?, ?,?,?,?,?,?)", wlasciciel, id, x, y, z, rot, r, g, b, 50, 0)
                local result, num_affected_rows, last_insert_id = dbPoll(query, -1)
                local r, g, b = getVehicleHeadLightColor(veh)
                dbExec(handler, "INSERT INTO tuning (id, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, paintjob, hr, hg, hb,ae) VALUES (?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", last_insert_id, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "3", r, g, b,getVehicleHandling(veh).engineAcceleration)
                --<<-->>
                setElementRotation(veh, 0, 0, rot)
                ustawDanePojazdu(veh, last_insert_id, wlasciciel)
                warpPedIntoVehicle(source, veh)
                end, 1500, 1, source)
            else
            outputChatBox("Mo?esz posiada? maksymalnie . pojazd?w.", source, 255, 255, 255, true)
            end
          end
        else
        outputChatBox("Potrzebujesz "..cena.."Euro by kupi? ten pojazd.", source, 255, 255, 255, true)
        end
    end
end)

--komenda tworzaca
function stworzPojazdCMD(player, cmd, id, wlasciciel)
local acc = getAccountName (getPlayerAccount(player))
    if acc then
    if isObjectInACLGroup ("user."..acc, aclGetGroup ("RCON")) then
        if id and wlasciciel then
        local id = tonumber(id)
            if id then
                if getVehicleNameFromModel(id) then
                local x, y, z = getElementPosition(player)
                local _, _, rot = getElementRotation(player)
                
                local veh = createVehicle(id, x, y, z)
                    if veh then
                    setElementData(veh, "pojazd_paliwo", 50) --na specjalna prosbe ;)
                    setElementData(veh, "pojazd_przebieg", 0)
                    local r, g, b = getVehicleColor(veh, true)
                    --<<-->>
                    local query = dbQuery(handler, "INSERT INTO pojazdy (wlasciciel, model, x, y, z, rot, ca, cb, cc, przebieg, paliwo) VALUES (?, ?, ?, ?, ?, ?,?,?,?,?,?)", wlasciciel, id, x, y, z, rot, r, g, b, 50, 0)
                    local result, num_affected_rows, last_insert_id = dbPoll(query, -1)
                    local r, g, b = getVehicleHeadLightColor(veh)
                    dbExec(handler, "INSERT INTO tuning (id, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, paintjob, hr, hg, hb,ea) VALUES (?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", last_insert_id, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "3", r, g, b,getVehicleHandling(veh).engineAcceleration)
                    --<<-->>
                    setElementRotation(veh, 0, 0, rot)
                    ustawDanePojazdu(veh, last_insert_id, wlasciciel)
                    else
                    outputChatBox("Podane ID jest niepoprawne.", player, 255, 255, 255, true)
                    end
                else
                outputChatBox("Podane ID jest niepoprawne.", player, 255, 255, 255, true)
                end
            end
        else
        outputChatBox("Wpisz /stworz [id-pojazdu] [wlasciciel]", player, 255, 255, 255, true)
        end
    end
    end
end
addCommandHandler("stworz", stworzPojazdCMD)


mam nadzieje si? nie pomyli?em

pamieta?e? o dodaniu kolumny w sql?
albo usun?? plik je?li jest tylko kilka pojazd?w zapisanych aby sie baza utworzy?a na nowo?

Ostatnio zmieniony przez Kronix.Cooder 2016-01-20, 00:42, w całości zmieniany 1 raz  
Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-01-20, 00:40


sebik2303

Mapper :)






Wiek: 25
Na forum: 4301 dni
Posty: 298
Nick w MP: sebik2303

Piwa: 899

Respekt: 55,3

Kronix.Cooder, tak :)

[ Dodano: 2016-01-20, 00:42 ]
DB mam

[ Dodano: 2016-01-20, 00:42 ]
Ta linijka :

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.."', ea='"..getVehicleHandling(v).engineAcceleration.."' WHERE id="..id.."")


Nowa baza danych jest

[ Dodano: 2016-01-20, 00:45 ]
oraz przy tworzeniu pojazdu :


linijka :
dbExec(handler, "INSERT INTO tuning (id, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, paintjob, hr, hg, hb,ea) VALUES (?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", last_insert_id, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "3", r, g, b,getVehicleHandling(vehicle).engineAcceleration)


155

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-01-20, 00:54


Kronix.Cooder







Wiek: 36
Na forum: 5040 dni
Posty: 26

Piwa: 15

Respekt: 90

linijka 155 masz ?le, sprawdz

sprawd? czy masz tak samo
przetestowa?em ten kod u siebie i jest ok :
--komenda tworzaca
function stworzPojazdCMD(player, cmd, id, wlasciciel)
local acc = getAccountName (getPlayerAccount(player))
    if acc then
    if isObjectInACLGroup ("user."..acc, aclGetGroup ("RCON")) then
        if id and wlasciciel then
        local id = tonumber(id)
            if id then
                if getVehicleNameFromModel(id) then
                local x, y, z = getElementPosition(player)
                local _, _, rot = getElementRotation(player)
                
                local veh = createVehicle(id, x, y, z)
                    if veh then
                    setElementData(veh, "pojazd_paliwo", 50) --na specjalna prosbe ;)
                    setElementData(veh, "pojazd_przebieg", 0)
                    local r, g, b = getVehicleColor(veh, true)
                    --<<-->>
                    local query = dbQuery(handler, "INSERT INTO pojazdy (wlasciciel, model, x, y, z, rot, ca, cb, cc, przebieg, paliwo) VALUES (?, ?, ?, ?, ?, ?,?,?,?,?,?)", wlasciciel, id, x, y, z, rot, r, g, b, 50, 0)
                    local result, num_affected_rows, last_insert_id = dbPoll(query, -1)
                    local r, g, b = getVehicleHeadLightColor(veh)
                    dbExec(handler, "INSERT INTO tuning (id, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, paintjob, hr, hg, hb,ea) VALUES (?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", last_insert_id, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "3", r, g, b,getVehicleHandling(veh).engineAcceleration)
                    --<<-->>
                    setElementRotation(veh, 0, 0, rot)
                    ustawDanePojazdu(veh, last_insert_id, wlasciciel)
                    else
                    outputChatBox("Podane ID jest niepoprawne.", player, 255, 255, 255, true)
                    end
                else
                outputChatBox("Podane ID jest niepoprawne.", player, 255, 255, 255, true)
                end
            end
        else
        outputChatBox("Wpisz /stworz [id-pojazdu] [wlasciciel]", player, 255, 255, 255, true)
        end
    end
    end
end
addCommandHandler("stworz", stworzPojazdCMD)


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, ea FLOAT)")
dbExec(handler, "CREATE UNIQUE INDEX IF NOT EXISTS IDX_id on tuning(id)")


function onStartLoadVehicles()
local query = dbQuery(handler, "SELECT * FROM pojazdy")
local result, num_rows, errormsg = dbPoll (query, -1)
    for i,v in pairs(result) do
    local veh = createVehicle(v["model"], v["x"], v["y"], v["z"])
    setElementRotation(veh, 0, 0, v["rot"])
    setVehicleColor(veh, v["ca"], v["cb"], v["cc"])
    ustawDanePojazdu(veh, v["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 result, num_rows, errormsg = dbPoll (query, -1)
    setVehiclePaintjob(veh, result[1].paintjob)
    setVehicleHeadLightColor(veh, result[1].hr, result[1].hg, result[1].hb)
    
    --ustawienie eA
    setVehicleHandling(veh, "engineAcceleration", result[1].ea )
    
        for i,v in pairs(result) do
            for ii, vv 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(veh, vv)
                    end
                end
            end
        end
    end
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStartLoadVehicles)

function ustawDanePojazdu(veh, id, wlasciciel) --id = INT, wlasciciel = STRING
setElementData(veh, "car_id", id)
setElementData(veh, "car_owner", wlasciciel)
end

function onVehicleStartEnter(player, seat, jacked)
  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.", player, 255, 255, 255, true)
        cancelEvent()
        end
    end
  end
end
addEventHandler ("onVehicleStartEnter", resourceRoot, onVehicleStartEnter)

--<<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 x, y, z = getElementPosition(v)
        local _, _, rot = getElementRotation(v)
        local color1, color2, color3, color4 = getVehicleColor(v, true)
        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 r, g, b = getVehicleHeadLightColor(v)
        sav = {}
            for i=0, 16 do
            local upgrade = getVehicleUpgradeOnSlot(v, i)
            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.."', ea='"..getVehicleHandling(v).engineAcceleration.."' WHERE id="..id.."")
        sav = nil
        end
    end
end
setTimer(zapiszPojazdy, 5000, 0)

function zapiszKomenda(player)
local acc = getAccountName (getPlayerAccount(player))
    if isObjectInACLGroup ("user."..acc, aclGetGroup ("Admin")) then
    zapiszPojazdy()
    outputChatBox("** Zapisano pojazdy.", player, 255, 255, 255, true)
    end
end
addCommandHandler("zapiszpojazdy", zapiszKomenda)

-- mapa, f11
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", root, vehs)
    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(tab, v)
            end
        end
    end
    return tab
end

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



Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-01-20, 10:43


sebik2303

Mapper :)






Wiek: 25
Na forum: 4301 dni
Posty: 298
Nick w MP: sebik2303

Piwa: 899

Respekt: 55,3

Kronix.Cooder, ok zaraz wytestuje, a jak dodam do starej bazy to nie b?dzie wadzi?o ? Bo nie chcia? bym aut oddawac :) a z 80 pozycji mam, i si? to nadpiesze ?

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-01-20, 11:02


Kronix.Cooder







Wiek: 36
Na forum: 5040 dni
Posty: 26

Piwa: 15

Respekt: 90

nawet jak dodasz r?cznie te kolumn? to stare pojazdy bed? mia?y warto?? `ea` 0 (ustawion? domy?ln?)
a ta warto?? powinna by? inna dla ka?dego przy uruchomieniu wczyta i wyjd? krzaki, czyli wszystkie stare pojazdy b?d? mia?y jednolity "engineAcceleration"

najlepiej na szybko napisa? konwerter
wczytanie pojazd?w z bazy '1'
zapis pojazd?w do bazy '2' razem z now? warto?ci? pobran? dla ka?dego pojazdu
?mia?o mo?na wykorzysta? z twojego skryptu wczytywanie i zapis.
dasz rade? czy nie bardzo?

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-01-20, 11:26


sebik2303

Mapper :)






Wiek: 25
Na forum: 4301 dni
Posty: 298
Nick w MP: sebik2303

Piwa: 899

Respekt: 55,3

Kronix.Cooder, Mam now? baze danych i nadal si? nie zapisuje :C
Tu DB

Tutaj Baza, powinno by? 17 a jest nadal 7.2


[ Dodano: 2016-01-20, 11:27 ]
sebik2303, co do tego zapisu i wczytywania to chyba nie za bardzo :C

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-01-20, 12:23


Kronix.Cooder







Wiek: 36
Na forum: 5040 dni
Posty: 26

Piwa: 15

Respekt: 90

Poddaje sie. Nie wiem co robisz ?le, testowa?em u siebie smiga a? mi?o.

pr?bowa?em celowo wywo?a? taki b??d, nie uda?o mi si?.
Preferujesz pomoc zdaln?? je?li tak pode?lij na pw

Postaw piwo autorowi tego posta
 

 
Tagi: zapis :: tuningu
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






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