• Hub Help
    9 replies, posted
Hello im creating a TTT Hub for some and and im adding there name into the hub but it doesn't show up code for the name to add the name to the hud [lua] function HudPlyName(ply) local text = ply:Nick() draw.SimpleText( text, font, 255, 255, Color(250, 250, 250, 250 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) end [/lua] any help is loved <3
Are you calling GetText? Edit: He edited the post and renamed the function to 'HudPlyName'
[QUOTE=Coffeee;49435950]Are you calling GetText?[/QUOTE] no, the function is subpost to get the name of the player then put it on the hub
Yeah, but just having the function won't do anything because it's not being run. Check if the player is looking at someone in the HUDPaint hook and call it there Also make sure 'font' is defined (and I think you mean HUD)
Thanks man [editline]1st January 2016[/editline] [QUOTE=Coffeee;49436023]Yeah, but just having the function won't do anything because it's not being run. Check if the player is looking at someone in the HUDPaint hook and call it there Also make sure 'font' is defined (and I think you mean HUD)[/QUOTE] the function is subpost to put the clients name on their own hub do you know what to do
[code] function HudPlyName() local text = LocalPlayer():Nick() draw.SimpleText( text, font, 255, 255, Color(250, 250, 250, 250), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP ) end hook.Add("HUDPaint", "SubpostToDrawNameOnHub", HudPlyName)[/code] ~Copy all of my posts, I don't mind!~
You need to be more specific in what you're trying to do. Are you trying to put the name of a player on your HUD or are you trying to get the name of a player you're looking at? Also, your function will not run or render because its not being told to. You need put it in a HUDPaint. If you want to put the player's name on the HUD, you use LocalPlayer():Name() [lua] surface.CreateFont( "myFont", { -- This is how you define a font. You need to refer to it's name, like in the draw.Simpletext when you want to use it. size = 12, weight = 500, antialias = true, shadow = false, font = "Trebuchet"}) function doHUD() local plyName = LocalPlayer():Name() -- This gets a client's name. draw.SimpleText( plyName, "myFont", 250, 250, Color(250, 250, 250, 250 ) ) end hook.Add( "HUDPaint", "doHUD", doHUD ) -- You need a HUDPaint or it won't render. [/lua]
thanks again [editline]1st January 2016[/editline] [QUOTE=angrypygmy;49436151]You need to be more specific in what you're trying to do. Are you trying to put the name of a player on your HUD or are you trying to get the name of a player you're looking at? Also, your function will not run or render because its not being told to. You need put it in a HUDPaint. If you want to put the player's name on the HUD, you use LocalPlayer():Name() [lua] surface.CreateFont( "myFont", { -- This is how you define a font. You need to refer to it's name, like in the draw.Simpletext when you want to use it. size = 12, weight = 500, antialias = true, shadow = false, font = "Trebuchet"}) function doHUD() local plyName = LocalPlayer():Name() -- This gets a client's name. draw.SimpleText( plyName, "myFont", 250, 250, Color(250, 250, 250, 250 ) ) end hook.Add( "HUDPaint", "doHUD", doHUD ) -- You need a HUDPaint or it won't render. [/lua][/QUOTE] okay so the text is behind the HUD. where whould i put that code or change some code your code is at the botem [lua] -- HUD HUD HUD local table = table local surface = surface local draw = draw local math = math local string = string local GetTranslation = LANG.GetTranslation local GetPTranslation = LANG.GetParamTranslation local GetLang = LANG.GetUnsafeLanguageTable local interp = string.Interp -- Fonts surface.CreateFont("TraitorState_ex", {font = "Octin Sports RG", size = 30, weight = 1000}) surface.CreateFont("TimeLeft_ex", {font = "Octin Sports RG", size = 28, weight = 800}) surface.CreateFont("HealthAmmo_ex", {font = "Octin Sports RG", size = 28, weight = 750}) surface.CreateFont("HasteMode_ex", {font = "Octin Sports RG", size = 14, weight = 250}) surface.CreateFont("Plyname_ex", {font = "Octin Sports RG", size = 14, weight = 250}) -- Default TTT fonts for SpecDM support surface.CreateFont("TraitorState", {font = "Trebuchet24", size = 28, weight = 1000}) surface.CreateFont("TimeLeft", {font = "Trebuchet24", size = 24, weight = 800}) surface.CreateFont("HealthAmmo", {font = "Trebuchet24", size = 24, weight = 750}) -- Color presets local bg_colors = { background_main = Color(40, 49, 58, 255), background_haste = Color(120, 125, 146), noround = Color(100,100,100,200), traitor = Color(192, 37, 23, 200), innocent = Color(39, 204, 56, 200), detective = Color(41, 108, 185, 200) }; local name_colors = Color(40, 40, 255, 250) local health_colors = { border = COLOR_WHITE, background = Color(40, 49, 58, 255), fill = Color(200, 50, 50, 255) }; local ammo_colors = { border = COLOR_WHITE, background = Color(40, 49, 58, 255), fill = Color(205, 155, 0, 255) }; local highlight_colors = { noround = Color(50,50,50,200), haste = Color(70, 75, 96), traitor = Color(142, 0, 0, 200), innocent = Color(0, 154, 6, 200), detective = Color(0, 58, 135, 200), ammo = Color(155, 105, 0, 255), health = Color(150, 0, 0, 250), } -- Modified RoundedBox local Tex_Corner8 = surface.GetTextureID( "gui/corner8" ) local function RoundedMeter( bs, x, y, w, h, color) surface.SetDrawColor(clr(color)) surface.DrawRect( x+bs, y, w-bs*2, h ) surface.DrawRect( x, y+bs, bs, h-bs*2 ) surface.SetTexture( Tex_Corner8 ) surface.DrawTexturedRectRotated( x + bs/2 , y + bs/2, bs, bs, 0 ) surface.DrawTexturedRectRotated( x + bs/2 , y + h -bs/2, bs, bs, 90 ) if w > 14 then surface.DrawRect( x+w-bs, y+bs, bs, h-bs*2 ) surface.DrawTexturedRectRotated( x + w - bs/2 , y + bs/2, bs, bs, 270 ) surface.DrawTexturedRectRotated( x + w - bs/2 , y + h - bs/2, bs, bs, 180 ) else surface.DrawRect( x + math.max(w-bs, bs), y, bs/2, h ) end end ---- The bar painting is loosely based on: ---- [url]http://wiki.garrysmod.com/?title=Creating_a_HUD[/url] -- Paints a graphical meter bar local function PaintBar(x, y, w, h, colors, value, bg) -- Background -- slightly enlarged to make a subtle border if bg then draw.RoundedBox(0, x-1, y-1, w+2, h+2, colors.background) end -- Fill local width = w * math.Clamp(value, 0, 1) if width > 0 then RoundedMeter(0, x, y, width, h, colors.fill) end end local roundstate_string = { [ROUND_WAIT] = "round_wait", [ROUND_PREP] = "round_prep", [ROUND_ACTIVE] = "round_active", [ROUND_POST] = "round_post" }; -- Returns player's ammo information local function GetAmmo(ply) local weap = ply:GetActiveWeapon() if not weap or not ply:Alive() then return -1 end local ammo_inv = weap:Ammo1() or 0 local ammo_clip = weap:Clip1() or 0 local ammo_max = weap.Primary.ClipSize or 0 return ammo_clip, ammo_max, ammo_inv end local function DrawBg(x, y, width, height, client) -- Traitor area sizes local th = 40 local tw = 170 -- Adjust for these y = y - th + 25 height = height + th - 30 -- main bg area, invariant -- encompasses entire area draw.RoundedBox(0, x, y, width, height, bg_colors.background_main) -- main border, traitor based local col = bg_colors.innocent local high = highlight_colors.innocent if GAMEMODE.round_state != ROUND_ACTIVE then col = bg_colors.noround high = highlight_colors.noround elseif client:GetTraitor() then col = bg_colors.traitor high = highlight_colors.traitor elseif client:GetDetective() then col = bg_colors.detective high = highlight_colors.detective end -- Role bar draw.RoundedBox(0, x + 10, y, tw + 10, th + 1, col) RoundedMeter( 0, x , y, 10, th + 1, high) end local sf = surface local dr = draw local function ShadowedText(text, font, x, y, color, xalign, yalign) -- dr.SimpleText(text, font, x+2, y+2, COLOR_BLACK, xalign, yalign) dr.SimpleText(text, font, x, y, color, xalign, yalign) end local margin = 30 -- Paint punch-o-meter local function PunchPaint(client) local L = GetLang() local punch = client:GetNWFloat("specpunches", 0) local width, height = 200, 25 local x = ScrW() / 2 - width/2 local y = margin/2 + height PaintBar(x, y, width, height, ammo_colors, punch, true) local color = bg_colors.background_main dr.SimpleText(L.punch_title, "HealthAmmo_ex", ScrW() / 2, y, Color(250,250,250,255), TEXT_ALIGN_CENTER) dr.SimpleText(L.punch_help, "TabLarge", ScrW() / 2, margin, COLOR_WHITE, TEXT_ALIGN_CENTER) local bonus = client:GetNWInt("bonuspunches", 0) if bonus != 0 then local text if bonus < 0 then text = interp(L.punch_bonus, {num = bonus}) else text = interp(L.punch_malus, {num = bonus}) end dr.SimpleText(text, "TabLarge", ScrW() / 2, y * 2, COLOR_WHITE, TEXT_ALIGN_CENTER) end end local key_params = { usekey = Key("+use", "USE") } local function SpecHUDPaint(client) local L = GetLang() -- for fast direct table lookups -- Draw round state local x = margin local height = 32 local width = 250 local round_y = ScrH() - height - margin -- move up a little on low resolutions to allow space for spectator hints if ScrW() < 1000 then round_y = round_y - 15 end local time_y = round_y + 4 draw.RoundedBox(0, x, round_y, width/2, height, bg_colors.background_main) draw.RoundedBox(0, x, round_y - height, width/1.2, height, bg_colors.noround) local text = L[ roundstate_string[GAMEMODE.round_state] ] ShadowedText(text, "TraitorState_ex", x + 10, round_y - height, COLOR_WHITE) -- Draw round/prep
:snip:
[QUOTE=MPan1;49436579]So... you're overriding the default HUDPaint function AND hooking to it?![/QUOTE] yep
Sorry, you need to Log In to post a reply to this thread.