Hello, Facepunch!
I had encountered with a very simple and even funny problem, but i don't have any idea how to solve it. (I'm not so smart though) :)
I'm making a tiny custom hud addon for my DarkRP server. I want to hide a small part of it and make it shown when player hold "alt" button for example.
I've tried [URL="http://wiki.garrysmod.com/page/Player/KeyDown"]this[/URL], but i don't actually find out how to use it properly.
SS of hud (with highlighted desired section) and code of that part:
[IMG]http://puu.sh/aclNW/0b2928bf71.png[/IMG]
[CODE]
local function PlayerInfo()
-- Values
local Salary_Value = "$"..formatNumber(LocalPlayer():getDarkRPVar("salary") or 0)
local Money_Value = "$"..formatNumber(LocalPlayer():getDarkRPVar("money") or 0)
local Job_Value = LocalPlayer():getDarkRPVar("job") or ""
local Box_Center = HUDSettings.Width / 10
local Box_TopSize = (HUDSettings.Width / 2 - 40) / 1.5
local Hud_Half = HUDSettings.Width / 2
-- W
draw.DrawText(" Кошелек: "..Money_Value, "rTCB_BebasNeue_mid", HUDSettings.PosX+5 + 1 + 320, HUDSettings.PosY+274 + 1, Color(0,0,0,255), 0)
draw.DrawText(" Кошелек: "..Money_Value, "rTCB_BebasNeue_mid", HUDSettings.PosX+5 + 2 + 320, HUDSettings.PosY+274, Color(255,255,255,255), 0)
-- S
draw.DrawText(" Жалование: "..Salary_Value, "rTCB_BebasNeue_mid", HUDSettings.PosX+5 + 1 + 320, HUDSettings.PosY+294 + 1, Color(0,0,0,255), 0)
draw.DrawText(" Жалование: "..Salary_Value, "rTCB_BebasNeue_mid", HUDSettings.PosX+5 + 2 + 320, HUDSettings.PosY+294, Color(255,255,255,255), 0)
-- J
draw.DrawText(" Статус: "..Job_Value, "rTCB_BebasNeue_mid", HUDSettings.PosX+5 + 1 + 320, HUDSettings.PosY+314 + 1, Color(0,0,0,255), 0)
draw.DrawText(" Статус: "..Job_Value, "rTCB_BebasNeue_mid", HUDSettings.PosX+5 + 2 + 320, HUDSettings.PosY+314, Color(255,255,255,255), 0)
end
[/CODE]
you can use i assume use something like
[code]
for k,v in pairs(player.GetAll()) do
if ply:KeyDown(KEY_ALT) then return true else return false
-- hud code
[/code]
not guaranteeing you anything, i have never made a hud.
Try this;
[code]-- Inside your HUDPaint
if LocalPlayer:KeyDown(KEY_LALT) then -- Check for left alt
PlayerInfo()
end[/code]
[CODE]
local ply = LocalPlayer()
if ply:KeyDown(KEY_ALT) then
-- Hud Code
else return end
[/CODE]
[QUOTE=jackwilsdon;45397002]Try this;
[code]-- Inside your HUDPaint
if LocalPlayer:KeyDown(KEY_LALT) then -- Check for left alt
PlayerInfo()
end[/code][/QUOTE]
gives
[CODE][ERROR] addons/darkrpmodification/lua/darkrp_modules/gmodlog_hud_v1/cl_hud.lua:574: attempt to index global 'LocalPlayer' (a function value)
1. fn - addons/darkrpmodification/lua/darkrp_modules/gmodlog_hud_v1/cl_hud.lua:574
[/CODE]
I feel really stupid :D
[QUOTE=Handsome Matt;45397707]did you somehow copy it wrong, post what you have nerd[/QUOTE]
I've edited last post for right error.
I have this:
[CODE]
-- HUDPaint
local function DrawTCBHud()
-- Custom
Base()
if LocalPlayer:KeyDown(KEY_LALT) then -- Check for left alt
PlayerInfo()
end
-- Elements
ElementHealth()
if HUDElements.Armor then
ElementArmor()
end
if HUDElements.Hunger then
ElementHunger()
end
if HUDElements.Stamina then
ElementStamina()
end
-- Default
Agenda()
DrawVoiceChat()
LockDown()
Arrested()
AdminTell()
DrawEntityDisplay()
end
hook.Add("HUDPaint", "DrawTCBHud", DrawTCBHud)[/CODE]
[QUOTE=logimy;45397732]I've edited last post for right error.
I have this:
[CODE]
-- HUDPaint
local function DrawTCBHud()
-- Custom
Base()
if LocalPlayer:KeyDown(KEY_LALT) then -- Check for left alt
PlayerInfo()
end
-- Elements
ElementHealth()
if HUDElements.Armor then
ElementArmor()
end
if HUDElements.Hunger then
ElementHunger()
end
if HUDElements.Stamina then
ElementStamina()
end
-- Default
Agenda()
DrawVoiceChat()
LockDown()
Arrested()
AdminTell()
DrawEntityDisplay()
end
hook.Add("HUDPaint", "DrawTCBHud", DrawTCBHud)[/CODE][/QUOTE]
You need LocalPlayer():KeyDown(KEY_LALT);, not LocalPlayer. It's a function, not a variable. However, Jack got it wrong too :v:
[QUOTE=Cyberuben;45397874]You need LocalPlayer():KeyDown(KEY_LALT);, not LocalPlayer. It's a function, not a variable. However, Jack got it wrong too :v:[/QUOTE]
It's working now, thanks!
Sorry, you need to Log In to post a reply to this thread.