Skip to content

Commit

Permalink
Added script to initialize on sv_allowcslua servers with the weapon s…
Browse files Browse the repository at this point in the history
…witcher working
  • Loading branch information
DyaMetR committed Apr 16, 2023
1 parent 484e475 commit 4496a66
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 66 deletions.
81 changes: 53 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# H0L-D4
# H0L-D4: Holographic Heads Up Display

![](https://img.shields.io/github/v/release/DyaMetR/holohud)
![](https://img.shields.io/steam/views/1705992410)
![](https://img.shields.io/steam/downloads/1705992410)
![](https://img.shields.io/steam/favorites/1705992410)
![](https://img.shields.io/github/issues/DyaMetR/holohud)
![](https://img.shields.io/github/license/DyaMetR/holohud)

Customizable holographic themed heads up display (HUD) for Garry's Mod.

# Features
## Features

+ HUD swaying with camera movement
+ Chromatic aberration
+ Health indicator
Expand All @@ -22,14 +31,16 @@ Customizable holographic themed heads up display (HUD) for Garry's Mod.
+ Target ID
+ Welcome screen

# Customization includes
## Customization includes

+ Each elements has their own array of options
+ Font family and offsets customization
+ Blur intensity and opacity
+ Background opacity
+ Swaying

# Credits
## Credits

+ *DyaMetR*
+ Design
+ Code
Expand All @@ -40,19 +51,23 @@ Customizable holographic themed heads up display (HUD) for Garry's Mod.
+ *code_gs*
+ [Weapon selector skeleton](https://github.com/Kefta/Weapon-Switcher-Skeleton)

# Adding custom content
## Setup your configuration folder
## Adding custom content

### Setup your configuration folder

To ensure that your configuration _loads correctly_, you'll have to make a **folder** inside your **addons** folder with a specific structure: `%YOUR_CONFIG_ADDON_FOLDER%/lua/autorun/holohud/add-ons`.

Once you created your folder you'll be able to add as many `.lua` files as you wish and the HUD will load them all. Try to use **unique file names** in order to avoid conflicts with other addons.

## Before you start writing code
### Before you start writing code

All of the custom files are loaded **shared**wise, meaning that it will work in both clientside and serverside, so I'd like to remind using `if CLIENT` and `if SERVER` respectively.

## Utilizing the API
### Utilizing the API

H0L-D4 offers an ample API, but I will only list the most important functions, which are those in charge of adding elements and forcing settings.

### Add element override
#### Add element override

`HOLOHUD.GAMEMODE:AddElementOverride( gamemode, elements )`
> **CLIENT**
Expand Down Expand Up @@ -85,7 +100,7 @@ HOLOHUD.GAMEMODE:AddElementOverride( { 'sandbox', 'darkrp' }, 'prop_count' )

```

### Set element override
#### Set element override

`HOLOHUD.GAMEMODE:SetElementOverride( gamemode, elements, whitelist )`
> **CLIENT**
Expand Down Expand Up @@ -117,7 +132,7 @@ HOLOHUD.GAMEMODE:SetElementOverride( 'terrortown', { 'health', 'ammunition', 'tt
HOLOHUD.GAMEMODE:SetElementOverride( { 'darkrp', 'terrortown' }, 'target_id' )
```

## Add element configuration override
### Add element configuration override

`HOLOHUD.GAMEMODE:AddConfigOverride( gamemode, element, config, force_default )`
> **CLIENT**
Expand Down Expand Up @@ -150,40 +165,50 @@ HOLOHUD.GAMEMODE:AddConfigOverride( 'terrortown', 'ammunition', { mode = 3 }, tr

```

### Cheat sheet for element's modes
#### Health
#### Cheat sheet for element's modes

##### Health

```
1 = Default
2 = Heartbeat with armour bar
3 = Heartbeat with kevlar icon
4 = Classic
```
#### Ammunition

##### Ammunition

```
1 = Default
2 = Minimalist
3 = Compact
```
#### Clock

##### Clock

```
1 = Simple
2 = Digital
3 = Simple with date
```
#### Speed-o-meter (units for both in foot and in vehicle)

##### Speed-o-meter (units for both in foot and in vehicle)

```
1 = km/h
2 = mph
3 = ups
```
#### Auxiliary power (for both the aux. power and the ep2 flashlight)

##### Auxiliary power (for both the aux. power and the ep2 flashlight)

```
1 = Default
2 = Icon with background
3 = Icon only
```

## Setup panel
### Setup panel

"Panels" are the rectangles used as background to draw stuff. They can be opened or closed, which will play an animation in the process.

Expand All @@ -205,7 +230,7 @@ Example:
HOLOHUD:AddFlashPanel( 'out_of_ammo' )
```

## Open/close a panel
### Open/close a panel

`HOLOHUD:SetPanelActive( panel, active, force )`

Expand Down Expand Up @@ -237,7 +262,7 @@ local function TriggerOutOfAmmoPanel()
end
```

## Draw panel with contents
### Draw panel with contents

`HOLOHUD:DrawFragmentAlignSimple( x, y, w, h, func, flash, align, ... )`
> **CLIENT**
Expand Down Expand Up @@ -283,7 +308,7 @@ local function DrawPanel( y )
end
```

## Draw panel with contents (with additional parameters)
### Draw panel with contents (with additional parameters)

`HOLOHUD:DrawFragmentAlign( x, y, w, h, func, flash, align, colour, alpha, blurQuality, ... )`
> **CLIENT**
Expand Down Expand Up @@ -337,7 +362,7 @@ local function DrawPanel( y )
end
```

## Add a number/text/texture highlighting
### Add a number/text/texture highlighting

"Highlighting" refers to when a number/text/texture brights for a while and then goes back to normal.

Expand All @@ -353,7 +378,7 @@ Example:
HOLOHUD:AddHighlight( 'out_of_ammo' )
```

## Trigger a number/text/texture highlighting
### Trigger a number/text/texture highlighting

`HOLOHUD:TriggerHighlight( id )`
> **CLIENT**
Expand Down Expand Up @@ -383,7 +408,7 @@ local function AnimateHighlight()
end
```

## Get a highlight value
### Get a highlight value

`HOLOHUD:GetHighlight( id )`
> **CLIENT**
Expand All @@ -401,7 +426,7 @@ print( HOLOHUD:GetHighlight( 'out_of_ammo' ) )

Result: `0`

## Draw a number
### Draw a number

`HOLOHUD:DrawNumber( x, y, number, colour, zeros, bright, font, off, align, vertical_align )`
> **CLIENT**
Expand Down Expand Up @@ -436,7 +461,7 @@ Example:
HOLOHUD:DrawNumber( ScrW() * .25, ScrH() * .5, LocalPlayer():Health(), Color( 255, 100, 100 ), '0000', HOLOHUD:GetHighlight('health'), 'holohud_main', false, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER )
```

## Draw text
### Draw text

`HOLOHUD:DrawText(x, y, text, font, colour, bright, align, vertical_align, off, alpha)`
> **CLIENT**
Expand Down Expand Up @@ -471,7 +496,7 @@ Example:
HOLOHUD:DrawText( ScrW() * .5, ScrH() * .25, LocalPlayer():Name(), 'holohud_small', Color( 100, 255, 100 ), HOLOHUD:GetHighlight('health'), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, false, 150 )
```

## Add an element
### Add an element

`HOLOHUD.ELEMENTS:AddElement( id, title, subtitle, hide_elements, default_config, draw_function, enabled )`
> **CLIENT**
Expand Down Expand Up @@ -520,7 +545,7 @@ HOLOHUD.ELEMENTS:AddElement('out_of_ammo',
)
```

## 'Out of ammo' element full example
### 'Out of ammo' element full example
```lua
if CLIENT then

Expand Down
14 changes: 7 additions & 7 deletions lua/autorun/holohud.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
--[[------------
H0L-D4
Version 1.10.4
12/08/22
By DyaMetR
]]--------------
--[[------------------------------------------------------------------
H0L-D4: Holographic Heads Up Display
Version 1.10.5
April 16th, 2023
Made by DyaMetR
]]--------------------------------------------------------------------

-- Main framework table
HOLOHUD = {};

-- Version and patch notes
HOLOHUD.Version = {
Major = 1, Minor = 10, Patch = 4
Major = 1, Minor = 10, Patch = 5
};

--[[
Expand Down
64 changes: 33 additions & 31 deletions lua/autorun/holohud/util/bind_press.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
--[[------------------------------------------------------------------
DyaMetR's unintrusive key bind press
September 17th, 2021
April 16th, 2023
Custom KeyBindPress hook used by HUDs that want to ease compatibility
by giving priority to any other addon.
]]--------------------------------------------------------------------

if SERVER then return end -- do not run on server

local version = 1 -- current version of the bind press replacer
local version = 2 -- current version of the bind press replacer

-- check whether there's a newer version of this script
if UnintrusiveBindPress and UnintrusiveBindPress.version >= version then return end
Expand All @@ -19,6 +16,36 @@ if not UnintrusiveBindPress then UnintrusiveBindPress = { hooks = {}, priorities
-- update version
UnintrusiveBindPress.version = version

--[[------------------------------------------------------------------
Replaces the PlayerBindPress hook, initializing our system.
]]--------------------------------------------------------------------
function UnintrusiveBindPress.init()
-- do not replace again
if not UnintrusiveBindPress.bindPress then
UnintrusiveBindPress.bindPress = GAMEMODE.PlayerBindPress -- get original bind press
end

-- create a replacement function
GAMEMODE.PlayerBindPress = function(self, _player, bind, pressed, code)
-- go through each priority in order
for priority, hooks in pairs(UnintrusiveBindPress.priorities) do
-- go through each hook without order
for _, func in pairs(hooks) do
-- run hook
local result = func(_player, bind, pressed, code)

-- if this hook has returned a value, override the rest
if result ~= nil then
return result
end
end
end

-- call original function
return UnintrusiveBindPress.bindPress(self, _player, bind, pressed, code)
end
end

--[[------------------------------------------------------------------
Adds an unintrusive bind press hook
@param {string} id
Expand Down Expand Up @@ -68,29 +95,4 @@ function UnintrusiveBindPress.getTable(priority)
end

-- do hook replace upon initializing every script
hook.Add('PostGamemodeLoaded', 'unintrusive_bind_press', function()
-- do not replace again
if not UnintrusiveBindPress.bindPress then
UnintrusiveBindPress.bindPress = GAMEMODE.PlayerBindPress -- get original bind press
end

-- create a replacement function
GAMEMODE.PlayerBindPress = function(self, _player, bind, pressed, code)
-- go through each priority in order
for priority, hooks in pairs(UnintrusiveBindPress.priorities) do
-- go through each hook without order
for _, func in pairs(hooks) do
-- run hook
local result = func(_player, bind, pressed, code)

-- if this hook has returned a value, override the rest
if result ~= nil then
return result
end
end
end

-- call original function
return UnintrusiveBindPress.bindPress(self, _player, bind, pressed, code)
end
end)
hook.Add('PostGamemodeLoaded', 'unintrusive_bind_press', UnintrusiveBindPress.init)
13 changes: 13 additions & 0 deletions lua/holohud_init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--[[------------------------------------------------------------------
Manual initialization script.
Run this if you're on a server that allows sv_allowcslua.
WARNING: The following features will NOT work since they require
the server-side part of the HUD to run, and it won't.
- Damage indicator
- Hazard icons
]]--------------------------------------------------------------------

if SERVER then return end

include('autorun/holohud.lua') -- initialize HUD
UnintrusiveBindPress.init() -- manually initialize bind press

0 comments on commit 4496a66

Please sign in to comment.