Hi all,
at the moment i am quite new at gmod lua and i am making a suit for my server, i have got the suit working well and when i click e on it, it will set my health and armor to 1000, this it just for testing, it will be changed later but i just need to know how i can show some text at the top of my screen for the time that i have the suit and i want it to disapear when i die/drop the suit
https://files.facepunch.com/forum/upload/397479/ce73d09b-c281-48cb-9871-c54392c8e465/image.png
This is my init.lua
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function ENT:Initialize()
self:SetModel("models/items/item_item_crate.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:Wake()
end
end
function ENT:Use(act,call)
act:SetHealth(1000)
act:SetArmor(1000)
self:Remove()
end
shared.lua
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Tier 1 Suit"
ENT.Spawnable = true
and cl_init.lua
include("shared.lua")
surface.CreateFont( "font", {
font = "Arial", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
extended = false,
size = 50,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
function ENT:Draw()
self:DrawModel()
local pos = self:GetPos()
local ang = self:GetAngles()
ang.y = LocalPlayer():EyeAngles().y - 90
cam.Start3D2D(Vector(pos.x,pos.y,pos.z+40),Angle(0,ang.y,90),0.3)
draw.RoundedBox(0,-60,0,120,50,Color(0,0,0,190))
draw.SimpleText("Tier 1","font",1,1,Color(255,255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_TOP)
cam.End3D2D()
end
You could use a NWBool and a value that you can check so you can show or hide the hud.
Entity/SetNWBool
-- code for use function
ply:SetNWBool("hasSuit", true)
-- code for hud
if ply:GetNWBool("hasSuit") then Hud code end
-- on player death
ply:SetNWBool("hasSuit", false)
thanks zippy, that was helpful to set the var but i dont know how to draw the hud inside of an entity, i have tried adding this to my cl_init.lua
surface.CreateFont( "font", {
font = "Arial", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
extended = false,
size = 50,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
hook.Add( "HUDPaint", "Text", function()
draw.SimpleText("Tier 1",font,ScrW()/w,ScrH()/2,Color(0,0,0),TEXT_ALIGN_LEFT,TEXT_ALIGN_TOP)
end )
but i just cant seem to get it to draw it, the only way i have been able to get it to do that is by removing everything that mentions 'ENT' and then doing lua_openscript_cl entities/suit/cl_init.lua
The hud would go in a different file.
The file structure should look something like this.
addon>
lua>
autorun>
cl_hud.lua
entities>
myent>
init.lua
cl_init.lua
shared.lua
And then at the hud file would look like this
AddCSLuaFile()
surface.CreateFont( "font", {
font = "Arial", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
extended = false,
size = 50,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
hook.Add( "HUDPaint", "Text", function()
-- check if the bool is true or false here then draw the text
draw.SimpleText("Tier 1",font,ScrW()/w,ScrH()/2,Color(0,0,0),TEXT_ALIGN_LEFT,TEXT_ALIGN_TOP)
end )
hey, i was running my addon in the garrysmod/garrysmod/lua/entities folder and now i have moved it to it own folder and it isnt showing up in the q menu
here is the folder structure of mine
addons
suits
lua
entities
tier1
cl_init.lua
shared.lua
init.lua
autorun
cl_hud.lua
all the code is the same as in the first post, please help
Weird it seems to be working for me are you sure your file structure looks like this?
https://i.imgur.com/NNU4bfR.png
also in shared.lua you can add this and it will make its own thing in the entities tab.
ENT.Category = "Suits"
nvm i had to restart my game and it is working now but i cant seem to modify the font size
I have tried calling it hud and still got the error, I can upload my files if you would like
autorun/client/cl_hud.lua: You don't need to AddCSLuaFile() in autorun, also change in text Default to "Default", because function require string for font
entities/tier1/cl_init.lua: Change "font" to "Tier1Font"
Found the issue a few days ago but forgot to post it, i forgot to put quotes around my font name
Sorry, you need to Log In to post a reply to this thread.