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

Wysłany: 2019-02-24, 12:34


Mateusesek

Szkrypterr






Wiek: 25
Na forum: 2668 dni
Posty: 43
Nick w MP: Kek



Respekt: 50

Witam czy w tym skrypcie na zapis pojazdow w MySQL da si? zrobi? dw?ch w?ascicieli do jednego auta [wszystko podlaczone i zapisuja sie w bazie]



Kod:

--@author:piotr172

local SQL_LOGIN="" --login do bazy danych
local SQL_PASSWD="" --has?o do bazy danych
local SQL_DB="" --baza danych
local SQL_HOST="" --host bazy danych
local SQL_PORT=tonumber(get("port") or 3306) --port(standardowo 3306)
local root = getRootElement()

local SQL

local function connect() --??czy z baz? danych
SQL = mysql_connect(SQL_HOST, SQL_LOGIN, SQL_PASSWD, SQL_DB, SQL_PORT)
if (not SQL) then
outputServerLog("BRAK POLACZENIA Z BAZA DANYCH!")
else
mysql_query(SQL,"SET NAMES utf8")
end

end

addEventHandler("onResourceStart",getResourceRootElement(),function() --po w?aczeniu skryptu wysy?a do funkcji kt?ra ?aczy si? z baz? danych
connect()
end)

function esc(value)
return mysql_escape_string(SQL,value)
end

function pobierzTabeleWynikow(query)
local result=mysql_query(SQL,query)
if (not result) then
outputDebugString("mysql_query failed: (" .. mysql_errno(SQL) .. ") " .. mysql_error(SQL)) -- Show the reason
return nil
end
local tabela={}
for result,row in mysql_rows_assoc(result) do
table.insert(tabela,row)
end
mysql_free_result(result)
return tabela
end

function pobierzWyniki(query)
local result=mysql_query(SQL,query)
if (not result) then return nil end
row = mysql_fetch_assoc(result)
mysql_free_result(result)
return row
end


function zapytanie(query)
local result=mysql_query(SQL,query)
if (result) then mysql_free_result(result) end
return
end

function insertID()
return mysql_insert_id(SQL)
end

--pobiera pojazdy z bazy danych i wysy?a dane do funkcji tworz?cej pojazdy
function veh_init()
local pojazdy=pobierzTabeleWynikow("select id,wlasciciel,model,xyz,rot,frozen,hp,ca,cb,cc,przebieg,paliwo,upgrades,wheelstates,opis,panelstates,doorstate from auta")
for i,v in ipairs(pojazdy) do
veh_create(v)
end
end


--tworzenie pojazdu
function veh_create(v)
v.xyz=split(v.xyz,",")
v.rot=split(v.rot,",")
local veh = createVehicle(v.model, v.xyz[1], v.xyz[2], v.xyz[3]) --tworzy pojazd na kordach odczytanych z bazy
setElementRotation(veh, v.rot[1],v.rot[2], v.rot[3]) --nadaje rotacje
setVehicleColor(veh, v.ca, v.cb, v.cc) --nadaje kolor
setElementHealth(veh,v.hp) --nadaje hp
setElementData(veh, "pojazd_id", v.id) --nadaje date odpowiedzialn? za ID pojazdu
setElementData(veh, "pojazd_owner", v.wlasciciel) --nadaje date odpowiedzialn? w?asciciela pojazdu
setElementData(veh, "pojazd_paliwo", v.paliwo or 50) --nadaje date odpowiedzialn? za paliwo pojazdu
setElementData(veh, "pojazd_przebieg", v.przebieg or 0) --nadaje date odpowiedzialn? za przebieg pojazdu
if (v.opis and type(v.opis)=="string") then
setElementData(veh,"pojazd_opis", v.opis) --nadaje date odpowiedzialn? za opis pojazdu
end
setVehicleEngineState ( veh, false )
setElementFrozen(veh, tonumber(v.frozen)>0)
--ko?a
v.wheelstates=split(v.wheelstates,",")
setVehicleWheelStates(veh, unpack(v.wheelstates))
--uszkodzone czesci
if (v.panelstates~="0,0,0,0,0,0,0") then
v.panelstates=split(v.panelstates,",")
for i,v in ipairs(v.panelstates) do
setVehiclePanelState(veh,i-1, tonumber(v))
end
else
v.panelstates=split(v.panelstates,",")
end
--uszkodzone drzwi
if (v.doorstate~="0,0,0,0,0,0,0") then
v.doorstate=split(v.doorstate,",")
for i,v in ipairs(v.doorstate) do
setVehicleDoorState(veh,i-1, tonumber(v))
end
else
v.doorstate=split(v.doorstate,",")
end
--tuning
if (v.upgrades and type(v.upgrades)=="string") then
v.upgrades=split(v.upgrades,",")
for i,v in ipairs(v.upgrades) do
addVehicleUpgrade(veh, tonumber(v))
end
end
end


--sprawda czy gracz jest w?ascicielem pojazdu
function StartEnter(client, seat, jacked)
if seat == 0 then
local pojazd_owner = getElementData(source, "pojazd_owner")
local name = getPlayerName(client)
if not (name == pojazd_owner) then
outputChatBox("Nie masz kluczyk?w do tego pojazdu.", client, 255, 255, 255, true)
cancelEvent()
end
end
end
addEventHandler ("onVehicleStartEnter", resourceRoot, StartEnter)


