Hud problemas! Please help?

I feel like I’m being completely ignored D: :tinfoil:

Lol, damn. I guess I’m missing an ‘=’ here?

[ERROR] lua_run:1: ‘=’ expected near ‘<eof>’

  1. unknown - lua_run:0
    Also, what tag do you put errors in to make them look like that one comment on this thread?

[lua]

if (SERVER) then return nil end – We only draw on the client. There is no screen for the server, EVER, even if the host is the server, it’s the computer, not them. True for laptops and desktops!

hud = {} – Creates a lonely table for ONE function.
–hud.maxammo = {} – Table to get our current weapon’s max ammo.
hud.maxammo = 18 – Max ammo for the pistol. This will change if we have the SMG1.

– I will comment this so that anyone can understand if they want to make their own HUD. –

function MetroHud() – Main bulk of the code, loops on.
if hidden then return end – The player wanted to hide the HUD. Too bad D: we do nothing!
local Scrw, Scrh = ScrW(), ScrH() – Creates two variables, screen width Scrw, and screan height Scrh. They are exactly equal to the true game resolution.
local HudBG = { – Names the table of settings.
texture = surface.GetTextureID “CombineHud/met_comb_ovr_2048”, – What texture to use
color = Color(255,255,255,255), – What color (this color does no change) (RED,GReeN,BLUe,Alpha)
x = 0, – 0 is the exact start of the width (X is width)
y = 0, – 0 is the exact start of the height (Y is height)
w = Scrw, – Cover the entire screen. Width = w
h = Scrh – Cover the entire screen. Height = h
} – Ends the table.
local Client = LocalPlayer() – The player that sees the HUD. Always him or her, never a connected player.
draw.TexturedQuad( HudBG ) – Draws what the {table} above, HudBG, says to draw.
local HealthBackMet = surface.GetTextureID “CombineHud/met_health_bg” – Background image for the health readout.
local HealthBarMet = surface.GetTextureID “CombineHud/met_health_bar” – Image of the actual meter for shields.
local SuitBackMet = surface.GetTextureID “CombineHud/met_shld_lvl” – Background image for the shield readout.
local SuitBarMet = surface.GetTextureID “CombineHud/met_shld_lvl” – Image of the actual meter for shields.
local CommandPost = surface.GetTextureID “CombineHud/met_command” – Not used yet!
local Criminal = surface.GetTextureID “CombineHud/met_criminal” – Not used yet!

local Promotion =  surface.GetTextureID "CombineHud/met_promo"			-- Not used yet!
local MeterWidth = Scrw / 4	-- The meter's actual size is one forth of the screen's width. 
local MeterWidthBarEnd = MeterWidth-(MeterWidth*math.min((Client:Health()/40),1)*0.5)	-- Max health as a metro cop? 40. This sets up the bar for health.
local MeterWidthBar = MeterWidth-(MeterWidth*math.min((Client:Armor()/25),1)*0.5)	-- Max shield as a metro cop? 25. This sets up the bar for shield.
local MeterHeight = MeterWidth/4	-- Since the texture resolution for width is 4x the height, we take one forth of our width for height.
surface.SetTexture( HealthBackMet )	-- This tells the game what image to draw.
surface.DrawTexturedRectRotated(Scrw/4,Scrh+MeterHeight,MeterWidth,MeterHeight,0)	-- This draws an image. Format: Position &lt;&gt;, position ^v, Width &lt;&gt;, Height &v, Counter Clock Rotation
surface.SetTexture( HealthBarMet )	-- This tells the game what image to draw, and overrides the last time it was set so we don't keep drawing the same thing.
surface.DrawTexturedRectUV(Scrw/4,Scrh+MeterHeight,MeterWidthBarEnd,MeterHeight,MeterWidthBarEnd,MeterHeight)	-- Draws the image. Format: Pos Wide, Pos Tall, Image Width, Image Height, How much to show texture wide, same for height.
local PosShieldsX = Scrw-MeterWidth-(Scrw/4)	-- Variable. Used so that we draw on the other side of the screen mathematically.

