TrickyTommy Posted October 12, 2017 Posted October 12, 2017 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: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.
Moderators IIYAMA Posted October 12, 2017 Moderators Posted October 12, 2017 (edited) local maxAmmo = 300 math.min(AllAmmo, maxAmmo)/x*jx Edited October 12, 2017 by IIYAMA
TrickyTommy Posted October 13, 2017 Author Posted October 13, 2017 still not working, it keeps sticking out.
TrickyTommy Posted October 13, 2017 Author Posted October 13, 2017 (edited) 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 October 13, 2017 by TrickyTommy
Moderators IIYAMA Posted October 13, 2017 Moderators Posted October 13, 2017 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.
TrickyTommy Posted October 13, 2017 Author Posted October 13, 2017 the bar's x length is 198. now it is not sticking out, but the bar is static, and not moving to anywhere.
Moderators IIYAMA Posted October 13, 2017 Moderators Posted October 13, 2017 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)
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