--zapis pojazdu
function veh_save(vehicle)
local id=getElementData(vehicle, "pojazd_id") --sprawdza id pojazdu
if id then --gdy auto posiada ID skrypt leci dalej i zapisuje pojazd
local x,y,z=getElementPosition(vehicle) --sprawdza kordy pojazdu
local rx,ry,rz=getElementRotation(vehicle) --sprawdza rotacje pojazdu
local hp=getElementHealth(vehicle) --sprawdza hp pojazdu
local wlasciciel=getElementData(vehicle,"pojazd_owner") --sprawdza date odpowiedzialn? za wlasciciela(czy nie zmieni? si? on)
local paliwo=getElementData(vehicle,"pojazd_paliwo") --sprawdza date odpowiedzialn? za paliwo
local przebieg=getElementData(vehicle,"pojazd_przebieg") or 0 --sprawdza date odpowiedzialn? za przebieg
local frozen= isElementFrozen(vehicle) and 1 or 0 --sprawdza czy pojazd jest na recznym(zamrozony)
local opis=getElementData(vehicle,"pojazd_opis") --sprawdza date odpowiedzialn? za opis
if (opis and string.len(opis)>=3) then
opis='' .. esc(opis) .. ''
else
opis=""
end

local wheelstates=table.concat({getVehicleWheelStates(vehicle)},",") --sprawdza stan k??
--sprawdza stan czesci pojazdu
local panelstates={}
for i=0,6 do
table.insert(panelstates, getVehiclePanelState(vehicle,i))
end
panelstates=table.concat(panelstates,",")
--sprawdza stan drzwi pojazdu
local doorstate={}
for i=0,5 do
table.insert(doorstate, getVehicleDoorState(vehicle,i))
end
doorstate=table.concat(doorstate,",")
local ca,cb,cc = getVehicleColor(vehicle,true) --sprawdza kolor pojazdu
--sprawdza tuning pojazdu
local vehUpgrades=getVehicleUpgrades(vehicle)
if not vehUpgrades then vehUpgrades={} end
local upgrades=esc(table.concat(vehUpgrades,","))
-- zapisuje pojazd do bazy danych
local query=string.format("UPDATE auta SET przebieg='%.2f',wlasciciel='%s',upgrades='%s',xyz='%.2f,%.2f,%.2f',rot='%.2f,%.2f,%.2f',hp='%d',frozen='%d',ca='%d',cb='%d',cc='%d',wheelstates='%s',panelstates='%s',doorstate='%s',opis='%s',paliwo='%.3f' WHERE id='%d'",
przebieg,wlasciciel,upgrades,x,y,z,rx,ry,rz,hp, frozen,
ca,cb,cc,esc(wheelstates), esc(panelstates),esc(doorstate), opis,paliwo,id)
zapytanie(query)
end
end

--pobiera wszytskie pojazdy z mapy i wysy?a ich dane do funkcji zapisujacej pojazdy
function veh_saveall()
local pojazdy=getElementsByType("vehicle",resourceRoot)
for i,v in ipairs(pojazdy) do
veh_save(v)
end
end
setTimer(veh_saveall, 5*60*1000, 0) --timer zapisuje co 5 minut wszystkie pojazdy z mapy(5=co ile minut zapis)

--komenda do zapisu pojazdu
function zapiszveh(plr)
local acc = getAccountName (getPlayerAccount(plr))
if isObjectInACLGroup ("user."..acc, aclGetGroup ("Admin")) then
veh_saveall()
outputChatBox("** Zapisano pojazdy.", plr, 255, 255, 255, true)
end
end
addCommandHandler("zapiszpojazdy", zapiszveh)

addEventHandler("onResourceStart",resourceRoot, veh_init) --po starcie skryptu tworzy pojazdy na mapie
addEventHandler("onResourceStop",resourceRoot, veh_saveall) --po zatrzymaniu skryptu tworzy pojazdy na mapie

-- zapisuje pojazd z kt?rego wyszed? gracz( nie wszytskie tylko ten jeden pojazd)
addEventHandler("onVehicleExit", resourceRoot, function(plr,seat)
if (seat==0) then
setVehicleEngineState ( source, false )
end
veh_save(source)
end)

--komenda tworzenia nowych pojazd?w do bazy danych(tworzy na mapie oraz od razu zapisuje do bazy)
function stworzveh(player, cmd, model, wlasciciel)
local acc = getAccountName (getPlayerAccount(player))
local model = tonumber(model)
if model and wlasciciel then
if isObjectInACLGroup ("user."..acc, aclGetGroup ("Admin")) then
local x, y, z = getElementPosition(player)
local rx, ry, rz = getElementRotation(player)
local veh = createVehicle(model, x, y, z)
setVehicleColor(veh, 16777215, 16777215, 16777215)
setElementPosition(player,x,y,z+2)
local id=insertID()
local query=string.format("INSERT INTO auta SET id='%d',model='%d', wlasciciel='%s',xyz='%.2f,%.2f,%.2f',rot='0,0,0',frozen='1'",
id,model,wlasciciel,x,y,z)
zapytanie(query)
setElementFrozen(veh,true)
setVehicleEngineState(veh,false)
setElementData(veh,"pojazd_id",id)
setElementData(veh,"pojazd_paliwo", 100)
setElementData(veh,"pojazd_przebieg", 0)
setElementData(veh,"pojazd_owner", wlasciciel)
setElementData(veh,"pojazd_opis", "")
end
else
outputChatBox("Wpisz /stworz [id-pojazdu] [wlasciciel]", player, 255, 255, 255, true)
end
end