– local PosShldMetX = Scrw-(MeterWidth*1.5)-(Scrw/4) – Half way further away because we didn’t flip it. – This was removed when we did flip it.
surface.SetTexture( SuitBackMet ) – Set and replace image…
surface.DrawTexturedRectRotated(PosShieldsX,Scrh,MeterWidth,MeterHeight,0) – This draws an image. Format: Position <>, position ^v, Width <>, Height &v, Counter Clock Rotation
surface.SetTexture( SuitBarMet ) – Set and replace image…
surface.DrawTexturedRectUV(PosShieldsX,Scrh,MeterWidthBar,MeterHeight,MeterWidthBarEnd,MeterHeight) – Draws the image. Format: Pos Wide, Pos Tall, Image Width, Image Height, How much to show texture wide, same for height.

if Client:GetActiveWeapon():GetPrintName() == "USP Match mod" then hud.maxammo = 18		-- The max ammo for the pistol is 18, 19 with chamber.
elseif Client:GetActiveWeapon():GetPrintName() == "STUNSTICK" then hud.maxammo = -1	-- The Stunstick has 100% ammo, 100 Guass Energy 'rounds'.
elseif Client:GetActiveWeapon():GetPrintName() == "MP7A1 mod" then hud.maxammo = 45			-- The MP7 (SMG1) has 45 rounds, 46 with chamber.
elseif Client:GetActiveWeapon():GetPrintName() == "SPAS-12 mod" then hud.maxammo = 6		-- The shotgun has a 6 round 'clip', with no chamber.
elseif Client:GetActiveWeapon():GetPrintName() == "Pulse Rifle" then hud.maxammo = 30 end	-- The shotgun has a 30 round 'clip', with no chamber.

end

hook.Add( “HUDPaint”, “MetroHUD”, MetroHud ) – This tells the game to draw the function as the HUD. Format: What to do, A unique name (what purpose?), What function to use to do it. Called before every frame that is drawn.

function HideHUD( name ) – Allow the combine elements, hide the regular.
if !hidden then – If the HUD is hidden, then do this:
if name == “CHudHealth” then return false end – Says that we don’t want the DEFAULT health display.
if name == “CHudBattery” then return false end – Says that we don’t want the DEFAULT battery display.
if name == “CHudAmmo” then return false end – Says that we don’t want the DEFAULT ammo display.
if name == “CHudSecondaryAmmo” then return false end – Says that we don’t want the DEFAULT alt-fire ammo display.
if name == “CHudCrosshair” then return false end – Says that we don’t want the DEFAULT crosshair.
if name == “CHudDeathNotice” then return false end – Says that we don’t want to know who killed who, and who died.
if name == “CHudWeaponSelection” then return false end – Says that we don’t want the DEFAULT weapon selection.
if name == “CHudSquadStatus” then return false end – Says that we don’t want the squad display, for rebels.
if name == “CHudZoom” then return false end – Says that we don’t want things darker when we zoom.
if name == “CHudHistoryResource” then return false end – Says that we don’t want to know what we have picked up, ammo-wise.
end – Closes the first “if” statement. The other ones close themselves.
return true – Should we make “the drawing” of these things do what we say? true. Otherwise, false.
– Format is: if name(default HUD function set) ==(is exactly) "Individual Function Name, case sensitive) then(Do this:) return(Give an answer) bool(false=no, true=yes) end(finishes it)
end – We are done with this function, so stop it here.

hook.Add(“HUDShouldDraw”,“HideHUD”,HideHUD) – Should we draw? Everything that the function doesn’t say no to. Act, Name, Function.
local hidden = false – Create the variable why don’t we?

function hud.hideme() – function used to hide this HUD.
if hidden == false then – If we’re not hidden, then
hidden = true –cry … Hide us!
elseif hidden == true then – If we’re already hidden, then (elseif means that we add an if statement to this code block. We don’t need to end the if we started with.)
hidden = false --oh now you want me back. Show us!
end – Done. We now know what to do.
end – Done, we have nothing else to do =P

concommand.Add(“z420hud_toggle”,“Hide Combine Hud”,hud.hideme) – Create the console command that hides this HUD. Format: “CommandName”, “Description”, function to use.[/lua]

Of course, my comments make no sense since it doesn’t work…

