Skip to content

Commit e5c3ac1

Browse files
committed
command part update, property stuff, luapad
add "jump to" option on proxy-affected properties and part reference properties, to navigate to the relevant part directly add reset to booleans, font-related fix for the label resizes the label for when using large enough fonts add apply size to scales option (for models, sprites) to normalize size to 1 generic multiline text panel for notes code panels for commands and proxies, derived from the luapad used in the hidden script part command part features: most of these are to reduce event load and duplicate parts -OnHide command string -Delayed command string -pac_event presets for both mainline pac_events and pac_event_sequenced. Random mode will replace lua command randomizers (people have consistently brought up the issue that cs lua is not allowed on many servers) -Dynamic mode: run a command repeatedly when the appended number is changed (e.g. for post-processing gradual fading) -Safe Guard: option to delay execution by 1 frame in order to attempt to fix certain specific event logic issues, thereby preventing false triggers. a lua timer is probably better than timerx events constantly running
1 parent 67ba395 commit e5c3ac1

File tree

5 files changed

+749
-19
lines changed

5 files changed

+749
-19
lines changed

lua/pac3/core/client/base_part.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ BUILDER
3131
:StartStorableVars()
3232
:SetPropertyGroup("generic")
3333
:GetSet("Name", "")
34-
:GetSet("Notes", "")
34+
:GetSet("Notes", "", {editor_panel = "generic_multiline"})
3535
:GetSet("Hide", false)
3636
:GetSet("EditorExpand", false, {hidden = true})
3737
:GetSet("UniqueID", "", {hidden = true})
@@ -1323,7 +1323,7 @@ function PART:SetupEditorPopup(str, force_open, tbl, x, y)
13231323
end
13241324
if not pnl then
13251325
pnl = pac.InfoPopup(info_string,popup_config_table, x, y)
1326-
self.pace_tree_node.popupinfopnl = pnl
1326+
if IsValid(self.pace_tree_node) then self.pace_tree_node.popupinfopnl = pnl end
13271327
end
13281328
if pace then
13291329
pace.legacy_floating_popup_reserved = pnl

lua/pac3/core/client/parts/command.lua

Lines changed: 142 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,43 @@ PART.Group = "advanced"
66
PART.Icon = "icon16/application_xp_terminal.png"
77

88
BUILDER:StartStorableVars()
9-
BUILDER:GetSet("String", "", {editor_panel = "string"})
9+
10+
BUILDER:SetPropertyGroup("generic")
11+
BUILDER:GetSet("String", "", {editor_panel = "code_script"})
1012
BUILDER:GetSet("UseLua", false)
1113
BUILDER:GetSet("ExecuteOnWear", false)
1214
BUILDER:GetSet("ExecuteOnShow", true)
15+
BUILDER:GetSet("SafeGuard", false, {description = "Delays the execution by 1 frame to attempt to prevent false triggers due to events' runtime quirks"})
16+
17+
--fading re-run mode
18+
BUILDER:SetPropertyGroup("dynamic mode")
19+
BUILDER:GetSet("DynamicMode", false, {description = "Dynamically assign an argument, adding the appended number to the string.\nWhen the appended number is changed, run the command again.\nFor example, it could be used with post processing fades. With pp_colormod 1, pp_colormod_color represents saturation multiplier. You could fade that to slowly fade to gray."})
20+
BUILDER:GetSet("AppendedNumber", 1, {description = "Argument to use. When it changes, the command will run again with the updated value."})
21+
22+
--common alternate activations
23+
BUILDER:SetPropertyGroup("alternates")
24+
BUILDER:GetSet("OnHideString", "", {description = "An alternate command when the part is hidden. Governed by execute on show", editor_panel = "code_script"})
25+
BUILDER:GetSet("DelayedString", "", {description = "An alternate command after a delay. Governed by execute on show", editor_panel = "code_script"})
26+
BUILDER:GetSet("Delay", 1)
27+
28+
--we might as well have a section for command events since they are so useful for logic, and often integrated with command parts
29+
--There should be a more convenient front-end for pac_event stuff and to fix the issue where people want to randomize their command (e.g. random attacks) when cs lua isn't allowed on some servers.
30+
BUILDER:SetPropertyGroup("pac_event")
31+
BUILDER:GetSet("CommandName", "", {description = "name of the pac_event to manage, or base name of the sequenced series.\n\nfor example, if you have commands hat1, hat2, hat3, and hat4:\n-the base name is hat\n-the minimum is 1\n-the maximum is 4"})
32+
BUILDER:GetSet("Action", "Default", {enums = {
33+
["Default: single-shot"] = "Default",
34+
["Default: On (1)"] = "On",
35+
["Default: Off (0)"] = "Off",
36+
["Default: Toggle (2)"] = "Toggle",
37+
["Sequence: forward"] = "Sequence+",
38+
["Sequence: back"] = "Sequence-",
39+
["Sequence: set"] = "SequenceSet",
40+
["Random"] = "Random",
41+
["Random (Sequence set)"] = "RandomSet",
42+
}, description = "The Default series corresponds to the normal pac_event command modes. Minimum and maximum don't apply.\nSequences run the sequence command pac_event_sequenced with the corresponding mode.\nRandom will select a random number to append to the base name and run the pac_event as a single-shot. This is intended to replace the lua randomizer method when sv_allowcslua is disabled."})
43+
BUILDER:GetSet("Minimum", 1, {description = "The defined minimum for the pac_event if it's for a numbered series.\nOr, when using the sequence set action, this will be used.", editor_onchange = function(self, val) return math.floor(val) end})
44+
BUILDER:GetSet("Maximum", 1, {description = "The defined maximum for the pac_event if it's for a numbered series.", editor_onchange = function(self, val) return math.floor(val) end})
45+
1346
BUILDER:EndStorableVars()
1447

