Jump to content

3 questions about fuel usage in cars


Recommended Posts

Hey I got 3 questions for you guys:

1.My cars have 100 fuel when first spawned. At the moment, there is preset fuel decreases depending on your speed. I was wondering if there is some form of math equation for fuel reduction based on the speed, so I won't have to write like 30 IF statements in my code.

2.How do I create a little red bar that slowly goes down to reflect the amount of fuel(between 0 and 100) that the car has(only visible to the occupants of the vehicle, or possibly the driver) --not asking for code, just some hints / tips / functions on how to do this myself, I don't like asking people to make my scripts for me, its not right ;){solved}

3.If the above question is answered, how can I create rounded text in the center of the bar?

I know the serverside code for adding text, but got no idea on how to round it, so it isn't like "89.44356454", but rather just "89".{solved}

So, for any people who can help me, I thank you :)

Edited by Guest
Link to comment

1. well figure out a formula yourself. take your consumption on mimimum speed and maximum speed, and devise a formula that would produce these value on similar speeds?

though maybe someone got better suggestions.

2. dxDrawImage (if you want some fancy bar) that you can stretch or simple dxDrawRectangle. "going down" can be made by setting the image/rectangle height/Y according to fuel amount.

you can also try guiCreateStaticImage and resizing that (though i prefer dx drawin for dynamic stuff).

as for showing it vehicle occupant, add onClientVehicleEnter(Exit) event handler that will show/hide the bar to the player that entered.

3. use dxDrawText with center X alignment (or guiCreateLabel if you're going with gui). as for rounding you can use Lua's math.ceil(), math.floor(), math.modf() for that.

Link to comment
  • Moderators

Personnaly I use a squarre function ( i.e: speed^2 ) but then you have to reduce it with / ( ie : (speed^2)/60 ) and change 60 and make test until you think that's a good fuel decrease. ( My system use the consomation of the vehicules ie: 3 L/100Km 8) )

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