Need Local variables for primary and secondary ammo.
5 replies, posted
Okay, I've been working on this District 9-themed HUD and unfortunately I've gotten stuck on the code because I can't find the variable for LocalPlayer that represents the primary and secondary ammo. Can someone tell me what it is?
Here is the code I have so far:
[lua]function HideHudBits( name )
if ( name == "CHudHealth" or name == "CHudBattery" or name == "CHudAmmo" or name == "CHudScondaryAmmo" or name == "CHudPoisonDamageIndicator") then
return false
end
end
hook.Add( "HUDShouldDraw", "HideHudBits", HideHudBits )
surface.CreateFont( "D9 non-humans", 100, 400, false, false, "D9NonHumans" )
hook.Add ( "HUDPaint", "D9HudPaint", function()
local hudPlayer = LocalPlayer()
local hudHealth = hudPlayer:Health()
local hudArmor = hudPlayer:Armor()
local hudammo = hudPlayer: --First part I'm stuck on
local hud2ammo = hudPlayer: --Second part I'm stuck on
surface.SetTextColor( 255, 0, 0, 255 )
surface.SetTextPos( 9, (ScrH()/2) + (ScrH()/4) )
surface.SetFont("D9NonHumans")
surface.DrawText( hudHealth )
surface.SetTextColor(221, 111, 0, 255)
surface.SetTextPos( 9, (ScrH()/2) + (ScrH()/6) )
surface.SetFont("D9NonHumans")
surface.DrawText( hudArmor )
surface.SetTextColor(0, 0, 255, 255)
surface.SetTextPos( 9, (ScrH()/2) + (ScrH()/8) )
surface.SetFont("D9NonHumans")
surface.DrawText( hudAmmo )
surface.SetTextColor(0, 255, 0, 255)
surface.SetTextPos (9, (ScrH()/2) + (ScrH()/10) )
surface.SetFont("D9NonHumans")
surface.DrawText( hud2ammo )
draw.RoundedBox(0, 5, ScrH() -160 -20, hudHealth, 15, Color(255,0,0,255))
draw.RoundedBox(0, 5, ScrH() -240 -20, hudArmor, 15, Color(221,111,0,255))
draw.RoundedBox(0, 5, ScRH() -320 -20, hudAmmo, 15, Color(0, 0, 255, 255))
draw.RoundedBox(0, 5, ScRH() -400 -20, hud2ammo, 15, Color(0, 255, 0, 255))
end)
[/lua]
I believe this is what you want.
[b][url=http://wiki.garrysmod.com/?title=Weapon.GetPrimaryAmmoType]Weapon.GetPrimaryAmmoType [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[b][url=http://wiki.garrysmod.com/?title=Weapon.GetSecondaryAmmoType]Weapon.GetSecondaryAmmoType [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
Edit:
Also, don't forget this.
[b][url=http://wiki.garrysmod.com/?title=Player.GetActiveWeapon]Player.GetActiveWeapon [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
And this
[b][url=http://wiki.garrysmod.com/?title=Player.GetAmmoCount]Player.GetAmmoCount [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[QUOTE=wakeboarderCWB;31038743]I believe this is what you want.
[b][url=http://wiki.garrysmod.com/?title=Weapon.GetPrimaryAmmoType]Weapon.GetPrimaryAmmoType [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[b][url=http://wiki.garrysmod.com/?title=Weapon.GetSecondaryAmmoType]Weapon.GetSecondaryAmmoType [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
Edit:
Also, don't forget this.
[b][url=http://wiki.garrysmod.com/?title=Player.GetActiveWeapon]Player.GetActiveWeapon [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
And this
[b][url=http://wiki.garrysmod.com/?title=Player.GetAmmoCount]Player.GetAmmoCount [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b][/QUOTE]
If I use these how do I add them into my code. I'm still a bit of a newbie. -_-'
[QUOTE=TheFallen(TF2);31039223]If I use these how do I add them into my code. I'm still a bit of a newbie. -_-'[/QUOTE]
[lua]if (LocalPlayer():GetActiveWeapon():IsValid()) then
local Ammo1 = LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType())
local Ammo2 = LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetSecondaryAmmoType())
local Current_Ammo = LocalPlayer():GetActiveWeapon():Clip1()
end[/lua]
Just an example. There's some examples on the links I sent you, too.
Thanks for the help I finally got it working!
[QUOTE=TheFallen(TF2);31057904]Thanks for the help I finally got it working![/QUOTE]
No problem. If you need anything else, feel free to ask.
Sorry, you need to Log In to post a reply to this thread.