1548
local sv_allowcslua = GetConVar("sv_allowcslua")
@@ -23,13 +56,54 @@ function PART:OnWorn()
2356
end
2457
end
2558

59+
function PART:SetMaximum(val)
60+
self.Maximum = val
61+
if self:GetPlayerOwner() == pac.LocalPlayer and self.CommandName ~= "" and self.Minimum ~= self.Maximum then
62+
self:GetPlayerOwner():ConCommand("pac_event_sequenced_force_set_bounds " .. self.CommandName .. " " .. self.Minimum .. " " .. self.Maximum)
63+
end
64+
end
65+
66+
function PART:SetMinimum(val)
67+
self.Minimum = val
68+
if self:GetPlayerOwner() == pac.LocalPlayer and self.CommandName ~= "" and self.Minimum ~= self.Maximum then
69+
self:GetPlayerOwner():ConCommand("pac_event_sequenced_force_set_bounds " .. self.CommandName .. " " .. self.Minimum .. " " .. self.Maximum)
70+
end
71+
end
72+
73+
function PART:SetAppendedNumber(val)
74+
if self.AppendedNumber ~= val then
75+
self.AppendedNumber = val
76+
if self:GetPlayerOwner() == pac.LocalPlayer and self.DynamicMode then
77+
self:Execute()
78+
end
79+
end
80+
self.AppendedNumber = val
81+
end
82+
2683
function PART:OnShow(from_rendering)
27-
if pace.still_loading_wearing then return end
2884
if not from_rendering and self:GetExecuteOnShow() then
29-
timer.Simple(0, function()
30-
if self.Hide or self:IsHidden() then return end
85+
if pace.still_loading_wearing then return end
86+
87+
if self.SafeGuard then
88+
timer.Simple(0,function()
89+
if self.Hide or self:IsHidden() then return end
90+
self:Execute()
91+
end)
92+
else
3193
self:Execute()
32-
end)
94+
end
95+
96+
if self.DelayedString ~= "" then
97+
timer.Simple(self.Delay, function()
98+
self:Execute(self.DelayedString)
99+
end)
100+
end
101+
end
102+
end
103+
104+
function PART:OnHide()
105+
if self.ExecuteOnShow and self.OnHideString ~= "" then
106+
self:Execute(self.OnHideString)
33107
end
34108
end
35109

