Jump to content

dxDrawRectangle question


TrickyTommy

Recommended Posts

Hi. I want to make a rectangle, that displays the whole amount of ammunition you have, but if i have more ammo, than the rectangle's width, it will stick out from it's border. Here, take  a look:

FjgE1al.png

I want it to be within it's black border. As you can see, it is sticking out.

Code:

 

local MaxClipAmmo = getWeaponProperty (tonumber(getPedWeapon(localPlayer)), "std", "maximum_clip_ammo")
local AmmoInClip = getPedAmmoInClip(localPlayer)
local AllAmmo = getPedTotalAmmo (localPlayer)

local FullAmmoBar = dxDrawRectangle (1701/x*jx, 65/y*jy, AllAmmo/x*jx, 8/y*jy, tocolor(227, 160, 93, 255))

x is my resolution = 1920, 1080
and jx is player's resolutiion.
so the rectangles will be the same on each monitor.

Link to comment
local MaxClipAmmo = getWeaponProperty (tonumber(getPedWeapon(localPlayer)), "std", "maximum_clip_ammo")
local AmmoInClip = getPedAmmoInClip(localPlayer)
local AllAmmo = getPedTotalAmmo (localPlayer)
local maxAmmo = 300

local FullAmmoBar = dxDrawRectangle (1701/x*jx, 65/y*jy, math.min(AllAmmo, maxAmmo)/x*jx, 8/y*jy, tocolor(227, 160, 93, 255))

 

Edited by TrickyTommy
Link to comment
  • Moderators

Try this.

local maxAmmo = 1000

dxDrawRectangle (1701/x*jx, 65/y*jy, (math.min(AllAmmo, maxAmmo) / maxAmmo * 100)/x*jx, 8/y*jy, tocolor(227, 160, 93, 255))
-- this is useless unless you know what you are doing: local FullAmmoBar = 

 

The bar length is based on the value 100? Else you have to change the value 100 to the correct value.

 

Link to comment
  • Moderators

Because you have to adjust the max value for that.

 

You could try something like this:

local maxAmmoTable = {}

-- function
-- ...
local weapon = getPedWeapon(localPlayer)

local maxAmmo = maxAmmoTable[weapon] or 1


if AllAmmo > maxAmmo then
	maxAmmoTable[weapon] = AllAmmo
end

-- ...
-- end

-- reset
addEventHandler("onClientPlayerWasted", localPlayer,
function ()
	maxAmmoTable = {}
end)

 

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