Otavio Posted January 3, 2021 Share Posted January 3, 2021 Ola, achei um script de quilometragem em um site russo, porem ele nao salva tentei fazer algo, usando outros scripts, pois eh minha primeira vez, e estou usando database pela primeira vez, vou deixar meu script aqui, pra voces me ajudarem como arrumar e toda vez que o veiculo for spawnado ou alguem entrar, ganhar o KM Rodado dele novamente! addEventHandler("onResourceStart", resourceRoot, function() db = dbConnect("sqlite", "database.db") dbExec(db, "CREATE TABLE IF NOT EXISTS VehicleKM (ID, Model, KM)") for i, player in ipairs(getElementsByType("player")) do updateVehicleInfo(player) end end) addEventHandler("onVehicleEnter", getRootElement() function() local theVehicle = getPedOccupiedVehicle(source) local id = getElementData(theVehicle, "ID") local KM = getElementData(theVehicle, "driveDistance") local Model = getElementModel(theVehicle) dbExec(db, "UPDATE VehicleList WHERE ID = ? AND Model = ? AND KM = ?", id, Model, KM) end addEventHandler("onVehicleExit", getRootElement() function() local theVehicle = getPedOccupiedVehicle(source) local id = getElementData(theVehicle, "ID") local KM = getElementData(theVehicle, "driveDistance") local Model = getElementModel(theVehicle) dbExec(db, "UPDATE VehicleList WHERE ID = ? AND Model = ? AND KM = ?", id, Model, KM) end Server-Side 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) end end addEventHandler("onClientRender", root, speedometrs) Client-Side Eu tentei fazer porem nao consegui Link to comment
Otavio Posted January 3, 2021 Author Share Posted January 3, 2021 Atualizei o meu script usando a um dos Banco de Dados explicados por Lord Henry, porem desta forma tambem nao esta salvando a quilometragem addEventHandler("onClientPlayerVehicleEnter",getRootElement(),function(veh,seat) if source == localPlayer then altx, alty, altz=getElementPosition(veh) lastTick = getTickCount() local KMRodeds = executeSQLQuery ("SELECT KMRodados FROM KMCarros WHERE IDCarro=?", id) local id = getElementData(veh, "ID") setElementData(veh, "driveDistance", KMRodeds) driveDistance = getElementData(veh, "driveDistance") end end) addEventHandler("onClientPlayerVehicleExit",getRootElement(),function(veh,seat) if source == localPlayer then driveDistance = getElementData(veh, "driveDistance") local id = getElementData(veh, "ID") executeSQLQuery ("INSERT INTO KMCarros(IDCarro TEXT, KMRodados INTEGER) VALUES(?,?,?)", id, driveDistance) executeSQLQuery ("UPDATE KMCarro SET KMRodados=? WHERE IDCarro=?", driveDistance, id) end end) Link to comment
Boechat Posted January 4, 2021 Share Posted January 4, 2021 20 hours ago, Otavio said: Atualizei o meu script usando a um dos Banco de Dados explicados por Lord Henry, porem desta forma tambem nao esta salvando a quilometragem addEventHandler("onClientPlayerVehicleEnter",getRootElement(),function(veh,seat) if source == localPlayer then altx, alty, altz=getElementPosition(veh) lastTick = getTickCount() local KMRodeds = executeSQLQuery ("SELECT KMRodados FROM KMCarros WHERE IDCarro=?", id) local id = getElementData(veh, "ID") setElementData(veh, "driveDistance", KMRodeds) driveDistance = getElementData(veh, "driveDistance") end end) addEventHandler("onClientPlayerVehicleExit",getRootElement(),function(veh,seat) if source == localPlayer then driveDistance = getElementData(veh, "driveDistance") local id = getElementData(veh, "ID") executeSQLQuery ("INSERT INTO KMCarros(IDCarro TEXT, KMRodados INTEGER) VALUES(?,?,?)", id, driveDistance) executeSQLQuery ("UPDATE KMCarro SET KMRodados=? WHERE IDCarro=?", driveDistance, id) end end) Banco de dados é server-side. 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now