Ammo Display for other gun in Hud ?

I got an idea and I don’t know if its possible to get the ammo for the other weapons we have without to have the current gun on us ?

(i.e : Like the Old-ishh Hud of Doom 95.)


for _,v in ipairs(LocalPlayer():GetWeapons()) do
	-- draw v:Clip1() or v:Clip2()
end

Like that?

Nope sorry, the draw rounded box code like for (240, 201, 100, 135) 0, 0) …

Yes, I know how draw works, I was just showing you that you can use player.GetWeapons to get the ammo of all the weapons. You put in the code yourself.

Oops sorry wrong thread, Ok but if I want the .357 and I hold the pistol it’s possible to get the Amount of ammo the .357 in same time?

Yes

yes ok, but this is the same code ?

[lua]for k,v in pairs (LocalPlayer():GetWeapons()) do
if v:GetClass() == “weapon_357” then
– draw v:Clip1()
end
end[/lua]

thanks very usefull, and if I want to make an DrawRounded box how I can add weapon_357 in the box ?

why I got an error with this ?

[lua]draw.SimpleText("Clip: " … client:GetWeapons(GetClass() == “weapon_shotgun”:Clip1()), “ScoreboardText”, 15, 50, Color(242, 204, 51, 225), 0, 0)[/lua]

GetWeapons() dosent take any arguments so you will need a loop

[editline]09:24AM[/editline]

this will hopefull display the 357 ammo:



for k, v in pairs(LocalPlayer():GetWeapons()) do
      if v:GetClass()=="weapon_357" then
               draw.SimpleText("Clip: " .. v:Clip1(), "ScoreboardText", 15, 50, Color(242, 204, 51, 225), 0, 0)
      end
end


It’s not working :
[lua] function myhud()

for k,v in pairs (LocalPlayer():GetWeapons()) do
if v:GetClass() == “weapon_357” then
– draw v:Clip1()
end
end

local client = LocalPlayer()

if !client:Alive() then return end

//Health, Name, and ping.
draw.RoundedBox(5, 5, 5, 200, 100, Color(0, 0, 0, 60))
draw.SimpleText("HP: " ..	 	client:Health() .. "%", "ScoreboardText", 15, 10, Color(242, 204, 51, 255), 0, 0) 
draw.SimpleText("Name: " ..	 	client:Name(), "ScoreboardText", 15, 20, Color(242, 204, 51, 225), 0, 0)
draw.SimpleText("Ping: " .. 	client:Ping(), "ScoreboardText", 15, 30, Color(242, 204, 51, 225), 0, 0)
//Ammo
draw.SimpleText("Clip: " .. v:Clip1(), "ScoreboardText", 15, 50, Color(242, 204, 51, 225), 0, 0)
draw.SimpleText("Clip Extra: " .. client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()), "ScoreboardText", 15, 60, Color(242, 204, 51, 225), 0, 0)
draw.SimpleText("Clip Secondary: " .. client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType()), "ScoreboardText", 15, 70, Color(242, 204, 51, 225), 0, 0)

end

hook.Add(“HUDPaint”, “myhud”, myhud)

function DrawPlayerArmor()
if (LocalPlayer():Armor() > 0) then
draw.RoundedBox( 8, 32, 16, ScrW() - 64, 16, Color(200, 200, 200, 200));
draw.RoundedBox( 8, 34, 18, (ScrW() - 68)*(LocalPlayer():Armor() / 1000), 12, Color(0, 0, 200, 200));
end
end
hook.Add(“HUDPaint”,“drawplayerarmor”,DrawPlayerArmor);

function hidehud(name)
for k, v in pairs{“CHudHealth”, “CHudBattery”, “CHudAmmo”, “CHudSecondaryAmmo”} do
if name == v then return false end
end
end
hook.Add(“HUDShouldDraw”, “hidehud”, hidehud)[/lua]



Lua initialized (Lua 5.1)
autorun/client/MyHud.lua:40: 'end' expected (to close 'function' at line 1) near '<eof>'
Registering gamemode 'sandbox' derived from 'base'