@@ -62,10 +136,31 @@ function PART:GetNiceName()
62136
if self.UseLua then
63137
return ("lua: " .. self.String)
64138
end
139+
if self.String == "" and self.CommandName ~= "" then
140+
if self.Action == "Default" then
141+
return "pac_event " .. self.CommandName
142+
elseif self.Action == "On" then
143+
return "pac_event " .. self.CommandName .. " 1"
144+
elseif self.Action == "Off" then
145+
return "pac_event " .. self.CommandName .. " 0"
146+
elseif self.Action == "Toggle" then
147+
return "pac_event " .. self.CommandName .. " 2"
148+
elseif self.Action == "Sequence+" then
149+
return "pac_event_sequenced " .. self.CommandName .. " +"
150+
elseif self.Action == "Sequence-" then
151+
return "pac_event_sequenced " .. self.CommandName .. " -"
152+
elseif self.Action == "SequenceSet" then
153+
return "pac_event_sequenced " .. self.CommandName .. " set " .. self.Minimum .. "[bounds:" .. self.Minimum .. ", " .. self.Maximum .."]"
154+
elseif self.Action == "Random" then
155+
return "pac_event " .. self.CommandName .. " <random:" .. self.Minimum .. ", " .. self.Maximum .. ">"
156+
elseif self.Action == "RandomSet" then
157+
return "pac_event_sequenced " .. self.CommandName .. " set " .. "<random:" .. self.Minimum .. "," .. self.Maximum .. ">"
158+
end
159+
end
65160
return "command: " .. self.String
66161
end
67162

68-
function PART:Execute()
163+
function PART:Execute(commandstring)
69164
local ent = self:GetPlayerOwner()
70165

71166
if ent == pac.LocalPlayer then
@@ -88,7 +183,47 @@ function PART:Execute()
88183
self:SetError("Concommand is blocked")
89184
return
90185
end
91-
ent:ConCommand(self.String)
186+
if self.String == "" and self.CommandName ~= "" then
187+
--[[
188+
["Default: single-shot"] = "Default",
189+
["Default: On (1)"] = "On",
190+
["Default: Off (0)"] = "Off",
191+
["Default: Toggle (2)"] = "Toggle",
192+
["Sequence: forward"] = "Sequence+",
193+
["Sequence: back"] = "Sequence-",
194+
["Sequence: set"] = "SequenceSet",
195+
["Random"] = "Random",
196+
["Random"] = "RandomSet",
197+
]]
198+
if self.Action == "Default" then
199+
ent:ConCommand("pac_event " .. self.CommandName)
200+
elseif self.Action == "On" then
201+
ent:ConCommand("pac_event " .. self.CommandName .. " 1")
202+
elseif self.Action == "Off" then
203+
ent:ConCommand("pac_event " .. self.CommandName .. " 0")
204+
elseif self.Action == "Toggle" then
205+
ent:ConCommand("pac_event " .. self.CommandName .. " 2")
206+
elseif self.Action == "Sequence+" then
207+
ent:ConCommand("pac_event_sequenced " .. self.CommandName .. " +")
208+
elseif self.Action == "Sequence-" then
209+
ent:ConCommand("pac_event_sequenced " .. self.CommandName .. " -")
210+
elseif self.Action == "SequenceSet" then
211+
ent:ConCommand("pac_event_sequenced " .. self.CommandName .. " set " .. self.Minimum)
212+
elseif self.Action == "Random" then
213+
local randnum = math.floor(math.Rand(self.Minimum, self.Maximum + 1))
214+
ent:ConCommand("pac_event " .. self.CommandName .. randnum)
215+
elseif self.Action == "RandomSet" then
216+
local randnum = math.floor(math.Rand(self.Minimum, self.Maximum + 1))
217+
ent:ConCommand("pac_event_sequenced " .. self.CommandName .. " set " .. randnum)
218+
end
219+
return
220+
end
221+
222+
if self.DynamicMode then
223+
ent:ConCommand(self.String .. " " .. self.AppendedNumber)
224+
return
225+
end
226+
ent:ConCommand(commandstring or self.String)
92227
end
93228
end
94229
end

