Jump to content

[BUG] vehicle health to integer


DriFtyZ

Recommended Posts

Hello there, i want to make a function where when the vehicle damages it syncs its health to the sqlite db.. It works quite a bit but the numbers are a bit different in database and in game

Code Below:

addEventHandler("onVehicleDamage", getRootElement(),
function(loss)
	local vehHealth = math.floor((getElementHealth(source) / 10) - (loss / 10)) 
	local owner = getElementData(source, "Owner")
	local getAccName = getAccountName(getPlayerAccount(owner))
	local getPlate = getVehiclePlateText(source)
	local checkOwner = dbQuery(vehicleDb,"SELECT * FROM vehicles WHERE ownerName=? AND veh_plate=?", getAccName, getPlate)
	local checkOwnerResult = dbPoll(checkOwner, -1)
	if checkOwnerResult ~= 0 then
		dbExec(vehicleDb,"UPDATE vehicles SET veh_Health=? WHERE ownerName=? AND veh_plate=?", vehHealth, getAccName, getPlate)
	end
end)

the database connection works well but i don't know how to calculate exact vehicle health after loss to an integer number, any help appreciated!

Edited by DriFtyZ
Link to comment
  • Moderators

Afaik the loss has already been subtract from the vehicle health.

 

This should be enough: (There is no need for convert it to integer, since a float number is more exact)

local vehHealth = getElementHealth(source)

 

Link to comment

Are you sure you want to do that? Every time a collision happens you do a query and exec on the db? It's a very bad idea, you should think of a different way. Not sure what your gamemode is, but maybe only update the db when the driver leaves the vehicle?

Link to comment
40 minutes ago, DriFtyZ said:

agreed, but if server is running for long time and a crash happens then the database would be looong behind i think

Well, make it so crashes doesn't happen.

If they do happen though, you could add a timer too, but not for too short period.

  • Like 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...