• Help converting code. DarkRP Hud
    8 replies, posted
Old Code [code] /*--------------------------------------------------------------------------- HUD ConVars ---------------------------------------------------------------------------*/ surface.CreateFont( "SpankyID", { font = "TargetID", size = 13, weight = 500, blursize = 0, scanlines = 0, antialias = true, underline = false, italic = false, strikeout = true, symbol = false, rotary = false, shadow = true, additive = false, outline = false, } ) local ConVars = {} local HUDWidth local HUDHeight CreateClientConVar("weaponhud", 0, true, false) local function ReloadConVars() ConVars = { background = {0,0,0,100}, Healthbackground = {0,0,0,200}, Healthforeground = {140,0,0,180}, HealthText = {255,255,255,200}, Job1 = {0,0,150,200}, Job2 = {0,0,0,255}, salary1 = {0,150,0,200}, salary2 = {0,0,0,255} } for name, Colour in pairs(ConVars) do ConVars[name] = {} for num, rgb in SortedPairs(Colour) do local CVar = GetConVar(name..num) or CreateClientConVar(name..num, rgb, true, false) table.insert(ConVars[name], CVar:GetInt()) if not cvars.GetConVarCallbacks(name..num, false) then cvars.AddChangeCallback(name..num, function() timer.Simple(0,ReloadConVars) end) end end ConVars[name] = Color(unpack(ConVars[name])) end HUDWidth = (GetConVar("HudW") or CreateClientConVar("HudW", 240, true, false)):GetInt() HUDHeight = (GetConVar("HudH") or CreateClientConVar("HudH", 115, true, false)):GetInt() if not cvars.GetConVarCallbacks("HudW", false) and not cvars.GetConVarCallbacks("HudH", false) then cvars.AddChangeCallback("HudW", function() timer.Simple(0,ReloadConVars) end) cvars.AddChangeCallback("HudH", function() timer.Simple(0,ReloadConVars) end) end end ReloadConVars() local function formatNumber(n) n = tonumber(n) if (!n) then return 0 end if n >= 1e14 then return tostring(n) end n = tostring(n) sep = sep or "," local dp = string.find(n, "%.") or #n+1 for i=dp-4, 1, -3 do n = n:sub(1, i) .. sep .. n:sub(i+1) end return n end local Scrw, Scrh, RelativeX, RelativeY /*--------------------------------------------------------------------------- HUD Seperate Elements ---------------------------------------------------------------------------*/ local function DrawInfo() LocalPlayer().DarkRPVars = LocalPlayer().DarkRPVars or {} local Salary = "$" .. (LocalPlayer().DarkRPVars.salary or 0) local JobWallet = LANGUAGE.job .. (LocalPlayer().DarkRPVars.job or "") .. "\n".. "$" .. (formatNumber(LocalPlayer().DarkRPVars.money) or 0) local wep = LocalPlayer( ):GetActiveWeapon( ); if IsValid(wep) and GAMEMODE.Config.weaponhud then local name = wep:GetPrintName(); draw.DrawText("Weapon: "..name, "UiBold", RelativeX + 5, RelativeY - HUDHeight - 18, Color(255, 255, 255, 255), 0) end end local Page = Material("icon16/page_white_text.png") local function GunLicense() if LocalPlayer().DarkRPVars.HasGunlicense then surface.SetMaterial(Page) surface.SetDrawColor(255, 255, 255, 255) surface.DrawTexturedRect(RelativeX + HUDWidth, ScrH() - 34, 32, 32) end end local function Agenda() local DrawAgenda, AgendaManager = DarkRPAgendas[LocalPlayer():Team()], LocalPlayer():Team() if not DrawAgenda then for k,v in pairs(DarkRPAgendas) do if table.HasValue(v.Listeners or {}, LocalPlayer():Team()) then DrawAgenda, AgendaManager = DarkRPAgendas[k], k break end end end if DrawAgenda then draw.RoundedBox(0, 10, 10, 460, 110, Color(0, 0, 0, 155)) draw.RoundedBox(0, 12, 12, 456, 106, Color(51, 58, 51,100)) draw.RoundedBox(0, 12, 12, 456, 20, Color(0, 0, 70, 100)) draw.DrawText(DrawAgenda.Title, "DarkRPHUD1", 30, 12, Color(255,0,0,255),0) local AgendaText = "" for k,v in pairs(team.GetPlayers(AgendaManager)) do if not v.DarkRPVars then continue end AgendaText = AgendaText .. (v.DarkRPVars.agenda or "") .. "\n" end draw.DrawText(string.gsub(string.gsub(AgendaText, "//", "\n"), "\\n", "\n"), "DarkRPHUD1", 30, 35, Color(255,255,255,255),0) end end local VoiceChatTexture = surface.GetTextureID("voice/icntlk_pl") local function DrawVoiceChat() if LocalPlayer().DRPIsTalking then local chbxX, chboxY = chat.GetChatBoxPos() local Rotating = math.sin(CurTime()*3) local backwards = 0 if Rotating < 0 then Rotating = 1-(1+Rotating) backwards = 180 end surface.SetTexture(VoiceChatTexture) surface.SetDrawColor(ConVars.Healthforeground) surface.DrawTexturedRectRotated(ScrW() - 100, chboxY, Rotating*96, 96, backwards) end end local function LockDown() local chbxX, chboxY = chat.GetChatBoxPos() if util.tobool(GetConVarNumber("DarkRP_LockDown")) then local cin = (math.sin(CurTime()) + 1) / 2 local chatBoxSize = math.floor(ScrH() / 4) draw.DrawText(LANGUAGE.lockdown_started, "ScoreboardSubtitle", chbxX, chboxY + chatBoxSize, Color(cin * 255, 0, 255 - (cin * 255), 255), TEXT_ALIGN_LEFT) end end local Arrested = function() end usermessage.Hook("GotArrested", function(msg) local StartArrested = CurTime() local ArrestedUntil = msg:ReadFloat() Arrested = function() if CurTime() - StartArrested <= ArrestedUntil and LocalPlayer().DarkRPVars.Arrested then draw.DrawText(string.format(LANGUAGE.youre_arrested, math.ceil(ArrestedUntil - (CurTime() - StartArrested))), "DarkRPHUD1", ScrW()/2, ScrH() - ScrH()/12, Color(255,255,255,255), 1) elseif not LocalPlayer().DarkRPVars.Arrested then Arrested = function() end end end end) local AdminTell = function() end usermessage.Hook("AdminTell", function(msg) local Message = msg:ReadString() AdminTell = function() draw.RoundedBox(4, 10, 10, ScrW() - 20, 100, Color(0, 0, 0, 200)) draw.DrawText(LANGUAGE.listen_up, "GModToolName", ScrW() / 2 + 10, 10, Color(255, 255, 255, 255), 1) draw.DrawText(Message, "ChatFont", ScrW() / 2 + 10, 80, Color(200, 30, 30, 255), 1) end timer.Simple(10, function() AdminTell = function() end end) end) hook.Add("PlayerSpawnedProp", "propCounter", function( ply, model, ent ) ent.Owner = ply end) function timeToStr( time ) local tmp = time local s = tmp % 60 tmp = math.floor( tmp / 60 ) local m = tmp % 60 tmp = math.floor( tmp / 60 ) local h = tmp % 24 tmp = math.floor( tmp / 24 ) local d = tmp % 7 local w = math.floor( tmp / 7 ) return string.format( "%2i hours and %2i minutes", h, m) end /*--------------------------------------------------------------------------- Drawing the HUD elements such as Health etc. ---------------------------------------------------------------------------*/ name = Material("icon16/user.png") job = Material("icon16/wrench.png") salarr = Material("icon16/money.png") banii = Material("icon16/money_dollar.png") played = Material("icon16/time.png") local function MyHUD() net.Receive( "FuelMod", function( len ) veh = net.ReadEntity() gas = net.ReadFloat() end ) local newtime = string.ToMinutesSeconds(CurTime()) local ply = LocalPlayer() local hp,ar = ply:Health(),ply:Armor() local slujba = LocalPlayer().DarkRPVars.job or "Unemployed" local salar = LocalPlayer().DarkRPVars.salary or "NONE" local bani = LocalPlayer().DarkRPVars.money or "NONE" local hr = LocalPlayer().DarkRPVars.Energy local pr = LocalPlayer():GetCount("props") local sta = LocalPlayer():GetNWInt( "tcb_Stamina" ) local totaltime = timeToStr(LocalPlayer():GetUTimeTotalTime()) local showstamina = true LocalPlayer().DarkRPVars = LocalPlayer().DarkRPVars or {} LocalPlayer().DarkRPVars.Energy = LocalPlayer().DarkRPVars.Energy or 0 if (ply:Alive()) then draw.RoundedBox(0,5,ScrH() - 145,270,25,Color(0,0,0,200)) draw.RoundedBox(0,5,ScrH() - 175,270,25,Color(0,0,0,200)) surface.SetMaterial(name) surface.SetDrawColor(255,255,255,255) surface.DrawTexturedRect(10,ScrH() - 110,16,16) draw.SimpleText("Vist: www.4lategaming.com","TargetID",10,ScrH() - 142) draw.RoundedBox(0,5,ScrH() - 115,270,110,
Something like this should work: [CODE] local plyHunger = LocalPlayer():getDarkRPVar( "Energy" ) draw.RoundedBox( 6, 20, 10, 200 * plyHunger / 100, 20, Color( 25, 255, 25, 245 ) ) and for the text draw.DrawText( plyHunger, "DermaLarge", 50, 50, color_white ) [/CODE] Mess around with the code, and make it so that it suits you. Untested but should work.
[QUOTE=Tupac;49878334]Something like this should work: [CODE] local plyHunger = LocalPlayer():getDarkRPVar( "Energy" ) draw.RoundedBox( 20, 10, 200 * plyHunger / 100, 20, Color( 25, 255, 25, 245 ) ) and for the text draw.DrawText( plyHunger, 50, 50, color_white ) [/CODE] Mess around with the code, and make it so that it suits you. Untested but should work.[/QUOTE] It does not trust me i have tried.
[QUOTE=Borris_Squad;49878366]It does not trust me i have tried.[/QUOTE] I highly doubt you did it correctly. Because the code I provided looks fine.
[QUOTE=Tupac;49878369]I highly doubt you did it correctly. Because the code I provided looks fine.[/QUOTE] Well, last time i got the stamina working so i must have done something correctly. So be it lost that code.
That code Tupac provided is incorrect. I don't know about DarkRP or DarkRP variables, but the use of draw.RoundedBox is wrong [code]draw.RoundedBox( number cornerRadius, number x, number y, number width, number height, table color )[/code] A corner radius wasn't provided. Same for draw.DrawText [code]draw.DrawText( string text, string font, number x, number y, table color, number xAlign )[/code] No font was provided.
[QUOTE=McDunkable;49878929]That code Tupac provided is incorrect. I don't know about DarkRP or DarkRP variables, but the use of draw.RoundedBox is wrong [code]draw.RoundedBox( number cornerRadius, number x, number y, number width, number height, table color )[/code] A corner radius wasn't provided. Same for draw.DrawText [code]draw.DrawText( string text, string font, number x, number y, table color, number xAlign )[/code] No font was provided.[/QUOTE] My bad, was in a rush. Thanks, fixed.
You don't need any of that garbage at the top, all of the [lua]local Color = Color local CurTime = CurTime local cvars = cvars local DarkRP = DarkRP local draw = draw local GetConVar = GetConVar local hook = hook local IsValid = IsValid local Lerp = Lerp local localplayer local math = math local pairs = pairs local ScrW, ScrH = ScrW, ScrH local SortedPairs = SortedPairs local string = string local surface = surface local table = table local timer = timer local tostring = tostring local plyMeta = FindMetaTable("Player") [/lua]
[QUOTE=DanielHershey;49881670]You don't need any of that garbage at the top, all of the [lua]local Color = Color local CurTime = CurTime local cvars = cvars local DarkRP = DarkRP local draw = draw local GetConVar = GetConVar local hook = hook local IsValid = IsValid local Lerp = Lerp local localplayer local math = math local pairs = pairs local ScrW, ScrH = ScrW, ScrH local SortedPairs = SortedPairs local string = string local surface = surface local table = table local timer = timer local tostring = tostring local plyMeta = FindMetaTable("Player") [/lua][/QUOTE] gotta make things quick!!111!!!11!
Sorry, you need to Log In to post a reply to this thread.