-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera Flash.lua
More file actions
143 lines (110 loc) · 4.09 KB
/
Camera Flash.lua
File metadata and controls
143 lines (110 loc) · 4.09 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
133
134
135
136
137
138
139
140
141
142
143
--[[
>>> Camera Flash Event for Psych Engine.
Flashes the screen with a specified colour and duration on a chosen camera object
Compatible with Psych Engine 0.5.x, 0.6.x, 0.7.X, 1.0.x
* Supports all parameters for the built-in cameraFlash function.
* Supports RGB and HEX as colour input or 'random' for random colour.
* Only triggers if Flashing Lights are enabled.
* Includes basic debugging output.
Script by AutisticLulu.
Usage:
Value 1:
Camera [camGame/camHUD/camOther], forced? [true/false]
(Example: camHUD, true)
Value 2:
Colour [HEX], Duration [Seconds]
(Example: 9DCFED, 4)
Colour [RGB], Duration [Seconds]
(Example: 157, 207, 237, 4)
If no camera is specified, it defaults to "defaultCamera"
If no bool is specified, it defaults to "defaultForced"
If no colour is specified, it defaults to "defaultColour"
If no duration is specified, it defaults to "defaultDuration"
]]
-- #####################################################################
-- [[ Setting Variables ]]
-- Users can modify these variables freely.
-- #####################################################################
local enableDebug = false
local validCameras = {
camGame = true,
camHUD = true,
camOther = true
}
local defaultCamera = "camGame"
local defaultForced = false
local defaultColour = "FFFFFF"
local defaultDuration = 1
-- #####################################################################
-- [[ Custom Functions ]]
-- #####################################################################
-- Converts each RGB value to hexadecimal
local function rgbToHex(r, g, b)
r = math.max(0, math.min(255, r))
g = math.max(0, math.min(255, g))
b = math.max(0, math.min(255, b))
return string.format("%02X%02X%02X", r, g, b)
end
-- Validates hex colour format
local function isValidHex(hex)
return #hex == 6 and not hex:find("[^0-9A-Fa-f]")
end
-- Parses the camera and forced value from the input string
local function parseCameraValue(value)
if not value or value == "" then
return defaultCamera, defaultForced
end
local cleanValue = value:gsub(" ", "")
local camera, forcedStr = string.match(cleanValue, "([^,]+),(%a+)")
if camera and validCameras[camera] then
return camera, forcedStr == "true"
end
return defaultCamera, defaultForced
end
-- Parses the colour and duration from the input string
local function parseFlashValue(value)
if not value or value == "" then
return defaultColour, defaultDuration
end
local cleanValue = value:gsub(" ", "")
local parts = {}
for part in string.gmatch(cleanValue, "[^,]+") do
table.insert(parts, part)
end
if #parts < 2 then
return defaultColour, defaultDuration
end
local duration = tonumber(parts[#parts]) or defaultDuration
-- Handle 'random' colour
if parts[1]:lower() == "random" then
return rgbToHex(math.random(0, 255), math.random(0, 255), math.random(0, 255)), duration
end
-- Handle RGB (3 parts + duration)
if #parts == 4 then
local r, g, b = tonumber(parts[1]), tonumber(parts[2]), tonumber(parts[3])
if r and g and b then
return rgbToHex(r, g, b), duration
end
end
-- Handle HEX (1 part + duration)
return parts[1], duration
end
-- #####################################################################
-- [[ Bind our local functions to Psych Engine events ]]
-- #####################################################################
function onEvent(name, value1, value2)
if (name == "Camera Flash" or name == "Camera_Flash") and flashingLights then
local camera, isForced = parseCameraValue(value1)
local colour, duration = parseFlashValue(value2)
-- Debug output if enabled
if enableDebug then
debugPrint("Camera Flash Event Triggered:")
debugPrint(" Camera: " .. camera .. " | Forced: " .. tostring(isForced))
debugPrint(" Colour: " .. colour .. " | Duration: " .. duration)
if not isValidHex(colour) then
debugPrint(" WARNING: Invalid hex colour format (expected 6 hex characters)")
end
end
cameraFlash(camera, colour, duration, isForced)
end
end