And also, how do I make a prop_combine_ball that doesn’t just go through every world surface? (with the owner of the swep as the owner of the combine’s ball)?

I only re posted because the last one was closed, the title was not descriptive. I tried to make this one’s title descriptive. The Lua what do you want help with thread has moved on, several times, to other pages, without an answer to this.

[editline]26th January 2013[/editline]

And the reason I put a comment on every line is specifically for people who don’t know a lick about making HUDs, or for that matter, Lua, yet whom still want to make their own HUDs.

Where is this file?

If you’re using lua_run_cl you should be using lua_openscript_cl

Okay… It’s in the Lua folder, included with a lua/autorun file, but I renamed that to a .lua.old file for now. Let me try it with the lua_openscript_cl.

[editline]26th January 2013[/editline]

Otay, now it’s not changing a thing at all! What’s wrong? Or does it need to run during loading?

See those ==?

lua_openscript_cl is disabled unless the server has sv_allowcslua set to 1

Also, your lua file should really not end with .old.

No what he said is he included it in a file that was in autorun, but he put a .old on it so it didn’t automatically run the script.

^Yes. The two above me are correct. But the == are intended… == means “Is it equal to this?” and = means “Make it equal to this, as exactly as the cpu can do so.”

[editline]26th January 2013[/editline]

Okay, there were some errors in the code D:
[ERROR] addons/combinification/lua/metrocophud.lua:38: bad argument #8 to ‘DrawTexturedRectUV’ (number expected, got no value)

  1. DrawTexturedRectUV - [C]:-1
  2. v - addons/combinification/lua/metrocophud.lua:38
    3. unknown - lua/includes/modules/hook.lua:82

[lua]

if (SERVER) then return nil end – We only draw on the client. There is no screen for the server, EVER, even if the host is the server, it’s the computer, not them. True for laptops and desktops!

hud = {} – Creates a lonely table for ONE function.
–hud.maxammo = {} – Table to get our current weapon’s max ammo.
hud.maxammo = 18 – Max ammo for the pistol. This will change if we have the SMG1.

– I will comment this so that anyone can understand if they want to make their own HUD. –

function MetroHud() – Main bulk of the code, loops on.
if hidden then return end – The player wanted to hide the HUD. Too bad D: we do nothing!
local Scrw, Scrh = ScrW(), ScrH() – Creates two variables, screen width Scrw, and screan height Scrh. They are exactly equal to the true game resolution.
local HudBG = surface.GetTextureID “CombineHud/met_comb_ovr_2048” – Makes us draw with the background image.
local Client = LocalPlayer() – The player that sees the HUD. Always him or her, never a connected player.
local ScrFXRot = Client:GetVelocity():Length()/400 – How much we rotate the background is based on your speed.
surface.SetTexture( HudBG )
surface.DrawTexturedRectRotated(0,0,Scrw1.05,Scrh1.05,ScrFXRot)
local HealthBackMet = surface.GetTextureID “CombineHud/met_health_bg” – Background image for the health readout.
local HealthBarMet = surface.GetTextureID “CombineHud/met_health_bar” – Image of the actual meter for shields.
local SuitBackMet = surface.GetTextureID “CombineHud/met_shld_lvl” – Background image for the shield readout.
local SuitBarMet = surface.GetTextureID “CombineHud/met_shld_lvl” – Image of the actual meter for shields.
local CommandPost = surface.GetTextureID “CombineHud/met_command” – Not used yet!
local Criminal = surface.GetTextureID “CombineHud/met_criminal” – Not used yet!

