I'm really startingout with Glua, i use the wiki beginner tutorials and stuff.
I need some help making a Console Command, That paints to the top left of my screen "WARTIME" for my MilitaryRP. Here's what i've done so far
concommand.Add( "waraddon_war", function( ply )
if ply:IsValid() and ply:IsSuperAdmin() then
draw.SimpleText( "WARTIME", "DermaLarge", 12, 16, Color( 200, 0, 0 ), 0, 1 )
print("Command works")
end
if ply:IsUserGroup("user") then return end
end )
hook.Add("HUDPaint", "waraddon", function()
When i enter the command nothing happens, Anyone can help please i'd be grateful
of all your missing a bracket in hook.Add
your not putting any code into the hooks function (or your jutst not showing it)
change the ply:IsValid() and ply:IsSuperAdmin() to true, to see if it works then. If it does then you know that the if statements dont execute. Either because player isnt valid, or player isnt superadmin
Ok after changhing the code to this
concommand.Add("waraddon_war", function( ply )
if ply:IsValid() and ply:IsSuperAdmin() then
draw.SimpleText( "WARTIME", "DermaLarge", 12, 16, Color( 200, 0, 0 ), 0, 1 )
print("Command works")
end if ply:IsUserGroup("user") then return end
end )
hook.Add("HUDPaint", "waraddon", "waraddon")
1-It only prints "Command Works" for superadmins so the whole restriction thing is not an issue
2-But yeah still nothing happens after i execute this command
Sorry if i sound dumb as shit i really just started the whole lua thing 2 days ago
almost forgot. this needs to be nside a 2D hook. thats what the wiki tells you as well.
Just do
concommand.Add("waraddon_war", function( ply )
if ply:IsValid() and ply:IsSuperAdmin() then
hook.Add("HUDPaint", "idkaname", function()
draw.SimpleText( "WARTIME", "DermaLarge", 12, 16, Color( 200, 0, 0 ), 0, 1 )
end)
print("Command works")
end if ply:IsUserGroup("user") then return end
end )
hook.Add("HUDPaint", "waraddon", "waraddon")
otherwise the draw.simpletext that appear, because it is not inside a hook that renders it. You need to do hook.Remove again tho, so actually remove your simpletext. otherwise it will appear when doing the console command, but it will never disappear again. You could use a timer to remove it after a few seconds
Worked, Thanks a lot mate <3
You need to network it
No idea how to do that i'll just get a developer to do it. Thanks for the info again everyone
networking in gmod is super simple..it takes like 4 or 5 lines of code to make the text appear on every admins screen.
If you wanna pay a dev for that, sure. I`d love to do that job and finish it in less than 5 minutes.
You have to pay full price tho of course
I would heavily advise against using hook.Add every time you wish to draw your hud. Instead create it once outside of all code blocks and use a variable to determine if your hud should be drawn. (Side note: For functions with global variables like draw.SimpleText, its good practice to use the corresponding variables over their “decimal value” as shown in little example) Just know that with this particular setup, the hud will be disabled every time you save the file assuming you didn’t disable the whole lua live reload or whatever it’s called.
local shouldDraw = false
concommand.Add("waraddon_war", function( ply )
if ply:IsValid() and ply:IsSuperAdmin()
shouldDraw = not shouldDraw
print("Command works")
end
end )
hook.Add("HUDPaint", "waraddon", function()
if not shouldDraw then return end
draw.SimpleText("WARTIME", "DermaLarge", 12, 16, Color( 200, 0, 0 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
end)
Sorry, you need to Log In to post a reply to this thread.