I am currently working on a Dark-RP hud that will have elements such as health, hunger, armor and all the basic stuff.
I have so far made the hud quite customisable but there's something I am struggling with
This is in the Config folder
The config works perfectly apart from this, As I am still learning lua I cannot get my head over this issue.
[CODE]local WeaponHudDisable = {} -- Weapons that you don't want the AMMOHUD to show the ammo for.
weapon_spiderman, gmod_camera, weapon_physcannon
[/CODE]
This is in the AmmoHud function.
The rest of the ammo function works, weapon is defined.
[CODE]if weapon != WeaponHudDisable then
print("Test")
end[/CODE]
Apologies for the lack of given code, Just know if I replace WeaponHudDisable in the AmmoHud function with weapon_physcannon it works and only prints 'Test' when the gravity gun is held :D
Any help and feedback is appreciated :3.
Thanks in advance <3
First of all, place the elements inside of the table, secondly the weapons should be strings.
[CODE]local WeaponHudDisable = { "weapon_spiderman", "gmod_camera", "weapon_physcannon" }[/CODE]
Now, when you want to check if a table contains a value you do this
[CODE]if !table.HasValue( WeaponHudDisable, weapon ) then
print("Test")
end[/CODE]
I hope this helped, sadly I couldn't help you anymore with the information you provided me.
This is enough, Thanks a bunch :3 <3
[QUOTE=http://wiki.garrysmod.com/page/table/HasValue]This function is very inefficient for large tables (O(n)) [b]and should probably not be called in things that run each frame[/b].[/QUOTE]
If you're checking it every frame, you should instead use something like this:
[code]local WeaponHudDisable = { [ "weapon_spiderman" ] = true, [ "gmod_camera" ] = true, [ "weapon_physcannon" ] = true }[/code]
and then instead of checking if the table has the value using table.HasValue(), just use something like this:
[code]if WeaponHudDisable[ weapon ] != true then[/code]
[QUOTE=AwfulRanger;51005260]
[code]if WeaponHudDisable[ weapon ] != true then[/code][/QUOTE]
IMO this looks a bit nicer than doing bullshit with [I]~= true[/I]:
[code]
if not WeaponHudDisable[weapon] then
[/code]
I got this error thrown at me when I tried using Mijyuoons peice of code.
[CODE]addons/deceptionhud/lua/autorun/cl_deceptionhud.lua:140: attempt to index global 'WeaponHudDisable' (a nil value)
1. AmmoWep - addons/deceptionhud/lua/autorun/cl_deceptionhud.lua:140
2. v - addons/deceptionhud/lua/autorun/cl_deceptionhud.lua:170
3. old_hook_call - lua/includes/modules/hook.lua:84
4. unknown - lua/includes/modules/momo/compat.lua:23
[/CODE]
Then actually create the table
I did create the table, Im not that dumb. :P
Could you post the code you used?
All of it? It's a lil bit lengthy..
[QUOTE=Deception_;51007878]All of it? It's a lil bit lengthy..[/QUOTE]
Post your table & if statement
This is in the actual hud.lua
[CODE]if not WeaponHudDisable[weapon] then
ammohud code[/CODE]
This is in the configuration.lua.
[CODE]local WeaponHudDisable = { [ "weapon_spiderman" ] = true, [ "gmod_camera" ] = true, [ "weapon_physcannon" ] = true }
[/CODE]
They're in separate files so I guess the table isn't being transferred over since it's local
I guess that's a possiblity, Ill try it.
No errors but it doesn't detect when I am holding a weapon from the table. Hmm, Progress is being made atleast :D
Thanks guys
What did you set 'weapon' to be?
[QUOTE=MPan1;51008388]What did you set 'weapon' to be?[/QUOTE]
MPan is right, to expand you should use the example from here: [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/GetActiveWeapon]Player:GetActiveWeapon[/url]
It is, As I said on my first post :P
[QUOTE=Deception_;51009097]It is, As I said on my first post :P[/QUOTE]
Sorry but we don't have the full code so we can't know what is wrong and only way to solve it for us is guess what the problem can be.
Alright then, Welcome to the most untidy ugly looking code on the planet.
[CODE] include("DeceptionConfig.lua")
local WeaponHudDisable = { [ "weapon_spiderman" ] = true, [ "gmod_camera" ] = true, [ "weapon_physcannon" ] = true }
-- Hiding Default HUD
local hidden = { "DarkRP_LocalPlayerHUD", "DarkRP_Hungermod", "CHudHealth", "CHudBattery", "DarkRP_Agenda", "DarkRP_EntityDisplay","CHudAmmo", "CHudSecondaryAmmo"}
if CLIENT then
surface.CreateFont( "Arrest", {
font = "junegull",
size = 18,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true
})
surface.CreateFont( "Name", {
font = "bebasneue",
size = 20,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true
})
surface.CreateFont( "Info", {
font = "bebasneue",
size = 26,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true
})
surface.CreateFont( "Jobs", {
font = "bebasneue",
size = 14,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true
})
surface.CreateFont( "AmmoHUD", {
font = "junegull",
size = 45,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true
})
surface.CreateFont( "AmmoHUD2", {
font = "junegull",
size = 16,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true
})
surface.CreateFont( "HealthBar", {
font = "bebasneue",
size = 18,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true
})
end
if SERVER then
resource.AddFile("resource/fonts/junegull.ttf")
resource.AddFile("resource/fonts/bebasneue.ttf")
return
end
-- Name and other data
local function Name()
name = LocalPlayer():Nick()
draw.SimpleText(name,"Name",33,ScrH()-140,Text_Color ,TEXT_ALIGN_LEFT)
namelength = string.len(name) * 1.8
end
local function Money()
local PlayersMoney = LocalPlayer():getDarkRPVar( "money" )
local Playerwallet = LocalPlayer():getDarkRPVar( "salary" )
draw.DrawText("$"..string.Comma( PlayersMoney).." + " ..Playerwallet, "Info",35,ScrH()-120 ,Text_Color, TEXT_ALIGN_LEFT)
end
local function Job()
local Playersjob = LocalPlayer():getDarkRPVar("job")
draw.DrawText("Rank: "..Playersjob , "Jobs",35,ScrH()-29 ,Text_Color, TEXT_ALIGN_LEFT)
end
-- Background
local function Background()
if hudcurved then
curved = 5
else
curved = 0
end
local namelength = string.len(name) * 1.4
-- Simple Background
draw.RoundedBoxEx(curved,28,ScrH()-150,354+namelength,120,Background_Color,false,false,false,false)
draw.RoundedBoxEx(curved,27,ScrH()-165,356+namelength,15,SecondBackGround_Color,true,true,false,false)
draw.RoundedBoxEx(curved,27,ScrH()-30,356+namelength,15,SecondBackGround_Color,false,false,true,true)
draw.RoundedBoxEx(curved,247,ScrH()-143,72,72,SecondBackGround_Color,false,false,true,true)
-- Seperation Lines
draw.RoundedBoxEx(0,195+namelength,ScrH()-165,2,140,SecondBackGround_Color,false,false,false,false)
end
-- Health Bar
local animhp = 0
local function Health()
local Healthbar = LocalPlayer():Health()
local Healthbar2 = math.Clamp( Healthbar, 0, 100 )
animhp = math.Approach(animhp, Healthbar2, AnimationTime*FrameTime())
draw.RoundedBox(2,215+namelength,ScrH()-65,140,6,Behind_Bar_Color)
if Healthbar != 0 then
draw.RoundedBox(2,215+namelength,ScrH()-65, animhp*1.4,6, Healthbar_color)
end
draw.SimpleText( ""..Healthbar.."" ,"HealthBar",215+namelength+animhp*1.4,ScrH()-70, Text_Color,TEXT_ALIGN_CENTER )
end
-- Armor Bar
local function Armorbar()
local Armorbar = LocalPlayer():Armor()
local Armorbar2 = math.Clamp(Armorbar,0,100)
draw.RoundedBox(2,215+namelength,ScrH()-50,140,6,Behind_Bar_Color)
if Armorbar != 0 then
draw.RoundedBox(2,215+namelength, ScrH()- 50,Armorbar2*1.4,6,Armorbar_color)
end
draw.SimpleText( ""..Armorbar.."" ,"HealthBar",215+namelength+Armorbar2*1.4,ScrH()-55, Text_Color,TEXT_ALIGN_CENTER )
end
-- Your sexy avatar image
local avatar
if IsValid( LocalPlayer() ) && !IsValid( avatar ) then
avatar= vgui.Create( "AvatarImage" )
avatar:SetSize( 64, 64 )
avatar:SetPos( 251, ScrH()-140 )
avatar:SetPlayer( LocalPlayer(), 64 )
end
-- Arrested Messege
local numto=85
local anim=0
local Arrested = function() end
usermessage.Hook("GotArrested", function(msg)
local StartArrested = CurTime()
local ArrestedUntil = msg:ReadFloat()
Arrested = function()
local shouldDraw = hook.Call("HUDShouldDraw", GAMEMODE, "DarkRP_ArrestedHUD")
if shouldDraw == false then return end
if CurTime() - StartArrested <= ArrestedUntil and LocalPlayer():getDarkRPVar("Arrested") then
if hudcurved then
curved = 6
else
curved = 0
end
anim = math.Approach( anim, numto, AnimationTime*FrameTime() )
draw.RoundedBoxEx(curved,ScrW()-anim*5+10,50, 370,30,Background_Color, false,false,true,true )
draw.RoundedBoxEx(curved, ScrW()- anim*5+10,38, 370,16,SecondBackGround_Color,true, true,false,false)
draw.SimpleText(DarkRP.getPhrase( "youre_arrested", math.ceil( ArrestedUntil - ( CurTime() - StartArrested ) ) ),"Arrest",ScrW()-anim*5+15,55, Text_Color,TEXT_ALIGN_LEFT )
elseif not LocalPlayer():getDarkRPVar("Arrested") then
Arrested = function() end
end
end
end)
-- Weapon Infomation
ammonate = 0
local function AmmoWep()
if hudcurved then
curved = 6
else
curved = 0
end
if not LocalPlayer():Alive() then return end
if (LocalPlayer():GetActiveWeapon() == NULL or LocalPlayer():GetActiveWeapon() == "Camera") then return end
local weapon = LocalPlayer():GetActiveWeapon():GetPrintName()
local weaponmag = LocalPlayer():GetActiveWeapon():Clip1()
local weaponmag2 = LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType())
local alt_ammo = LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetSecondaryAmmoType())
if WeaponHudDisable[weapon] then
print("Yep")
end
if weaponmag != -1 then
ammonate = math.Approach( ammonate, 45, AmmoAnimationTime*FrameTime() )
draw.RoundedBoxEx(curved,ScrW()-ammonate*5+15,ScrH()-90,170,55,Background_Color,false,false,true,true)
draw.SimpleText( ""..weaponmag.." / "..weaponmag2 ,"AmmoHUD",ScrW()-ammonate*5+100,ScrH()-88,Text_Color ,TEXT_ALIGN_CENTER)
draw.RoundedBoxEx(curved, ScrW()- ammonate*5+15,ScrH()-106, 170,16,SecondBackGround_Color,true, true,false,false)
else
ammonate = 0
end
end
function deceptionhud()
Name()
Background()
if Show_Job then
Job()
end
AmmoWep()
Arrested()
if Show_Money then
Money()
end
if Show_Health then
Health()
end
if Show_Armor then
Armorbar()
end
end
if hudon then
hook.Add("HUDPaint", "MyHudName", deceptionhud)
hook.Add("HUDShouldDraw", "MHUD_Hide", function(name)
if table.HasValue(hidden, name) || (name == "DarkRP_EntityDisplay" && Config.HeadHUD) then return false end
end)
end
[/CODE]
[QUOTE=Deception_;51009097]It is, As I said on my first post :P[/QUOTE]
[QUOTE=Deception_;51009445]
[CODE]
local weapon = LocalPlayer():GetActiveWeapon():GetPrintName()
[/CODE][/QUOTE]
No, you are not using the example
God damn it, I completely missed that haha, Thanks a bunch :3 Sorry for that. I was tired lols.
Sorry, you need to Log In to post a reply to this thread.