local Promotion =  surface.GetTextureID "CombineHud/met_promo"			-- Not used yet!
local MeterWidth = Scrw / 4	-- The meter's actual size is one forth of the screen's width. 
local MeterWidthBarEnd = MeterWidth-(MeterWidth*math.min((Client:Health()/40),1)*0.5)	-- Max health as a metro cop? 40. This sets up the bar for health.
local MeterWidthBar = MeterWidth-(MeterWidth*math.min((Client:Armor()/25),1)*0.5)	-- Max shield as a metro cop? 25. This sets up the bar for shield.
local MeterHeight = MeterWidth/4	-- Since the texture resolution for width is 4x the height, we take one forth of our width for height.
surface.SetTexture( HealthBackMet )	-- This tells the game what image to draw.
surface.DrawTexturedRectRotated(Scrw/4,Scrh+MeterHeight,MeterWidth,MeterHeight,0)	-- This draws an image. Format: Position &lt;&gt;, position ^v, Width &lt;&gt;, Height &v, Counter Clock Rotation
surface.SetTexture( HealthBarMet )	-- This tells the game what image to draw, and overrides the last time it was set so we don't keep drawing the same thing.
surface.DrawTexturedRectUV(Scrw/4,Scrh+MeterHeight,MeterWidthBarEnd,MeterHeight,MeterWidthBarEnd,MeterHeight)	-- Draws the image. Format: Pos Wide, Pos Tall, Image Width, Image Height, How much to show texture wide, same for height.
local PosShieldsX = Scrw-MeterWidth-(Scrw/4)	-- Variable. Used so that we draw on the other side of the screen mathematically.

– local PosShldMetX = Scrw-(MeterWidth*1.5)-(Scrw/4) – Half way further away because we didn’t flip it. – This was removed when we did flip it.
surface.SetTexture( SuitBackMet ) – Set and replace image…
surface.DrawTexturedRectRotated(PosShieldsX,Scrh,MeterWidth,MeterHeight,0) – This draws an image. Format: Position <>, position ^v, Width <>, Height &v, Counter Clock Rotation
surface.SetTexture( SuitBarMet ) – Set and replace image…
surface.DrawTexturedRectUV(PosShieldsX,Scrh,MeterWidthBar,MeterHeight,MeterWidthBar,MeterHeight) – Draws the image. Format: Pos Wide, Pos Tall, Image Width, Image Height, How much to show texture wide, same for height.

if Client:GetActiveWeapon():GetPrintName() == "USP Match mod" then hud.maxammo = 18		-- The max ammo for the pistol is 18, 19 with chamber.
elseif Client:GetActiveWeapon():GetPrintName() == "STUNSTICK" then hud.maxammo = -1	-- The Stunstick has 100% ammo, 100 Guass Energy 'rounds'.
elseif Client:GetActiveWeapon():GetPrintName() == "MP7A1 mod" then hud.maxammo = 45			-- The MP7 (SMG1) has 45 rounds, 46 with chamber.
elseif Client:GetActiveWeapon():GetPrintName() == "SPAS-12 mod" then hud.maxammo = 6		-- The shotgun has a 6 round 'clip', with no chamber.
elseif Client:GetActiveWeapon():GetPrintName() == "Pulse Rifle" then hud.maxammo = 30 end	-- The shotgun has a 30 round 'clip', with no chamber.

end

hook.Add( “HUDPaint”, “MetroHUD”, MetroHud ) – This tells the game to draw the function as the HUD. Format: What to do, A unique name (what purpose?), What function to use to do it. Called before every frame that is drawn.

function HideHUD( name ) – Allow the combine elements, hide the regular.
if !hidden then – If the HUD is hidden, then do this:
if name == “CHudHealth” then return false end – Says that we don’t want the DEFAULT health display.
if name == “CHudBattery” then return false end – Says that we don’t want the DEFAULT battery display.
if name == “CHudAmmo” then return false end – Says that we don’t want the DEFAULT ammo display.
if name == “CHudSecondaryAmmo” then return false end – Says that we don’t want the DEFAULT alt-fire ammo display.
if name == “CHudCrosshair” then return false end – Says that we don’t want the DEFAULT crosshair.
if name == “CHudDeathNotice” then return false end – Says that we don’t want to know who killed who, and who died.
if name == “CHudWeaponSelection” then return false end – Says that we don’t want the DEFAULT weapon selection.
if name == “CHudSquadStatus” then return false end – Says that we don’t want the squad display, for rebels.
if name == “CHudZoom” then return false end – Says that we don’t want things darker when we zoom.
if name == “CHudHistoryResource” then return false end – Says that we don’t want to know what we have picked up, ammo-wise.
end – Closes the first “if” statement. The other ones close themselves.
return true – Should we make “the drawing” of these things do what we say? true. Otherwise, false.
– Format is: if name(default HUD function set) ==(is exactly) "Individual Function Name, case sensitive) then(Do this:) return(Give an answer) bool(false=no, true=yes) end(finishes it)
end – We are done with this function, so stop it here.

