Jump to content

DATABASE COM QUILOMETRAGEM


Recommended Posts

Olá estoua qui de novo, tentei fazer a database da Quilometragem por quaisquer jeito, preciso de ajudar, a como posso fazer uma mudança que possa fazer funcionar, consegui fazer isso de lógico:

SERVER SIDE
 

function RespawnHRT(veh)
	if source == localPlayer then
		local id = getElementData(veh, "ID")
		local KMRodeds = executeSQLQuery ("SELECT KMRodados FROM KMCarros WHERE IDCarro=?", id)
		driveDistance = getElementData(veh, "driveDistance")
		setElementData(veh, "driveDistance", KMRodeds)
	end
end
addEvent("InfoKilometragem", true)
addEventHandler("InfoKilometragem", getRootElement(), RespawnHRT)


function SpawnHRT(veh)
	if source == localPlayer then
		driveDistance = getElementData(veh, "driveDistance")
		local id = getElementData(veh, "ID")
		if getElementData(veh, "driveDistance") > 0 then
			executeSQLQuery ("INSERT INTO KMCarros(IDCarro TEXT, KMRodados INTEGER) VALUES(?,?,?)", id, driveDistance)
		else
			executeSQLQuery ("UPDATE KMCarro SET KMRodados=? WHERE IDCarro=?", driveDistance, id)
	end
end
addEvent("SetarKM", true)
addEventHandler("SetarKM", getRootElement(), SpawnHRT)

CLIENT SIDE
 

local font1 = dxCreateFont("files/RobotoCondensed.ttf", 35)
local SizeX, SizeY = guiGetScreenSize()
local px,py = 1920,1080
local x,y = (SizeX/px), (SizeY/py)

function speedometrs ()
	if getElementData(getLocalPlayer(), "hud") == true then return end
    local veh = getPedOccupiedVehicle(getLocalPlayer()) 
    if not veh or getVehicleOccupant ( veh ) ~= localPlayer then return true end
    if not driveDistance then lastTick = getTickCount() driveDistance = getElementData(veh, "driveDistance") or 0 end
	local neux, neuy, neuz = getElementPosition(veh)

    dxDrawText("Quilometragem "..tostring(math.round(driveDistance),1).." км",SizeX,SizeY - 100, SizeX - 380,SizeY, tocolor(255,255,255,180), 0.5,0.5, font1,"center","center")

	if not altx or not alty or not altz then
		altx, alty, altz=getElementPosition(veh)
	end
	local driveTotal = getDistanceBetweenPoints3D(neux,neuy,neuz,altx,alty,altz)
	driveTotal = driveTotal/1000
	altx,alty,altz=neux,neuy,neuz
	driveDistance = math.round(driveDistance+driveTotal,3)
	if lastTick+5000 < getTickCount() then
		lastTick = getTickCount()
		setElementData(veh, "driveDistance", driveDistance)
		triggerServerEvent(SetarKM, veh)
	end
	
end
addEventHandler("onClientRender", root, speedometrs)
addEventHandler("SetarKM", getRootElement(), speedometrs)

function math.round(number, decimals, method)
    decimals = decimals or 0
    local factor = 10 ^ decimals
    if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
    else return tonumber(("%."..decimals.."f"):format(number)) end
end

function EnterVehicleHRT(veh,seat)
	if source == localPlayer then
		altx, alty, altz=getElementPosition(veh)
		lastTick = getTickCount()
		driveDistance = getElementData(veh, "driveDistance")
		triggerServerEvent(InfoKilometragem, veh)
	end
end
addEventHandler("onClientPlayerVehicleEnter",getRootElement(), EnterVehicleHRT) 

 

Link to comment
10 hours ago, Otavio said:

Olá estoua qui de novo, tentei fazer a database da Quilometragem por quaisquer jeito, preciso de ajudar, a como posso fazer uma mudança que possa fazer funcionar, consegui fazer isso de lógico:

SERVER SIDE
 

CLIENT SIDE
 

 

 

 

Só dei uma olhada rápida e vou deixar alguns comentários no código, veja se ajuda em algo:

function RespawnHRT(veh)
	--if source == localPlayer then --localPlayer no server-side?
		local id = getElementData(veh, "ID")
		local KMRodeds = executeSQLQuery ("SELECT KMRodados FROM KMCarros WHERE IDCarro=?", id)
		--driveDistance = getElementData(veh, "driveDistance") --Pra que está pegando o valor sendo que não irá usar e o carro só terá um driveDistance na linha de baixo?
		setElementData(veh, "driveDistance", KMRodeds)
	--end
end
addEvent("InfoKilometragem", true)
addEventHandler("InfoKilometragem", getRootElement(), RespawnHRT)


function SpawnHRT(veh)
	--if source == localPlayer then --localPlayer no server-side novamente. E também não está fechando esse if
		local id = getElementData(veh, "ID")
		if getElementData(veh, "driveDistance") > 0 then
			executeSQLQuery ("INSERT INTO KMCarros(IDCarro TEXT, KMRodados INTEGER) VALUES(?,?)", id, driveDistance) --Estava pedindo 3 parâmetros em VALUES
		else
			executeSQLQuery ("UPDATE KMCarro SET KMRodados=? WHERE IDCarro=?", driveDistance, id)
		end
end
addEvent("SetarKM", true)
addEventHandler("SetarKM", getRootElement(), SpawnHRT)

 

  • Thanks 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...