forked from Derek-G1/Hide-Map-in-Rust-Game-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobs-map-hide.lua
More file actions
132 lines (114 loc) · 4.1 KB
/
obs-map-hide.lua
File metadata and controls
132 lines (114 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
obs = obslua
-- Script properties
local source_name = ""
local hotkey_id = obs.OBS_INVALID_HOTKEY_ID
local hotkey_id_shift = obs.OBS_INVALID_HOTKEY_ID
local check_attempts = 0
local MAX_ATTEMPTS = 5
-- Upvalues to track hotkey and overlay state
local hotkey_active = false
local overlay_active = false
local timer_count = 0
local timer_delay_ms = 250
local timer_is_running = false
-- Function to print to the OBS script log
function debug_log(message)
print(message)
end
-- Function to show/hide the source
function set_visibility(visible)
local source = obs.obs_get_source_by_name(source_name)
if source ~= nil then
obs.obs_source_set_enabled(source, visible)
debug_log(string.format("Source '%s' visibility set to %s", source_name, tostring(visible)))
obs.obs_source_release(source)
return true
else
debug_log(string.format("ERROR: Could not find source '%s'", source_name))
return false
end
end
-- Timer callback for delayed overlay removal
function disable_overlay()
if hotkey_active then
timer_count = 0
elseif timer_count < 1 then
timer_count = timer_count + 1
else
set_visibility(false)
overlay_active = false
timer_count = 0
timer_is_running = false
debug_log("Timer lapsed - hiding source")
obs.timer_remove(disable_overlay)
end
end
-- Callback for key press/release
function on_hotkey(pressed)
if pressed then
hotkey_active = true
if not overlay_active then
overlay_active = true
set_visibility(true)
-- Only start a new timer if one isn't already running
if not timer_is_running then
timer_is_running = true
obs.timer_add(disable_overlay, timer_delay_ms)
end
debug_log("Hotkey pressed - showing source")
end
else
hotkey_active = false
debug_log("Hotkey released")
end
end
function script_description()
return [[Map Cover Script for Rust
Shows an image when G or Shift+G is held, hides it when released.
Setup:
1. Enter the exact name of your image source below
2. Configure hotkeys in OBS Settings -> Hotkeys
3. Make sure the image is hidden by default]]
end
function script_properties()
local props = obs.obs_properties_create()
obs.obs_properties_add_text(props, "source", "Image Source Name", obs.OBS_TEXT_DEFAULT)
return props
end
function script_update(settings)
source_name = obs.obs_data_get_string(settings, "source")
debug_log(string.format("Source name updated to '%s'", source_name))
-- Immediately check if source exists
local source = obs.obs_get_source_by_name(source_name)
if source ~= nil then
debug_log("Source found successfully")
obs.obs_source_release(source)
set_visibility(false) -- Ensure it starts hidden
else
debug_log("WARNING: Source not found!")
end
end
function script_load(settings)
debug_log("Script loading...")
-- Register hotkeys
hotkey_id = obs.obs_hotkey_register_frontend("map_cover_g", "Show Map Cover (Hold G)", on_hotkey)
hotkey_id_shift = obs.obs_hotkey_register_frontend("map_cover_shift_g", "Show Map Cover (Hold Shift+G)", on_hotkey)
-- Load saved hotkey data
local htdata = obs.obs_data_get_array(settings, "htkey_g")
obs.obs_hotkey_load(hotkey_id, htdata)
obs.obs_data_array_release(htdata)
local htdata_shift = obs.obs_data_get_array(settings, "htkey_shift_g")
obs.obs_hotkey_load(hotkey_id_shift, htdata_shift)
obs.obs_data_array_release(htdata_shift)
script_update(settings)
debug_log("Script loaded successfully - configure hotkeys in Settings -> Hotkeys")
end
function script_save(settings)
-- Save hotkey data
local htdata = obs.obs_hotkey_save(hotkey_id)
obs.obs_data_set_array(settings, "htkey_g", htdata)
obs.obs_data_array_release(htdata)
local htdata_shift = obs.obs_hotkey_save(hotkey_id_shift)
obs.obs_data_set_array(settings, "htkey_shift_g", htdata_shift)
obs.obs_data_array_release(htdata_shift)
end