hook.Add(“HUDShouldDraw”,“HideHUD”,HideHUD) – Should we draw? Everything that the function doesn’t say no to. Act, Name, Function.
local hidden = false – Create the variable why don’t we?

function hud.hideme() – function used to hide this HUD.
if hidden == false then – If we’re not hidden, then
hidden = true –cry … Hide us!
elseif hidden == true then – If we’re already hidden, then (elseif means that we add an if statement to this code block. We don’t need to end the if we started with.)
hidden = false --oh now you want me back. Show us!
end – Done. We now know what to do.
end – Done, we have nothing else to do =P

concommand.Add("****hud_toggle",“Hide Combine Hud”,hud.hideme) – Create the console command that hides this HUD. Format: “CommandName”, “Description”, function to use.[/lua]

[editline]26th January 2013[/editline]

Ugh. I HATE how editing destroys lua tags.

I hate how this code kinda makes me barf.

I hate how your comment makes me… want to… BARFS… slap you.

[editline]26th January 2013[/editline]

But, could sum1 please tell me whatsa matta?

[editline]26th January 2013[/editline]

Because… once I get this Hud working, I will give a preview of the very first Metro Police map I’m making, right now it’s just the main base and some buildings in the background. Eventually, it will also have a place where you try to act like a Metro Cop.

I’m pretty sure it wants to make Magenta barf because your code is ugly as shit, lets state how many problems I see.

  1. You comment every single line. You shouldn’t have to because you should know what your code does… you’re the one writing it.
  2. Line 77, I would advise you read the wiki because you don’t have to do:


if hidden == false then
--do shit
end


Just do:



if !hidden then
--do shit
end


If you want to check if a variable is true or not you don’t have to do:



if hidden == true then
--doshit
end


Just do:



if hidden then
--doshit
end


I mean seriously all this shit is on the Garry’s Mod 12 wiki and most of it is still implementable in GM13.

  1. Your HideHud function is ugly as fucking hell and should only be about 4 lines… not even.
    It can be 4 lines if you know how to use tables and apparently you don’t because I don’t see it implemented anywhere.

I would add more to this but I don’t feel like wasting anymore of my time.

I comment every line so someone without ANY lua experience could make their own Hud!
if !hidden … That I copied from another HUD.
For hide hud, the console command toggles it, so I need either 5 lines, or 1 line with a lot of ; symbols.

[editline]26th January 2013[/editline]

For that matter, I used another hud as a base, so I didn’t change a lot of it…

No one said you need ;

They are optional and never play a part in lua.

Well, I guess I could do [lua]if !hidden then hidden=true else hidden=false end[/lua]

[editline]26th January 2013[/editline]

Shut up. If I want to do multiple lines in only ONE line, I do need it!

[editline]26th January 2013[/editline]

But we are getting off track. I don’t care how ugly my code is, as long as it works! Please tell me, how do I fix this error? I can’t find an 8th argument for the function it states.

[lua]
print(“Line 1”)
print(“Line 2”)
print(“Line 3”)
[/lua]

[lua]
print(“Line 1”);
print(“Line 2”);
print(“Line 3”);
[/lua]

[lua]
print(“Line 1”); print(“Line 2”); print(“Line 3”)
[/lua]

[lua]
print(“Line 1”) print(“Line 2”) print(“Line 3”)
[/lua]

All 4 of them. Will do the exact same thing.

[editline]26th January 2013[/editline]

And if you don’t make your scripts neat and efficient.
Then your gonna have some big god damn problems when you try and find errors routing through a whole game mode.

[lua]if (SERVER) then return nil end
hud = {}
–hud.maxammo = {}
hud.maxammo = 18 – I don’t want a table. We won’t be showing it for all weapons at one time.

