• GLua Variable Reassignment Syntax
    1 replies, posted
Hey guys! I am trying to manipulate text position depending on the highest point of an entity. I have this code but it does not work properly. Nothing is drawing. When I remove the variable reassignment stuff, the code works fine. I am not sure why this is not working how it is supposed. Does GLua not support what I am trying do? Code: function DrawNPCData() local localplayer = LocalPlayer() local tr = localplayer:GetEyeTrace() local npc_bar = Material("materials/npc_bar.png") local NPC_View_Small = {150, 50} local NPC_View_Normal = {300, 75} local NPC_View_Large = {600, 150} local max_view = 0 local min_view = 0 for _, npc in pairs(ents.GetAll()) do local pos = (npc:GetPos() + Vector(0,0,75)):ToScreen() local alpha = 255 - math.Clamp(npc:GetPos():Distance(localplayer:GetPos()) * 0.6, 0, 255) local npc_bounds = npc:OBBMaxs() local npc_top = npc_bounds[3] if npc_bounds[3] >= 0 and npc_bounds[3] <= 60 then local npc_top = npc_bounds[3] - 75 local max_view = NPC_View_Small[1] local min_view = NPC_View_Small[2] elseif npc_bounds[3] >= 61 and npc_bounds[3] <= 90 then local npc_top = npc_bounds[3] local max_view = NPC_View_Normal[1] local min_view = NPC_View_Normal[2] elseif npc_bounds[3] >= 90 and npc_bounds[3] <= 99999 then local npc_top = npc_bounds[3] local max_view = NPC_View_Large[1] local min_view = NPC_View_Large[2] if npc:IsValid() and npc:IsNPC() and (npc:GetPos():Distance(localplayer:GetPos()) <= max_view and npc:GetPos():Distance(localplayer:GetPos()) >= min_view) then --print(npc_bounds) surface.SetMaterial(npc_bar)         surface.SetDrawColor(255,255,255,alpha)         surface.DrawTexturedRect(pos.x-130, pos.y-npc_top, 250, 80) --draw.RoundedBox(0, pos.x-80, pos.y-65, 150, 10, Color(0, 0, 0, 175)) --draw.RoundedBox(0, pos.x-80, pos.y-65, 150 * (npc:Health() / npc:GetMaxHealth()), 10, Color(255, 0, 0, 155)) --draw.SimpleText("prank", HUDFontBar, pos.x, pos.y+25, Color( 255, 255, 255, 255 )) -- end end end end end hook.Add("HUDPaint", "NPCDataDrawing", DrawNPCData)
You're declaring local variables inside a deeper scope than where you're using them
Sorry, you need to Log In to post a reply to this thread.