P.Wiśnia
Programista LUA
Wiek: 24 Na forum: 4045 dni Posty: 568
Nick w MP: P.Wiśnia
Piwa : 376
ale one same si? tepaj? i /zapiszpojazdy niedzia?a
a i jakim programem otworzy? pojazdy.db
[ Dodano : 2016-02-16, 13:33 ]
skrypt na zapisz
Kod: --[[
Ten plik zawiera:
* tworzenie aut przy uruchomieniu skryptu
* laczenie sie z baza SQL Lite
* zapis danych aut co 15 min i przy wylaczeniu skryptu
* komende dla administratora sluzaca zapisowi aut
* funkcje blokujaca wejscie do auta jesli nie jestesmy jego wlascicieleme
--]]
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, 900000, 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
[ Dodano : 2016-02-16, 13:33 ]
skrypt na zapisz
Kod: --[[
Ten plik zawiera:
* tworzenie aut przy uruchomieniu skryptu
* laczenie sie z baza SQL Lite
* zapis danych aut co 15 min i przy wylaczeniu skryptu
* komende dla administratora sluzaca zapisowi aut
* funkcje blokujaca wejscie do auta jesli nie jestesmy jego wlascicieleme
--]]
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, 900000, 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
[ Dodano : 2016-02-16, 13:46 ]
dodaje sc http://scr.hu/9vti/sl38n