addCommandHandler("stworzpojazd", stworzveh)


Prosz? o pomoc :)

Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-02-24, 13:10


Gravgor







Wiek: 22
Na forum: 3619 dni
Posty: 380
Nick w MP: 1944

Piwa: 702

Respekt: 57,8

Poka? struktur?

Podpis
Portfolio marceliborowczak.me
Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-02-24, 13:16


Mateusesek

Szkrypterr






Wiek: 25
Na forum: 2668 dni
Posty: 43
Nick w MP: Kek



Respekt: 50

Rozumiem baze danych?

[ Dodano: 2019-02-24, 13:18 ]
Je?eli baze danych to = https://imgur.com/a/c7dAk1K
Chcia?bym jeszcze do tego doda? zapis Paintjobow

Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-02-24, 13:38


Gravgor







Wiek: 22
Na forum: 3619 dni
Posty: 380
Nick w MP: 1944

Piwa: 702

Respekt: 57,8

Dodaj kolumn? w tabeli od pojazd?w drugiwlasciciel w formie text

function start(clientseatjacked)
if seat == 0 then
local pojazd_owner_dwa getElementData(source"pojazd_drugi_wlas")
local name getPlayerName(client)
if not (name == pojazd_owner_dwathen
outputChatBox("Nie masz kluczyk?w do tego pojazdu."client255255255true)
cancelEvent()
end
end
end
addEventHandler ("onVehicleStartEnter"resourceRootstart


Funkcje powy?ej dodaj, a dwie funkcje poni?ej podmie?

function stworzveh(playercmdmodelwlascicieldrugiwlasciciel)
local acc getAccountName (getPlayerAccount(player))
local model tonumber(model)
if model and wlasciciel then
if isObjectInACLGroup ("user."..accaclGetGroup ("Admin")) then
local xygetElementPosition(player)
local rxryrz getElementRotation(player)
local veh createVehicle(modelxyz)
setVehicleColor(veh167772151677721516777215)
setElementPosition(player,x,y,z+2)
local id=insertID()
local query=string.format("INSERT INTO auta SET id='%d',model='%d', wlasciciel='%s',xyz='%.2f,%.2f,%.2f',rot='0,0,0',frozen='1'",
id,model,wlasciciel,x,y,z)
zapytanie(query)
setElementFrozen(veh,true)
setVehicleEngineState(veh,false)
setElementData(veh,"pojazd_id",id)
setElementData(veh,"pojazd_paliwo"100)
setElementData(veh,"pojazd_przebieg"0)
setElementData(veh,"pojazd_owner"wlasciciel)
setElementData(veh,"pojazd_opis""")
setElementData(veh"pojazd_drugi_wlas"drugiwlasciciel)
end
else
outputChatBox("Wpisz /stworz [id-pojazdu] [wlasciciel] [drugiwlasciciel]"player255255255true)
end
end

addCommandHandler("stworzpojazd"stworzveh)



function veh_save(vehicle)
local id=getElementData(vehicle"pojazd_id") --sprawdza id pojazdu
if id then --gdy auto posiada ID skrypt leci dalej i zapisuje pojazd
local x,y,z=getElementPosition(vehicle) --sprawdza kordy pojazdu
local rx,ry,rz=getElementRotation(vehicle) --sprawdza rotacje pojazdu
local hp=getElementHealth(vehicle) --sprawdza hp pojazdu
local wlasciciel=getElementData(vehicle,"pojazd_owner") --sprawdza date odpowiedzialnza wlasciciela(czy nie zmienision)
local paliwo=getElementData(vehicle,"pojazd_paliwo") --sprawdza date odpowiedzialnza paliwo
local przebieg=getElementData(vehicle,"pojazd_przebieg") or --sprawdza date odpowiedzialnza przebieg
local frozenisElementFrozen(vehicle) and or --sprawdza czy pojazd jest na recznym(zamrozony)
local opis=getElementData(vehicle,"pojazd_opis") --sprawdza date odpowiedzialnza opis
local drugiwlasciciel=getElementData(vehicle"pojazd_drugi_wlas")
if (opis and string.len(opis)>=3then
opis='' .. esc(opis) .. ''
else
opis=""
end

local wheelstates=table.concat({getVehicleWheelStates(vehicle)},",") --sprawdza stan k??
--sprawdza stan czesci pojazdu
local panelstates={}
for i=0,do
table.insert(panelstatesgetVehiclePanelState(vehicle,i))
end
panelstates=table.concat(panelstates,",")
--sprawdza stan drzwi pojazdu
local doorstate={}
for i=0,do
table.insert(doorstategetVehicleDoorState(vehicle,i))
end
doorstate=table.concat(doorstate,",")
local ca,cb,cc getVehicleColor(vehicle,true) --sprawdza kolor pojazdu
--sprawdza tuning pojazdu
local vehUpgrades=getVehicleUpgrades(vehicle)
if not vehUpgrades then vehUpgrades={} end
local upgrades=esc(table.concat(vehUpgrades,","))
-- zapisuje pojazd do bazy danych
local query=string.format("UPDATE auta SET przebieg='%.2f',wlasciciel='%s',upgrades='%s',xyz='%.2f,%.2f,%.2f',rot='%.2f,%.2f,%.2f',hp='%d',frozen='%d',ca='%d',cb='%d',cc='%d',wheelstates='%s',panelstates='%s',doorstate='%s',opis='%s',paliwo='%.3f', drugiwlasciciel=?, WHERE id='%d'",
przebieg,wlasciciel,upgrades,x,y,z,rx,ry,rz,hpfrozen,
ca,cb,cc,esc(wheelstates), esc(panelstates),esc(doorstate), opis,paliwo,drugiwlasciciel,id)
zapytanie(query)
end
end 


Podpis
Portfolio marceliborowczak.me
Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-02-24, 13:56


Mateusesek

Szkrypterr






Wiek: 25
Na forum: 2668 dni
Posty: 43
Nick w MP: Kek



Respekt: 50

A m?g?by? mi to podmieni? pod ca?y skrypt? bo nie wiem jak to popodmienia?...

[ Dodano: 2019-02-24, 14:17 ]
I jak doda? t? kolumne ?

[ Dodano: 2019-02-24, 14:24 ]
Jak pomo?esz stawiam piwko i respekt :)

Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-02-24, 14:39


Gravgor







Wiek: 22
Na forum: 3619 dni
Posty: 380
Nick w MP: 1944

Piwa: 702

Respekt: 57,8

Po prostu podmie? funkcj?, nie dodam Ci kolumny bo nie mam jak.

Podpis
Portfolio marceliborowczak.me
Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-02-24, 14:42


Mateusesek

Szkrypterr






Wiek: 25
Na forum: 2668 dni
Posty: 43
Nick w MP: Kek



Respekt: 50

A wytlumaczysz mi to jak?

[ Dodano: 2019-02-24, 14:45 ]
Z t? kolumn?

Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-02-24, 14:48


Gravgor







Wiek: 22
Na forum: 3619 dni
Posty: 380
Nick w MP: 1944

Piwa: 702

Respekt: 57,8

Tworzenie kolumny?

Klikasz na stworzon? tabel?, rozwijasz i klikasz Nowy. Nast?pnie w nazwie wpisujesz drugiwlasciciel, typ zmieniasz na text i klikasz zapisz.

Podpis
Portfolio marceliborowczak.me
Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-02-24, 15:05


Mateusesek

Szkrypterr






Wiek: 25
Na forum: 2668 dni
Posty: 43
Nick w MP: Kek



Respekt: 50

https://imgur.com/a/s2t7OdS

[ Dodano: 2019-02-24, 15:06 ]
Nie wiem co jest

Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-02-24, 15:09


Gravgor







Wiek: 22
Na forum: 3619 dni
Posty: 380
Nick w MP: 1944

Piwa: 702

Respekt: 57,8

11 dodaj do d?ugo?ci

Podpis
Portfolio marceliborowczak.me
Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-02-24, 15:12


Mateusesek

Szkrypterr






Wiek: 25
Na forum: 2668 dni
Posty: 43
Nick w MP: Kek



Respekt: 50

dalej co? takiego https://imgur.com/a/4v5yseP

Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-02-24, 15:17


Gravgor







Wiek: 22
Na forum: 3619 dni
Posty: 380
Nick w MP: 1944

Piwa: 702

Respekt: 57,8

Wy?lij mi tabele tutaj, do pobrania.

Podpis
Portfolio marceliborowczak.me
Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-02-24, 15:20


Mateusesek

Szkrypterr






Wiek: 25
Na forum: 2668 dni
Posty: 43
Nick w MP: Kek



Respekt: 50

https://www.mediafire.com...y/auta.sql/file

[ Dodano: 2019-02-24, 15:22 ]
Mam pytanie czy dobrze to podmieni?em ? Masz TeamViewera? zrobi?by? mi to bo nie ogarniam

Kod:

--@author:piotr172

local SQL_LOGIN="" --login do bazy danych
local SQL_PASSWD="" --has?o do bazy danych
local SQL_DB="" --baza danych
local SQL_HOST="" --host bazy danych
local SQL_PORT=tonumber(get("port") or 3306) --port(standardowo 3306)
local root = getRootElement()

local SQL

local function connect() --??czy z baz? danych
SQL = mysql_connect(SQL_HOST, SQL_LOGIN, SQL_PASSWD, SQL_DB, SQL_PORT)
if (not SQL) then
outputServerLog("BRAK POLACZENIA Z BAZA DANYCH!")
else
mysql_query(SQL,"SET NAMES utf8")
end

end

addEventHandler("onResourceStart",getResourceRootElement(),function() --po w?aczeniu skryptu wysy?a do funkcji kt?ra ?aczy si? z baz? danych
connect()
end)

function esc(value)
return mysql_escape_string(SQL,value)
end

function pobierzTabeleWynikow(query)
local result=mysql_query(SQL,query)
if (not result) then
outputDebugString("mysql_query failed: (" .. mysql_errno(SQL) .. ") " .. mysql_error(SQL)) -- Show the reason
return nil
end
local tabela={}
for result,row in mysql_rows_assoc(result) do
table.insert(tabela,row)
end
mysql_free_result(result)
return tabela
end

function pobierzWyniki(query)
local result=mysql_query(SQL,query)
if (not result) then return nil end
row = mysql_fetch_assoc(result)
mysql_free_result(result)
return row
end


function start(client, seat, jacked)
if seat == 0 then
local pojazd_owner_dwa = getElementData(source, "pojazd_drugi_wlas")
local name = getPlayerName(client)
if not (name == pojazd_owner_dwa) then
outputChatBox("Nie masz kluczyk?w do tego pojazdu.", client, 255, 255, 255, true)
cancelEvent()
end
end
end
addEventHandler ("onVehicleStartEnter", resourceRoot, start)


function zapytanie(query)
local result=mysql_query(SQL,query)
if (result) then mysql_free_result(result) end
return
end

function insertID()
return mysql_insert_id(SQL)
end

--pobiera pojazdy z bazy danych i wysy?a dane do funkcji tworz?cej pojazdy
function veh_init()
local pojazdy=pobierzTabeleWynikow("select id,wlasciciel,model,xyz,rot,frozen,hp,ca,cb,cc,przebieg,paliwo,upgrades,wheelstates,opis,panelstates,doorstate from auta")
for i,v in ipairs(pojazdy) do
veh_create(v)
end
end


--tworzenie pojazdu
function stworzveh(player, cmd, model, wlasciciel, drugiwlasciciel)
local acc = getAccountName (getPlayerAccount(player))
local model = tonumber(model)
if model and wlasciciel then
if isObjectInACLGroup ("user."..acc, aclGetGroup ("Admin")) then
local x, y, z = getElementPosition(player)
local rx, ry, rz = getElementRotation(player)
local veh = createVehicle(model, x, y, z)
setVehicleColor(veh, 16777215, 16777215, 16777215)
setElementPosition(player,x,y,z+2)
local id=insertID()
local query=string.format("INSERT INTO auta SET id='%d',model='%d', wlasciciel='%s',xyz='%.2f,%.2f,%.2f',rot='0,0,0',frozen='1'",
id,model,wlasciciel,x,y,z)
zapytanie(query)
setElementFrozen(veh,true)
setVehicleEngineState(veh,false)
setElementData(veh,"pojazd_id",id)
setElementData(veh,"pojazd_paliwo", 100)
setElementData(veh,"pojazd_przebieg", 0)
setElementData(veh,"pojazd_owner", wlasciciel)
setElementData(veh,"pojazd_opis", "")
setElementData(veh, "pojazd_drugi_wlas", drugiwlasciciel)
end
else
outputChatBox("Wpisz /stworz [id-pojazdu] [wlasciciel] [drugiwlasciciel]", player, 255, 255, 255, true)
end
end

addCommandHandler("stworzpojazd", stworzveh)
setVehicleEngineState ( veh, false )
setElementFrozen(veh, tonumber(v.frozen)>0)
--ko?a
v.wheelstates=split(v.wheelstates,",")
setVehicleWheelStates(veh, unpack(v.wheelstates))
--uszkodzone czesci
if (v.panelstates~="0,0,0,0,0,0,0") then
v.panelstates=split(v.panelstates,",")
for i,v in ipairs(v.panelstates) do
setVehiclePanelState(veh,i-1, tonumber(v))
end
else
v.panelstates=split(v.panelstates,",")
end
--uszkodzone drzwi
if (v.doorstate~="0,0,0,0,0,0,0") then
v.doorstate=split(v.doorstate,",")
for i,v in ipairs(v.doorstate) do
setVehicleDoorState(veh,i-1, tonumber(v))
end
else
v.doorstate=split(v.doorstate,",")
end
--tuning
if (v.upgrades and type(v.upgrades)=="string") then
v.upgrades=split(v.upgrades,",")
for i,v in ipairs(v.upgrades) do
addVehicleUpgrade(veh, tonumber(v))
end
end
end


--sprawda czy gracz jest w?ascicielem pojazdu
function StartEnter(client, seat, jacked)
if seat == 0 then
local pojazd_owner = getElementData(source, "pojazd_owner")
local name = getPlayerName(client)
if not (name == pojazd_owner) then
outputChatBox("Nie masz kluczyk?w do tego pojazdu.", client, 255, 255, 255, true)
cancelEvent()
end
end
end
addEventHandler ("onVehicleStartEnter", resourceRoot, StartEnter)


--zapis pojazdu
function veh_save(vehicle)
local id=getElementData(vehicle, "pojazd_id") --sprawdza id pojazdu
if id then --gdy auto posiada ID skrypt leci dalej i zapisuje pojazd
local x,y,z=getElementPosition(vehicle) --sprawdza kordy pojazdu
local rx,ry,rz=getElementRotation(vehicle) --sprawdza rotacje pojazdu
local hp=getElementHealth(vehicle) --sprawdza hp pojazdu
local wlasciciel=getElementData(vehicle,"pojazd_owner") --sprawdza date odpowiedzialn? za wlasciciela(czy nie zmieni? si? on)
local paliwo=getElementData(vehicle,"pojazd_paliwo") --sprawdza date odpowiedzialn? za paliwo
local przebieg=getElementData(vehicle,"pojazd_przebieg") or 0 --sprawdza date odpowiedzialn? za przebieg
local frozen= isElementFrozen(vehicle) and 1 or 0 --sprawdza czy pojazd jest na recznym(zamrozony)
local opis=getElementData(vehicle,"pojazd_opis") --sprawdza date odpowiedzialn? za opis
local drugiwlasciciel=getElementData(vehicle, "pojazd_drugi_wlas")
if (opis and string.len(opis)>=3) then
opis='' .. esc(opis) .. ''
else
opis=""
end

local wheelstates=table.concat({getVehicleWheelStates(vehicle)},",") --sprawdza stan k??
--sprawdza stan czesci pojazdu
local panelstates={}
for i=0,6 do
table.insert(panelstates, getVehiclePanelState(vehicle,i))
end
panelstates=table.concat(panelstates,",")
--sprawdza stan drzwi pojazdu
local doorstate={}
for i=0,5 do
table.insert(doorstate, getVehicleDoorState(vehicle,i))
end
doorstate=table.concat(doorstate,",")
local ca,cb,cc = getVehicleColor(vehicle,true) --sprawdza kolor pojazdu
--sprawdza tuning pojazdu
local vehUpgrades=getVehicleUpgrades(vehicle)
if not vehUpgrades then vehUpgrades={} end
local upgrades=esc(table.concat(vehUpgrades,","))
-- zapisuje pojazd do bazy danych
local query=string.format("UPDATE auta SET przebieg='%.2f',wlasciciel='%s',upgrades='%s',xyz='%.2f,%.2f,%.2f',rot='%.2f,%.2f,%.2f',hp='%d',frozen='%d',ca='%d',cb='%d',cc='%d',wheelstates='%s',panelstates='%s',doorstate='%s',opis='%s',paliwo='%.3f', drugiwlasciciel=?, WHERE id='%d'",
przebieg,wlasciciel,upgrades,x,y,z,rx,ry,rz,hp, frozen,
ca,cb,cc,esc(wheelstates), esc(panelstates),esc(doorstate), opis,paliwo,drugiwlasciciel,id)
zapytanie(query)
end
end

--pobiera wszytskie pojazdy z mapy i wysy?a ich dane do funkcji zapisujacej pojazdy
function veh_saveall()
local pojazdy=getElementsByType("vehicle",resourceRoot)
for i,v in ipairs(pojazdy) do
veh_save(v)
end
end
setTimer(veh_saveall, 5*60*1000, 0) --timer zapisuje co 5 minut wszystkie pojazdy z mapy(5=co ile minut zapis)

--komenda do zapisu pojazdu
function zapiszveh(plr)
local acc = getAccountName (getPlayerAccount(plr))
if isObjectInACLGroup ("user."..acc, aclGetGroup ("Admin")) then
veh_saveall()
outputChatBox("** Zapisano pojazdy.", plr, 255, 255, 255, true)
end
end
addCommandHandler("zapiszpojazdy", zapiszveh)

addEventHandler("onResourceStart",resourceRoot, veh_init) --po starcie skryptu tworzy pojazdy na mapie
addEventHandler("onResourceStop",resourceRoot, veh_saveall) --po zatrzymaniu skryptu tworzy pojazdy na mapie

-- zapisuje pojazd z kt?rego wyszed? gracz( nie wszytskie tylko ten jeden pojazd)
addEventHandler("onVehicleExit", resourceRoot, function(plr,seat)
if (seat==0) then
setVehicleEngineState ( source, false )
end
veh_save(source)
end)

--komenda tworzenia nowych pojazd?w do bazy danych(tworzy na mapie oraz od razu zapisuje do bazy)
function stworzveh(player, cmd, model, wlasciciel)
local acc = getAccountName (getPlayerAccount(player))
local model = tonumber(model)
if model and wlasciciel then
if isObjectInACLGroup ("user."..acc, aclGetGroup ("Admin")) then
local x, y, z = getElementPosition(player)
local rx, ry, rz = getElementRotation(player)
local veh = createVehicle(model, x, y, z)
setVehicleColor(veh, 16777215, 16777215, 16777215)
setElementPosition(player,x,y,z+2)
local id=insertID()
local query=string.format("INSERT INTO auta SET id='%d',model='%d', wlasciciel='%s',xyz='%.2f,%.2f,%.2f',rot='0,0,0',frozen='1'",
id,model,wlasciciel,x,y,z)
zapytanie(query)
setElementFrozen(veh,true)
setVehicleEngineState(veh,false)
setElementData(veh,"pojazd_id",id)
setElementData(veh,"pojazd_paliwo", 100)
setElementData(veh,"pojazd_przebieg", 0)
setElementData(veh,"pojazd_owner", wlasciciel)
setElementData(veh,"pojazd_opis", "")
end
else
outputChatBox("Wpisz /stworz [id-pojazdu] [wlasciciel]", player, 255, 255, 255, true)
end
end

addCommandHandler("stworzpojazd", stworzveh)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-02-24, 15:36


Gravgor







Wiek: 22
Na forum: 3619 dni
Posty: 380
Nick w MP: 1944

Piwa: 702

Respekt: 57,8

Dobra podmieni? Ci to.

-@author:piotr172

local SQL_LOGIN="" --login do bazy danych
local SQL_PASSWD="" --has?do bazy danych
local SQL_DB="" --baza danych
local SQL_HOST="" --host bazy danych
local SQL_PORT=tonumber(get("port") or 3306) --port(standardowo 3306)
local root getRootElement()

local SQL

local function connect() --??czy z bazdanych
SQL mysql_connect(SQL_HOSTSQL_LOGINSQL_PASSWDSQL_DBSQL_PORT)
if (not SQLthen
outputServerLog("BRAK POLACZENIA Z BAZA DANYCH!")
else
mysql_query(SQL,"SET NAMES utf8")
end

end

addEventHandler("onResourceStart",getResourceRootElement(),function() --po w?aczeniu skryptu wysy?do funkcji kt?ra ?aczy siz bazdanych
connect()
end)

function esc(value)
return mysql_escape_string(SQL,value)
end

function pobierzTabeleWynikow(query)
local result=mysql_query(SQL,query)
if (not resultthen
outputDebugString("mysql_query failed: (" .. mysql_errno(SQL) .. ") " .. mysql_error(SQL)) -- Show the reason
return nil
end
local tabela={}
for result,row in mysql_rows_assoc(result) do
table.insert(tabela,row)
end
mysql_free_result(result)
return tabela
end

function pobierzWyniki(query)
local result=mysql_query(SQL,query)
if (not resultthen return nil end
row mysql_fetch_assoc(result)
mysql_free_result(result)
return row
end


function zapytanie(query)
local result=mysql_query(SQL,query)
if (resultthen mysql_free_result(resultend
return
end

function insertID()
return mysql_insert_id(SQL)
end

--pobiera pojazdy z bazy danych i wysy?a dane do funkcji tworz?cej pojazdy
function veh_init()
local pojazdy=pobierzTabeleWynikow("select id,wlasciciel,model,xyz,rot,frozen,hp,ca,cb,cc,przebieg,paliwo,upgrades,wheelstates,opis,panelstates,doorstate from auta")
for i,v in ipairs(pojazdy) do
veh_create(v)
end
end


function start(clientseatjacked)
if seat == 0 then
local pojazd_owner_dwa getElementData(source"pojazd_drugi_wlas")
local name getPlayerName(client)
if not (name == pojazd_owner_dwathen
outputChatBox("Nie masz kluczyk?w do tego pojazdu."client255255255true)
cancelEvent()
end
end
end
addEventHandler ("onVehicleStartEnter"resourceRootstart) 

--tworzenie pojazdu
function veh_create(v)
v.xyz=split(v.xyz,",")
v.rot=split(v.rot,",")
local veh createVehicle(v.modelv.xyz[1], v.xyz[2], v.xyz[3]) --tworzy pojazd na kordach odczytanych z bazy
setElementRotation(vehv.rot[1],v.rot[2], v.rot[3]) --nadaje rotacje
setVehicleColor(vehv.cav.cbv.cc) --nadaje kolor
setElementHealth(veh,v.hp) --nadaje hp
setElementData(veh"pojazd_id"v.id) --nadaje date odpowiedzialnza ID pojazdu
setElementData(veh"pojazd_owner"v.wlasciciel) --nadaje date odpowiedzialnw?asciciela pojazdu
setElementData(veh"pojazd_paliwo"v.paliwo or 50) --nadaje date odpowiedzialnza paliwo pojazdu
setElementData(veh"pojazd_przebieg"v.przebieg or 0) --nadaje date odpowiedzialnza przebieg pojazdu
setElementData(veh"pojazd_drugi_wlas"v.drugiwlasciciel)
if (v.opis and type(v.opis)=="string"then
setElementData(veh,"pojazd_opis"v.opis) --nadaje date odpowiedzialnza opis pojazdu
end
setVehicleEngineState vehfalse )
setElementFrozen(vehtonumber(v.frozen)>0)
--ko?a
v.wheelstates=split(v.wheelstates,",")
setVehicleWheelStates(vehunpack(v.wheelstates))
--uszkodzone czesci
if (v.panelstates~="0,0,0,0,0,0,0"then
v.panelstates=split(v.panelstates,",")
for i,v in ipairs(v.panelstates) do
setVehiclePanelState(veh,i-1tonumber(v))
end
else
v.panelstates=split(v.panelstates,",")
end
--uszkodzone drzwi
if (v.doorstate~="0,0,0,0,0,0,0"then
v.doorstate=split(v.doorstate,",")
for i,v in ipairs(v.doorstate) do
setVehicleDoorState(veh,i-1tonumber(v))
end
else
v.doorstate=split(v.doorstate,",")
end
--tuning
if (v.upgrades and type(v.upgrades)=="string"then
v.upgrades=split(v.upgrades,",")
for i,v in ipairs(v.upgrades) do
addVehicleUpgrade(vehtonumber(v))
end
end
end


--sprawda czy gracz jest w?ascicielem pojazdu
function StartEnter(clientseatjacked)
if seat == 0 then
local pojazd_owner getElementData(source"pojazd_owner")
local name getPlayerName(client)
if not (name == pojazd_ownerthen
outputChatBox("Nie masz kluczyk?w do tego pojazdu."client255255255true)
cancelEvent()
end
end
end
addEventHandler ("onVehicleStartEnter"resourceRootStartEnter)


--zapis pojazdu
function veh_save(vehicle)
local id=getElementData(vehicle"pojazd_id") --sprawdza id pojazdu
if id then --gdy auto posiada ID skrypt leci dalej i zapisuje pojazd
local x,y,z=getElementPosition(vehicle) --sprawdza kordy pojazdu
local rx,ry,rz=getElementRotation(vehicle) --sprawdza rotacje pojazdu
local hp=getElementHealth(vehicle) --sprawdza hp pojazdu
local wlasciciel=getElementData(vehicle,"pojazd_owner") --sprawdza date odpowiedzialnza wlasciciela(czy nie zmienision)
local paliwo=getElementData(vehicle,"pojazd_paliwo") --sprawdza date odpowiedzialnza paliwo
local przebieg=getElementData(vehicle,"pojazd_przebieg") or --sprawdza date odpowiedzialnza przebieg
local frozenisElementFrozen(vehicle) and or --sprawdza czy pojazd jest na recznym(zamrozony)
local opis=getElementData(vehicle,"pojazd_opis") --sprawdza date odpowiedzialnza opis
local drugiwlasciciel=getElementData(vehicle"pojazd_drugi_wlas")
if (opis and string.len(opis)>=3then
opis='' .. esc(opis) .. ''
else
opis=""
end

local wheelstates=table.concat({getVehicleWheelStates(vehicle)},",") --sprawdza stan k??
--sprawdza stan czesci pojazdu
local panelstates={}
for i=0,do
table.insert(panelstatesgetVehiclePanelState(vehicle,i))
end
panelstates=table.concat(panelstates,",")
--sprawdza stan drzwi pojazdu
local doorstate={}
for i=0,do
table.insert(doorstategetVehicleDoorState(vehicle,i))
end
doorstate=table.concat(doorstate,",")
local ca,cb,cc getVehicleColor(vehicle,true) --sprawdza kolor pojazdu
--sprawdza tuning pojazdu
local vehUpgrades=getVehicleUpgrades(vehicle)
if not vehUpgrades then vehUpgrades={} end
local upgrades=esc(table.concat(vehUpgrades,","))
-- zapisuje pojazd do bazy danych
local query=string.format("UPDATE auta SET przebieg='%.2f',wlasciciel='%s',upgrades='%s',xyz='%.2f,%.2f,%.2f',rot='%.2f,%.2f,%.2f',hp='%d',frozen='%d',ca='%d',cb='%d',cc='%d',wheelstates='%s',panelstates='%s',doorstate='%s',opis='%s',paliwo='%.3f', drugiwlasciciel=?, WHERE id='%d'",
przebieg,wlasciciel,upgrades,x,y,z,rx,ry,rz,hpfrozen,
ca,cb,cc,esc(wheelstates), esc(panelstates),esc(doorstate), opis,paliwo,drugiwlasciciel,id)
zapytanie(query)
end
end 

--pobiera wszytskie pojazdy z mapy i wysy?a ich dane do funkcji zapisujacej pojazdy
function veh_saveall()
local pojazdy=getElementsByType("vehicle",resourceRoot)
for i,v in ipairs(pojazdy) do
veh_save(v)
end
end
setTimer(veh_saveall5*60*10000) --timer zapisuje co 5 minut wszystkie pojazdy z mapy(5=co ile minut zapis)

--komenda do zapisu pojazdu
function zapiszveh(plr)
local acc getAccountName (getPlayerAccount(plr))
if isObjectInACLGroup ("user."..accaclGetGroup ("Admin")) then
veh_saveall()
outputChatBox("** Zapisano pojazdy."plr255255255true)
end
end
addCommandHandler("zapiszpojazdy"zapiszveh)

addEventHandler("onResourceStart",resourceRootveh_init) --po starcie skryptu tworzy pojazdy na mapie
addEventHandler("onResourceStop",resourceRootveh_saveall) --po zatrzymaniu skryptu tworzy pojazdy na mapie

-- zapisuje pojazd z kt?rego wyszedgracznie wszytskie tylko ten jeden pojazd)
addEventHandler("onVehicleExit"resourceRoot, function(plr,seat)
if (seat==0then
setVehicleEngineState sourcefalse )
end
veh_save(source)
end)

--komenda tworzenia nowych pojazd?do bazy danych(tworzy na mapie oraz od razu zapisuje do bazy)
function stworzveh(playercmdmodelwlascicieldrugiwlasciciel)
local acc getAccountName (getPlayerAccount(player))
local model tonumber(model)
if model and wlasciciel then
if isObjectInACLGroup ("user."..accaclGetGroup ("Admin")) then
local xygetElementPosition(player)
local rxryrz getElementRotation(player)
local veh createVehicle(modelxyz)
setVehicleColor(veh167772151677721516777215)
setElementPosition(player,x,y,z+2)
local id=insertID()
local query=string.format("INSERT INTO auta SET id='%d',model='%d', wlasciciel='%s',xyz='%.2f,%.2f,%.2f',rot='0,0,0',frozen='1'",
id,model,wlasciciel,x,y,z)
zapytanie(query)
setElementFrozen(veh,true)
setVehicleEngineState(veh,false)
setElementData(veh,"pojazd_id",id)
setElementData(veh,"pojazd_paliwo"100)
setElementData(veh,"pojazd_przebieg"0)
setElementData(veh,"pojazd_owner"wlasciciel)
setElementData(veh,"pojazd_opis""")
setElementData(veh"pojazd_drugi_wlas"drugiwlasciciel)
end
else
outputChatBox("Wpisz /stworz [id-pojazdu] [wlasciciel] [drugiwlasciciel]"player255255255true)
end
end

addCommandHandler("stworzpojazd"stworzveh)



https://www43.zippyshare.com/v/YpGPRmiq/file.html

Przed wgraniem bazy, usu? poprzedni? kolumn?

Podpis
Portfolio marceliborowczak.me
Postaw piwo autorowi tego posta
 

 
Wysłany: 2019-02-24, 15:44


Mateusesek

Szkrypterr






Wiek: 25
Na forum: 2668 dni
Posty: 43
Nick w MP: Kek



Respekt: 50

Og?lnie to wszystko spoko piwko postawie rp te? ale - https://imgur.com/a/fovZNle
przy wgrywaniu na baze

Postaw piwo autorowi tego posta
 

 
Tagi: skrypt :: zapis :: pojazdow :: mysql
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