dobrograd-13-06-2022/garrysmod/addons/feature-wire/lua/wire/gates/comparison.lua
Jonny_Bro (Nikita) e4d5311906 first commit
2023-11-16 15:01:19 +05:00

113 lines
2.1 KiB
Lua

--[[
Comparison Gates
]]
GateActions("Comparison")
GateActions["="] = {
name = "Equal",
inputs = { "A", "B" },
output = function(gate, A, B)
if (math.abs(A-B) < 0.001) then return 1 end
return 0
end,
label = function(Out, A, B)
return A.." == "..B.." = "..Out
end
}
GateActions["!="] = {
name = "Not Equal",
inputs = { "A", "B" },
output = function(gate, A, B)
if (math.abs(A-B) < 0.001) then return 0 end
return 1
end,
label = function(Out, A, B)
return A.." ~= "..B.." = "..Out
end
}
GateActions["<"] = {
name = "Less Than",
inputs = { "A", "B" },
output = function(gate, A, B)
if (A < B) then return 1 end
return 0
end,
label = function(Out, A, B)
return A.." < "..B.." = "..Out
end
}
GateActions[">"] = {
name = "Greater Than",
inputs = { "A", "B" },
output = function(gate, A, B)
if (A > B) then return 1 end
return 0
end,
label = function(Out, A, B)
return A.." > "..B.." = "..Out
end
}
GateActions["<="] = {
name = "Less or Equal",
inputs = { "A", "B" },
output = function(gate, A, B)
if (A <= B) then return 1 end
return 0
end,
label = function(Out, A, B)
return A.." <= "..B.." = "..Out
end
}
GateActions[">="] = {
name = "Greater or Equal",
inputs = { "A", "B" },
output = function(gate, A, B)
if (A >= B) then return 1 end
return 0
end,
label = function(Out, A, B)
return A.." >= "..B.." = "..Out
end
}
GateActions["inrangei"] = {
name = "Is In Range (Inclusive)",
inputs = { "Min", "Max", "Value" },
output = function(gate, Min, Max, Value)
if (Max < Min) then
local temp = Max
Max = Min
Min = temp
end
if ((Value >= Min) && (Value <= Max)) then return 1 end
return 0
end,
label = function(Out, Min, Max, Value)
return Min.." <= "..Value.." <= "..Max.." = "..Out
end
}
GateActions["inrangee"] = {
name = "Is In Range (Exclusive)",
inputs = { "Min", "Max", "Value" },
output = function(gate, Min, Max, Value)
if (Max < Min) then
local temp = Max
Max = Min
Min = temp
end
if ((Value > Min) && (Value < Max)) then return 1 end
return 0
end,
label = function(Out, Min, Max, Value)
return Min.." < "..Value.." < "..Max.." = "..Out
end
}
GateActions()