function MetroHud()
if hidden then return end
local Scrw, Scrh = ScrW(), ScrH()
local HudBG = surface.GetTextureID “CombineHud/met_comb_ovr_2048”
local Client = LocalPlayer()
local ScrFXRot = Client:GetVelocity():Length()/400
surface.SetTexture( HudBG )
surface.DrawTexturedRectRotated(0,0,Scrw1.05,Scrh1.05,ScrFXRot)
local HealthBackMet = surface.GetTextureID “CombineHud/met_health_bg”
local HealthBarMet = surface.GetTextureID “CombineHud/met_health_bar”
local SuitBackMet = surface.GetTextureID “CombineHud/met_shld_lvl”
local SuitBarMet = surface.GetTextureID “CombineHud/met_shld_lvl”
local CommandPost = surface.GetTextureID “CombineHud/met_command” – Not used yet!
local Criminal = surface.GetTextureID “CombineHud/met_criminal” – Not used yet!

local Promotion =  surface.GetTextureID "CombineHud/met_promo"			-- Not used yet!
local MeterWidth = Scrw / 4
local MeterWidthBarEnd = MeterWidth-(MeterWidth*math.min((Client:Health()/40),1)*0.5)
local MeterWidthBar = MeterWidth-(MeterWidth*math.min((Client:Armor()/25),1)*0.5)
local MeterHeight = MeterWidth/4
surface.SetTexture( HealthBackMet )
surface.DrawTexturedRectRotated(Scrw/4,Scrh+MeterHeight,MeterWidth,MeterHeight,0)
surface.SetTexture( HealthBarMet )
surface.DrawTexturedRectUV(Scrw/4,Scrh+MeterHeight,MeterWidthBarEnd,MeterHeight,MeterWidthBarEnd,MeterHeight)
local PosShieldsX = Scrw-MeterWidth-(Scrw/4)
surface.SetTexture( SuitBackMet )
surface.DrawTexturedRectRotated(PosShieldsX,Scrh,MeterWidth,MeterHeight,0)
surface.SetTexture( SuitBarMet )
surface.DrawTexturedRectUV(PosShieldsX,Scrh,MeterWidthBar,MeterHeight,MeterWidthBar,MeterHeight)
-- TODO: Check for class name instead. We only will want ammo for the USP, MP7, SPAS, and AR2,
if Client:GetActiveWeapon():GetPrintName() == "USP Match mod" then hud.maxammo = 18
elseif Client:GetActiveWeapon():GetPrintName() == "STUNSTICK" then hud.maxammo = -1
elseif Client:GetActiveWeapon():GetPrintName() == "MP7A1 mod" then hud.maxammo = 45
elseif Client:GetActiveWeapon():GetPrintName() == "SPAS-12 mod" then hud.maxammo = 6
elseif Client:GetActiveWeapon():GetPrintName() == "Pulse Rifle" then hud.maxammo = 30 end

end
hook.Add( “HUDPaint”, “MetroHUD”, MetroHud )
function HideHUD( name )
if !hidden then
if name == “CHudHealth” then return false end
if name == “CHudBattery” then return false end
if name == “CHudAmmo” then return false end
if name == “CHudSecondaryAmmo” then return false end
if name == “CHudCrosshair” then return false end
if name == “CHudDeathNotice” then return false end
if name == “CHudWeaponSelection” then return false end
if name == “CHudSquadStatus” then return false end
if name == “CHudZoom” then return false end
if name == “CHudHistoryResource” then return false end
end
return true
end
hook.Add(“HUDShouldDraw”,“HideHUD”,HideHUD)
local hidden = false
function hud.hideme()
if !hidden then hidden=true else hidden=false end
end
concommand.Add(“z420hud_toggle”,“Hide Combine Hud”,hud.hideme)[/lua]

I did this just so people would stop complaining.

[editline]26th January 2013[/editline]

Oh, also, is there a way I can just hide the entire default HUD with one line?

Listen. We are not complaining, we are trying to help you. We are doing this for your own good, cause after all, if experienced people wont help you, who will?

OMG… I did it because I thought I was done, and it took a LONG time to make all of those comments. I have not removed them, I only created a second file with the ending “.lua.old”

[lua]
hook.Add(“HUDShouldDraw”, “Disable”, function(n)
local d = {“CHudHealth”,“CHudBattery”} --So on so fourth
for k,v in pairs(d) do
if v == n then
return end
end
end
end)[/lua]

And I don’t have any “print” lines…