DriFtyZ Posted June 3, 2017 Share Posted June 3, 2017 (edited) 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 June 3, 2017 by DriFtyZ Link to comment
Moderators IIYAMA Posted June 3, 2017 Moderators Share Posted June 3, 2017 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
DriFtyZ Posted June 3, 2017 Author Share Posted June 3, 2017 if i don't subtract the loss it just writes a "1000" number in database no matter how many damage been done to the vehicle Link to comment
Moderators IIYAMA Posted June 3, 2017 Moderators Share Posted June 3, 2017 First start with debug the variable: ? iprint("vehHealth: ", vehHealth) If this is oke, then show me how you create your table. Link to comment
DriFtyZ Posted June 3, 2017 Author Share Posted June 3, 2017 if the vehicle health goes below 300 it caughts in fire, how to calculate the health in just integers 1-100 cuz i want to show it later on a gui Link to comment
pa3ck Posted June 4, 2017 Share Posted June 4, 2017 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
DriFtyZ Posted June 4, 2017 Author Share Posted June 4, 2017 i was thinking something about leaving the vehicle or despawing but i was to focused on how to make the health show correct first and then i forgot it, thank you for reminding me this Link to comment
keymetaphore Posted June 4, 2017 Share Posted June 4, 2017 For me, it saves all the vehicles on my DB (including their health), when resource stops. 1 Link to comment
Hale Posted June 4, 2017 Share Posted June 4, 2017 2 hours ago, Gourmet. said: For me, it saves all the vehicles on my DB (including their health), when resource stops. This guy has the right idea, best way for good performance. Link to comment
DriFtyZ Posted June 4, 2017 Author Share Posted June 4, 2017 agreed, but if server is running for long time and a crash happens then the database would be looong behind i think Link to comment
keymetaphore Posted June 4, 2017 Share Posted June 4, 2017 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. 1 Link to comment
DriFtyZ Posted June 4, 2017 Author Share Posted June 4, 2017 crashes can always happen for whatever reason, anyway Link to comment
keymetaphore Posted June 4, 2017 Share Posted June 4, 2017 1 minute ago, DriFtyZ said: crashes can always happen for whatever reason, anyway Is the problem solved? 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