Calling a function from another file - N00B Question
2 replies, posted
Hello!
I have created a HUD on a file called "HUD.lua", my question is how would I actually make it work? As in, how would I call it in the cl_init/init files to draw the HUD on the player's screen.
Here is my code for HUD.lua:
[CODE]function myhud()
local client = LocalPlayer()
draw.RoundedBox(3, 5, 5, 200, 100, Color(51, 58, 51, 255))
draw.SimpleText(client:Health() .. "%", "ScoreboardText", 100, 50, Color(86, 104, 86, 255), 0, 0)
local mag_left = client:GetActiveWeapon():Clip1()
local mag_extra = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType())
local secondary_ammo = client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType())
end
hook.Add("HUDPaint", "myhud", myhud)
local tohide = {
["CHudHealth"] = true,
["CHudBattery"] = true,
["CHudAmmo"] = true,
["CHudSecondaryAmmo"] = true
}
local function HUDShouldDraw(name)
if (tohide[name]) then
return false;
end
end
hook.Add("HUDShouldDraw", "hidehud", HUDShouldDraw)
[/CODE]
All other files are the default files needed, setup found over at [url]http://wiki.garrysmod.com/page/Gamemode_Creation[/url]
Thanks,
Safixk
If you are creating your own gamemode, just put this into beginning of your cl_init.lua
[code]
include("HUD.lua")
[/code]
And this into your init.lua
[code]AddCSLuaFile("HUD.lua")[/code]
[QUOTE=Robotboy655;42266743]If you are creating your own gamemode, just put this into beginning of your cl_init.lua
[code]
include("HUD.lua")
[/code]
And this into your init.lua
[code]AddCSLuaFile("HUD.lua")[/code][/QUOTE]
I didn't fail that hard. I actually just did the exact opposite of this.
Thanks, it's working now.
Sorry, you need to Log In to post a reply to this thread.