How to add new HUD elements
This took me hours to work out, so I'm posting it.
Your first thought when trying to add new HUD elements would be to override a function in the relevant GUI class, but this fails because the classes themselves don't exist until the player spawns (<3 loosely-typed languages) but your scripts run when the map starts. The best solution I've found is to hook into GUIManager:CreateGUIScript instead and check the name of each script which is created.
Here is a function which adds a new text item to the marine HUD:
Your first thought when trying to add new HUD elements would be to override a function in the relevant GUI class, but this fails because the classes themselves don't exist until the player spawns (<3 loosely-typed languages) but your scripts run when the map starts. The best solution I've found is to hook into GUIManager:CreateGUIScript instead and check the name of each script which is created.
Here is a function which adds a new text item to the marine HUD:
local base_CreateGUIScript = GUIManager.CreateGUIScript
function GUIManager:CreateGUIScript(scriptName)
script = base_CreateGUIScript(self,scriptName)
if (scriptName == "Hud/Marine/GUIMarineHUD") then
script.testString = script:CreateAnimatedTextItem()
script.testString:SetFontName(GUIMarineHUD.kTextFontName)
script.testString:SetLayer(kGUILayerPlayerHUDForeground1)
script.testString:SetColor(Color(1,1,1,1))
script.testString:SetText("TEST TEXT")
script.testString:SetPosition(Vector(100, 400, 0))
script.background:AddChild(script.testString)
end
return script
endMake sure this is only running on the client, obviously!
Comments