• HUD error
    5 replies, posted
Hi, i was trying to make a HUD that shows the admins online. but i cant get the HUD to work :/ [CODE]ShowAdmins = true function toggleAdminList() if ShowAdmins then ShowAdmins = false else showAdmins = true end end toggleAdminList() concommand.Add("show_admin", function() toggleAdminList() end) hook.Add("HUDPaint", "toggleAdminList", function() if ShowAdmins then for k, v in pairs(player.GetAll()) do if v:IsAdmin() or v:IsSuperAdmin() then adminList = adminList .. ", " .. v:Nick() // use .. to concat strings end end if (adminList != "") then adminList = string.sub(adminList, 3, string.len(adminList)) draw.SimpleText("Admins: "..adminList, ScrW() * 0.8, ScrH() * 0.2, Color(0, 255, 0, 200), 1, 1) else draw.SimpleText("No admins online!", ScrW() * 0.8, ScrH() * 0.2, Color(255, 0, 0, 200), 1, 1) end end) end)[/CODE]
When you post Lua, place it in a lua tag instead of a code tag. You did not have a font set in your draw.SimpleText calls. I also cleaned up your code a bit: [lua]local showAdmins = true concommand.Add("show_admin", function() if showAdmins then showAdmins = false else showAdmins = true end end ) hook.Add("HUDPaint", "AdminList", function() if showAdmins then local adminList = "" for _,v in pairs(player.GetAll()) do if v:IsAdmin() or v:IsSuperAdmin() then adminList = adminList..", "..v:Nick() end end if adminList ~= "" then adminList = string.sub(adminList, 3, string.len(adminList)) draw.SimpleText("Admins: "..adminList, "ScoreboardText", ScrW()*0.8, ScrH()*0.2, Color(0,255,0,200), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) else draw.SimpleText("No admins online!", "ScoreboardText", ScrW()*0.8, ScrH()*0.2, Color(255,0,0,200), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) end end end )[/lua]
[QUOTE=LuaMilkshake;34233973]When you post Lua, place it in a lua tag instead of a code tag. You did not have a font set in your draw.SimpleText calls. I also cleaned up your code a bit: [lua]local showAdmins = true concommand.Add("show_admin", function() if showAdmins then showAdmins = false else showAdmins = true end end ) hook.Add("HUDPaint", "AdminList", function() if showAdmins then local adminList = "" for _,v in pairs(player.GetAll()) do if v:IsAdmin() or v:IsSuperAdmin() then adminList = adminList..", "..v:Nick() end end if adminList ~= "" then adminList = string.sub(adminList, 3, string.len(adminList)) draw.SimpleText("Admins: "..adminList, "ScoreboardText", ScrW()*0.8, ScrH()*0.2, Color(0,255,0,200), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) else draw.SimpleText("No admins online!", "ScoreboardText", ScrW()*0.8, ScrH()*0.2, Color(255,0,0,200), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) end end end )[/lua][/QUOTE] Thanks! As you can see its my first time posting here, and I guess I should have read the sticky :|
HUD is clientside. From what I know, the only player you can get from the client is the client himself. You'll want to send some usermessages or datastream the info.
Other players exist on the client.. [b][url=http://wiki.garrysmod.com/?title=Player.GetByID]player.GetByID(id)[img]http://wiki.garrysmod.com/images/0/0d/NewerShared.png[/img][/url][/b]
[QUOTE=ArmageddonScr;34286928]Other players exist on the client.. [b][url=http://wiki.garrysmod.com/?title=Player.GetByID]player.GetByID(id)[img]http://wiki.garrysmod.com/images/0/0d/NewerShared.png[/img][/url][/b][/QUOTE] Oh shit, I never knew this. [media]http://www.youtube.com/watch?v=-kl4hJ4j48s[/media] But yeah, I'm just returning (I haven't really played GMod since 08 or 09...) to Lua scripting. So there's a lot of new shit I don't know about. Back when I was scripting, this kinda shit always fucked up on me.
Sorry, you need to Log In to post a reply to this thread.