lua/pac3/core/client/parts/proxy.lua

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ BUILDER:StartStorableVars()
3131
BUILDER:GetSet("MultipleTargetParts", "", {description = "send output to multiple external partss.\npaste multiple UIDs or names here, separated by semicolons. With bulk select, you can select parts and right click to get that done quickly.."})
3232
BUILDER:GetSetPart("OutputTargetPart", {hide_in_editor = true})
3333
BUILDER:GetSet("AffectChildren", false)
34-
BUILDER:GetSet("Expression", "", {description = "write math here. hit F1 for a tutorial or right click for examples."})
34+
BUILDER:GetSet("Expression", "", {description = "write math here. hit F1 for a tutorial or right click for examples.", editor_panel = "code_proxy"})
3535

3636
BUILDER:SetPropertyGroup("easy setup")
3737
BUILDER:GetSet("Input", "time", {enums = function(part) return part.Inputs end, description = "base (inner) function for easy setup\nin sin(time()) it is time"})
@@ -54,11 +54,11 @@ BUILDER:StartStorableVars()
5454

5555
BUILDER:SetPropertyGroup("extra expressions")
5656
BUILDER:GetSet("ExpressionOnHide", "", {description = "Math to apply once, when the proxy is hidden. It computes once, so it will not move."})
57-
BUILDER:GetSet("Extra1", "", {description = "Write extra math here.\nIt computes before the main expression and can be accessed from the main expression as extra1() or var1() to save space, or by another proxy as extra1(\"uid or name\") or var1(\"uid or name\")"})
58-
BUILDER:GetSet("Extra2", "", {description = "Write extra math here.\nIt computes before the main expression and can be accessed from the main expression as extra2() or var2() to save space, or by another proxy as extra2(\"uid or name\") or var2(\"uid or name\")"})
59-
BUILDER:GetSet("Extra3", "", {description = "Write extra math here.\nIt computes before the main expression and can be accessed from the main expression as extra3() or var3() to save space, or by another proxy as extra3(\"uid or name\") or var3(\"uid or name\")"})
60-
BUILDER:GetSet("Extra4", "", {description = "Write extra math here.\nIt computes before the main expression and can be accessed from the main expression as extra4() or var4() to save space, or by another proxy as extra4(\"uid or name\") or var4(\"uid or name\")"})
61-
BUILDER:GetSet("Extra5", "", {description = "Write extra math here.\nIt computes before the main expression and can be accessed from the main expression as extra5() or var5() to save space, or by another proxy as extra5(\"uid or name\") or var5(\"uid or name\")"})
57+
BUILDER:GetSet("Extra1", "", {description = "Write extra math here.\nIt computes before the main expression and can be accessed from the main expression as extra1() or var1() to save space, or by another proxy as extra1(\"uid or name\") or var1(\"uid or name\")", editor_panel = "code_proxy"})
58+
BUILDER:GetSet("Extra2", "", {description = "Write extra math here.\nIt computes before the main expression and can be accessed from the main expression as extra2() or var2() to save space, or by another proxy as extra2(\"uid or name\") or var2(\"uid or name\")", editor_panel = "code_proxy"})
59+
BUILDER:GetSet("Extra3", "", {description = "Write extra math here.\nIt computes before the main expression and can be accessed from the main expression as extra3() or var3() to save space, or by another proxy as extra3(\"uid or name\") or var3(\"uid or name\")", editor_panel = "code_proxy"})
60+
BUILDER:GetSet("Extra4", "", {description = "Write extra math here.\nIt computes before the main expression and can be accessed from the main expression as extra4() or var4() to save space, or by another proxy as extra4(\"uid or name\") or var4(\"uid or name\")", editor_panel = "code_proxy"})
61+
BUILDER:GetSet("Extra5", "", {description = "Write extra math here.\nIt computes before the main expression and can be accessed from the main expression as extra5() or var5() to save space, or by another proxy as extra5(\"uid or name\") or var5(\"uid or name\")", editor_panel = "code_proxy"})
6262
BUILDER:EndStorableVars()
6363

