Jump to content

[Help]Making a Weapon Ammo DX text


Xierra

Recommended Posts

Hi guys!

As I told you, I just made the Health & Armor bar. Thanks to 50p and Doomed_space_marine, who helped me a lot.

Now I wanted to make ammo DX text.

I tried some effort, but it failed. It said bad arguments repeatedly.

Script (client):

-- Direct X Drawings
function DXdraw()
	health = getElementHealth( getLocalPlayer() )
	lineLength1 = 114 * ( health / 100 )
 
	armor = getPedArmor( getLocalPlayer() )
	lineLength2 = 114 * ( armor / 100 )
 
	ammoinclip = getPedAmmoInClip (getLocalPlayer())
	totalammo = getPedTotalAmmo (getLocalPlayer())
	showammo1=ammoinclip
	showammo2=totalammo
 
 
dxDrawText("",646.0,731.0,694.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","right","top",false,false,false) --Ammo (for shotgun, grenades, etc)
dxDrawRectangle(818.0,725.0,lineLength2,14.0,tocolor(200,200,200,200),true)
dxDrawRectangle(818.0,745.0,114.0,14.0,tocolor(50,0,0,150),false)
dxDrawText(showammo2,684.0,731.0,732.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false) -- Total Ammo
dxDrawText("|",665.0,731.0,677.0,762.0,tocolor(255,200,0,200),1.0,"bankgothic","left","top",false,false,false) --Separator
dxDrawText(showammo1,611.0,731.0,659.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","right","top",false,false,false) -- Ammo in clip
dxDrawRectangle(818.0,725.0,114.0,14.0,tocolor(50,50,50,150),false)
dxDrawRectangle(818.0,745.0,lineLength1,14.0,tocolor(175,0,0,200),false)
end
addEventHandler("onClientRender",getRootElement(),DXdraw)
 
function hudChanger ()
showPlayerHudComponent ( "armour", false )    -- Hide the ammo displays for the newly joined player
showPlayerHudComponent ( "health", false )  -- Hide the weapon displays for the newly joined player
showPlayerHudComponent ( "money", false )
showPlayerHudComponent ( "clock", false )
showPlayerHudComponent ( "weapon", false )
showPlayerHudComponent ("ammo", false)
showPlayerHudComponent ( "money", false )
end
 
addCommandHandler ( "hidehud", hudChanger )
 
function hudChanger2 ()
showPlayerHudComponent ( "armour", true )    -- Hide the ammo displays for the newly joined player
showPlayerHudComponent ( "health", true )  -- Hide the weapon displays for the newly joined player
showPlayerHudComponent ( "money", true )
showPlayerHudComponent ( "clock", true )
showPlayerHudComponent ( "weapon", true )
showPlayerHudComponent ("ammo", true)
showPlayerHudComponent ( "money", true)
end
addCommandHandler ( "showhud", hudChanger2)

Link to comment

dxDrawText expects you to put string in the first parameter but you put a number. Convert the number to string:

dxDrawText( tostring( ammoinclip ), ...... )
dxDrawText( tostring( totalammo ), ...... )

Link to comment

Yes! It's working. Thanks again 50p!

One thing though, is it possible to detect reloads?

Like the GTA's ammo system. Only reduce total ammo after he reloads.

Also, for some weapons, I want it to show only total ammo. How to do that? (check the script again, on line 15, that's where it's gonna be used.)

Edited by Guest
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...