you seems to have forgot a “end” somewhere but i cant see any problem…

[editline]09:58AM[/editline]

is that the whole file?

[editline]10:00AM[/editline]

pairs{“CHudHealth”, “CHudBattery”, “CHudAmmo”, “CHudSecondaryAmmo”}
should be:



pairs( {"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"} )


what do you mean by whole file ?

i meant is that everything in your lua file?

yes and it show all clip for the principal gun and ping + name

but I want to make display the weapon_357 clip in the hud in the same time

your problem seems to be at:



 function hidehud(name) 
 	for k, v in pairs{"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"} do 
 		if name == v then return false end 
 	end 
 end 
 hook.Add("HUDShouldDraw", "hidehud", hidehud)


the pairs{“CHudHealth”, “CHudBattery”, “CHudAmmo”, “CHudSecondaryAmmo”} should be:
pairs({“CHudHealth”, “CHudBattery”, “CHudAmmo”, “CHudSecondaryAmmo”} )

[editline]10:10AM[/editline]

you must also return true at the end or things can get messy

it’s saying :



Lua initialized (Lua 5.1)
autorun/client/MyHud.lua:38: 'do' expected near 'if'
Registering gamemode 'sandbox' derived from 'base'
Sending 267 'User Info' ConVars to server (cl_spewuserinfoconvars to see)
Redownloading all lightmaps


just add a “do” without quotes at the end of that line

[lua] function myhud()

for k,v in pairs (LocalPlayer():GetWeapons()) do
if v:GetClass() == “weapon_357” then
– draw v:Clip1()
end
end

local client = LocalPlayer()

if !client:Alive() then return end

//Health, Name, and ping.
draw.RoundedBox(5, 5, 5, 200, 100, Color(0, 0, 0, 60))
draw.SimpleText("HP: " ..	 	client:Health() .. "%", "ScoreboardText", 15, 10, Color(242, 204, 51, 255), 0, 0) 
draw.SimpleText("Name: " ..	 	client:Name(), "ScoreboardText", 15, 20, Color(242, 204, 51, 225), 0, 0)
draw.SimpleText("Ping: " .. 	client:Ping(), "ScoreboardText", 15, 30, Color(242, 204, 51, 225), 0, 0)
//Ammo
draw.SimpleText("Clip: " .. v:Clip1(), "ScoreboardText", 15, 50, Color(242, 204, 51, 225), 0, 0)
draw.SimpleText("Clip Extra: " .. client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()), "ScoreboardText", 15, 60, Color(242, 204, 51, 225), 0, 0)
draw.SimpleText("Clip Secondary: " .. client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType()), "ScoreboardText", 15, 70, Color(242, 204, 51, 225), 0, 0)

end

hook.Add(“HUDPaint”, “myhud”, myhud)

function DrawPlayerArmor()
if (LocalPlayer():Armor() > 0) then
draw.RoundedBox( 8, 32, 16, ScrW() - 64, 16, Color(200, 200, 200, 200));
draw.RoundedBox( 8, 34, 18, (ScrW() - 68)*(LocalPlayer():Armor() / 1000), 12, Color(0, 0, 200, 200));
end
end
hook.Add(“HUDPaint”,“drawplayerarmor”,DrawPlayerArmor);

function hidehud(name)
for k, v in pairs({“CHudHealth”, “CHudBattery”, “CHudAmmo”, “CHudSecondaryAmmo”} ) do
if name == v then return false end
end
end
hook.Add(“HUDShouldDraw”, “hidehud”, hidehud)[/lua]



Lua initialized (Lua 5.1)
Registering gamemode 'sandbox' derived from 'base'
Sending 267 'User Info' ConVars to server (cl_spewuserinfoconvars to see)
Redownloading all lightmaps
Hook 'myhud' Failed: autorun/client/MyHud.lua:19: attempt to index global 'v' (a nil value)