6464
-- redirect
@@ -1818,10 +1818,14 @@ local function set(self, part, x, y, z, children)
18181818
local math_description = "expression:\n"..self.Expression
18191819
if self.Expression == "" then math_description = "using " .. self.Function .. " and " .. self.Input end
18201820
if vector_type then
1821+
property_pnl.user_proxies = property_pnl.right.user_proxies or {}
1822+
property_pnl.user_proxies [self] = self
18211823
if self.using_x then
18221824
property_pnl.used_by_proxy = true
18231825
container = property_pnl.left
18241826
property_pnl.left.used_by_proxy = true
1827+
property_pnl.left.user_proxies = property_pnl.left.user_proxies or {}
1828+
property_pnl.left.user_proxies [self] = self
18251829
local num = x or 0
18261830
property_pnl.left:SetValue(math.Round(tonumber(num),4))
18271831
container:SetTooltip("LOCKED: Used by proxy:\n"..self:GetName().."\n\n" .. math_description)
@@ -1830,6 +1834,8 @@ local function set(self, part, x, y, z, children)
18301834
property_pnl.used_by_proxy = true
18311835
container = property_pnl.middle
18321836
property_pnl.middle.used_by_proxy = true
1837+
property_pnl.middle.user_proxies = property_pnl.middle.user_proxies or {}
1838+
property_pnl.middle.user_proxies [self] = self
18331839
local num = y or x or 0
18341840
property_pnl.middle:SetValue(math.Round(tonumber(num),4))
18351841
container:SetTooltip("LOCKED: Used by proxy:\n"..self:GetName().."\n\n" .. math_description)
@@ -1838,18 +1844,24 @@ local function set(self, part, x, y, z, children)
18381844
property_pnl.used_by_proxy = true
18391845
container = property_pnl.right
18401846
property_pnl.right.used_by_proxy = true
1847+
property_pnl.right.user_proxies = property_pnl.right.user_proxies or {}
1848+
property_pnl.right.user_proxies [self] = self
18411849
local num = z or x or 0
18421850
property_pnl.right:SetValue(math.Round(tonumber(num),4))
18431851
container:SetTooltip("LOCKED: Used by proxy:\n"..self:GetName().."\n\n" .. math_description)
18441852
end
18451853
elseif T == "boolean" then
18461854
if x ~= nil then
18471855
property_pnl.used_by_proxy = true
1856+
property_pnl.user_proxies = property_pnl.user_proxies or {}
1857+
property_pnl.user_proxies [self] = self
18481858
property_pnl:SetValue(tonumber(x) > 0)
18491859
container:SetTooltip("LOCKED: Used by proxy:\n"..self:GetName().."\n\n" .. math_description)
18501860
end
18511861
elseif original_x ~= nil then
18521862
property_pnl.used_by_proxy = true
1863+
property_pnl.user_proxies = property_pnl.user_proxies or {}
1864+
property_pnl.user_proxies [self] = self
18531865
property_pnl:SetValue(math.Round(tonumber(x) or 0,4))
18541866
container:SetTooltip("LOCKED: Used by proxy:\n"..self:GetName().."\n\n" .. math_description)
18551867
end
@@ -1960,11 +1972,19 @@ function PART:OnThink(to_hide)
19601972

19611973
if not ok then self.error = true
19621974
if self:GetPlayerOwner() == pac.LocalPlayer and self.Expression ~= self.LastBadExpression then
1963-
chat.AddText(Color(255,180,180),"============\n[ERR] PAC Proxy error on "..tostring(self)..":\n"..x.."\n============\n")
1975+
--don't spam the chat every time we type a single character in the luapad
1976+
if not (pace.ActiveSpecialPanel and pace.ActiveSpecialPanel.luapad) then
1977+
chat.AddText(Color(255,180,180),"============\n[ERR] PAC Proxy error on "..tostring(self)..":\n"..x.."\n============\n")
1978+
end
19641979
self.LastBadExpression = self.Expression
1980+
self.Error = x --will be used by the luapad for its title
19651981
end
1982+
1983+
if not self.errors_override then self:SetError(self.Error) end
19661984
return
19671985
end
1986+
self.Error = nil
1987+
if not self.errors_override then self:SetError() end
19681988

19691989
if x and not isnumber(x) then x = 0 end
19701990
if y and not isnumber(y) then y = 0 end

0 commit comments

Comments
 (0)