Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 17 additions & 119 deletions lua/entities/gmod_wire_expression2/core/unitconv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,132 +2,30 @@
Unit conversion
\******************************************************************************/

/*
u - source unit
A Source Unit is 0.75 Inch long, more info here:
http://developer.valvesoftware.com/wiki/Dimensions#Map_Grid_Units:_quick_reference

mm - millimeter
cm - centimeter
dm - decimeter
m - meter
km - kilometer
in - inch
ft - foot
yd - yard
mi - mile
nmi - nautical mile

g - gram
kg - kilogram
t - tonne
oz - ounce
lb - pound
*/

local speed = {
["u/s"] = 1 / 0.75,
["u/m"] = 60 * (1 / 0.75),
["u/h"] = 3600 * (1 / 0.75),

["mm/s"] = 25.4,
["cm/s"] = 2.54,
["dm/s"] = 0.254,
["m/s"] = 0.0254,
["km/s"] = 0.0000254,
["in/s"] = 1,
["ft/s"] = 1 / 12,
["yd/s"] = 1 / 36,
["mi/s"] = 1 / 63360,
["nmi/s"] = 127 / 9260000,

["mm/m"] = 60 * 25.4,
["cm/m"] = 60 * 2.54,
["dm/m"] = 60 * 0.254,
["m/m"] = 60 * 0.0254,
["km/m"] = 60 * 0.0000254,
["in/m"] = 60,
["ft/m"] = 60 / 12,
["yd/m"] = 60 / 36,
["mi/m"] = 60 / 63360,
["nmi/m"] = 60 * 127 / 9260000,

["mm/h"] = 3600 * 25.4,
["cm/h"] = 3600 * 2.54,
["dm/h"] = 3600 * 0.254,
["m/h"] = 3600 * 0.0254,
["km/h"] = 3600 * 0.0000254,
["in/h"] = 3600,
["ft/h"] = 3600 / 12,
["yd/h"] = 3600 / 36,
["mi/h"] = 3600 / 63360,
["nmi/h"] = 3600 * 127 / 9260000,

["mph"] = 3600 / 63360,
["knots"] = 3600 * 127 / 9260000,
["mach"] = 0.0254 / 295,
}

local length = {
["u"] = 1 / 0.75,

["mm"] = 25.4,
["cm"] = 2.54,
["dm"] = 0.254,
["m"] = 0.0254,
["km"] = 0.0000254,
["in"] = 1,
["ft"] = 1 / 12,
["yd"] = 1 / 36,
["mi"] = 1 / 63360,
["nmi"] = 127 / 9260000,
}

local weight = {
["g"] = 1000,
["kg"] = 1,
["t"] = 0.001,
["oz"] = 1 / 0.028349523125,
["lb"] = 1 / 0.45359237,
}

__e2setcost(2) -- approximated

e2function number toUnit(string rv1, rv2)
local unitconv = WireLib.UnitConv

if speed[rv1] then
return (rv2 * 0.75) * speed[rv1]
elseif length[rv1] then
return (rv2 * 0.75) * length[rv1]
elseif weight[rv1] then
return rv2 * weight[rv1]
end

return -1
e2function number toUnit(string rv1, rv2)
for _, tbl in pairs(unitconv) do
if tbl[rv1] then
return rv2 * tbl[rv1]
end
end
return -1
end

e2function number fromUnit(string rv1, rv2)

if speed[rv1] then
return (rv2 / 0.75) / speed[rv1]
elseif length[rv1] then
return (rv2 / 0.75) / length[rv1]
elseif weight[rv1] then
return rv2 / weight[rv1]
end

return -1
for _, tbl in pairs(unitconv) do
if tbl[rv1] then
return rv2 / tbl[rv1]
end
end
return -1
end

e2function number convertUnit(string rv1, string rv2, rv3)

if speed[rv1] and speed[rv2] then
return rv3 * (speed[rv2] / speed[rv1])
elseif length[rv1] and length[rv2] then
return rv3 * (length[rv2] / length[rv1])
elseif weight[rv1] and weight[rv2] then
return rv3 * (weight[rv2] / weight[rv1])
end

return -1
local factor = WireLib.ConvertUnit(rv1, rv2)
if factor then return rv3 * factor end
return -1
end
13 changes: 13 additions & 0 deletions lua/entities/gmod_wire_interactiveprop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ InteractiveModels = {
{type="DNumberScratch", x = 85, y = 55, name="Knob6"},
}
},
["models/props_lab/reciever01d.mdl"] = {
width = 112,
height = 80,
title="reciever01d",
widgets={
{type="DNumberScratch", x = 10, y = 30, name="Knob1", color=Color(128,64,64)},
{type="DNumberScratch", x = 35, y = 30, name="Knob2", color=Color(128,64,64)},
{type="DNumberScratch", x = 10, y = 55, name="Knob3"},
{type="DNumberScratch", x = 35, y = 55, name="Knob4"},
{type="DNumberScratch", x = 60, y = 55, name="Knob5"},
{type="DNumberScratch", x = 85, y = 55, name="Knob6"},
}
},
["models/props_interiors/vendingmachinesoda01a.mdl"] = {
width = 60,
height = 200,
Expand Down
209 changes: 209 additions & 0 deletions lua/wire/gates/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1027,4 +1027,213 @@ GateActions["entity_heading"] = {
end
}

GateActions["entity_getattachments"] = {
name = "Attachments",
description = "Returns an array of all attachment IDs for the entity's model.",
inputs = { "Ent" },
inputtypes = { "ENTITY" },
outputs = { "IDs", "Names" },
outputtypes = { "ARRAY", "ARRAY" },
output = function(gate, Ent)
if not Ent:IsValid() then return {}, {} end
local attachments = Ent:GetAttachments()
if not attachments or #attachments == 0 then return {}, {} end
local ids = {}
local names = {}
for _, att in ipairs(attachments) do
ids[#ids + 1] = att.id
names[#names + 1] = att.name
end
return ids, names
end,
label = function(Out)
return string.format("Attachments: %d found", #Out.IDs)
end
}

GateActions["entity_getattachment"] = {
name = "Attachment",
description = "Gets the position and angle of a specific attachment by ID or Name. Return Position/Angles must be > 0 to output their respective values.",
inputs = { "Ent", "ID", "Name", "Return Position", "Return Angles" },
inputtypes = { "ENTITY", "NORMAL", "STRING", "NORMAL", "NORMAL" },
outputs = { "Position", "Angles" },
outputtypes = { "VECTOR", "ANGLE" },
timed = true,
output = function(gate, Ent, ID, Name, ReturnPos, ReturnAng)
if not Ent:IsValid() then return vec0, ang0 end

local attachID = ID
if Name and Name ~= "" then
local found = Ent:LookupAttachment(Name)
if found and found > 0 then
attachID = found
end
end

if not attachID or attachID <= 0 then return vec0, ang0 end

local attData = Ent:GetAttachment(attachID)
if not attData then return vec0, ang0 end

local pos = vec0
local ang = ang0

if ReturnPos and ReturnPos > 0 then
pos = attData.Pos
end
if ReturnAng and ReturnAng > 0 then
ang = attData.Ang
end

return pos, ang
end,
label = function(Out, Ent, ID, Name)
return string.format("attachment(%s, id=%s, name=%q) Pos=(%d,%d,%d) Ang=(%d,%d,%d)",
tostring(Ent), tostring(ID), tostring(Name or ""),
Out.Position.x, Out.Position.y, Out.Position.z,
Out.Angles.p, Out.Angles.y, Out.Angles.r)
end
}

GateActions["entity_isfrozen"] = {
name = "Is Frozen",
inputs = { "Ent" },
inputtypes = { "ENTITY" },
outputtypes = { "NORMAL" },
timed = true,
output = function(gate, Ent)
if not Ent:IsValid() then return 0 end
local phys = Ent:GetPhysicsObject()
if not IsValid(phys) then return 0 end
return phys:IsMoveable() and 0 or 1
end,
label = function(Out)
return string.format("Is Frozen = %d", Out)
end
}

GateActions["entity_getchildren"] = {
name = "Children",
description = "Returns an array of all children entities parented to the given entity.",
inputs = { "Ent" },
inputtypes = { "ENTITY" },
outputs = { "Children", "Count" },
outputtypes = { "ARRAY", "NORMAL" },
output = function(gate, Ent)
if not Ent:IsValid() then return {}, 0 end
local keytable = Ent:GetChildren()
local result = {}
local i = 1
for _, child in pairs(keytable) do
if IsValid(child) then
result[i] = child
i = i + 1
end
end
return result, #result
end,
label = function(Out)
return string.format("Children: %d found", Out.Count)
end
}

GateActions["entity_vehicle"] = {
name = "Vehicle",
description = "Returns the vehicle that the player is currently sitting in. Returns NULL if the player is not in a vehicle.",
inputs = { "Ent" },
inputtypes = { "ENTITY" },
outputtypes = { "ENTITY" },
timed = true,
output = function(gate, Ent)
if not IsValid(Ent) then return NULL end
if not Ent:IsPlayer() then return NULL end
return Ent:GetVehicle()
end,
label = function(Out, Ent)
return string.format("vehicle(%s) = %s", tostring(Ent), tostring(Out))
end
}

local moveTypes = {
[0] = "NONE",
[1] = "ISOMETRIC",
[2] = "WALK",
[3] = "STEP",
[4] = "FLY",
[5] = "FLYGRAVITY",
[6] = "VPHYSICS",
[7] = "PUSH",
[8] = "NOCLIP",
[9] = "LADDER",
[10] = "OBSERVER",
[11] = "CUSTOM",
}

GateActions["entity_getmovetype"] = {
name = "Move Type",
description = "Returns the move type of an entity. 0=NONE, 1=ISOMETRIC, 2=WALK, 3=STEP, 4=FLY, 5=FLYGRAVITY, 6=VPHYSICS, 7=PUSH, 8=NOCLIP, 9=LADDER, 10=OBSERVER, 11=CUSTOM",
inputs = { "Ent" },
inputtypes = { "ENTITY" },
outputtypes = { "NORMAL" },
timed = true,
output = function(gate, Ent)
if not IsValid(Ent) then return 0 end
return Ent:GetMoveType()
end,
label = function(Out, Ent)
return string.format("getMoveType(%s) = %s", tostring(Ent), moveTypes[Out] or tostring(Out))
end
}

GateActions["entity_activeweapon"] = {
name = "Weapon",
description = "Returns the weapon the player is currently holding.",
inputs = { "Ent" },
inputtypes = { "ENTITY" },
outputtypes = { "ENTITY" },
timed = true,
output = function(gate, Ent)
if not IsValid(Ent) then return NULL end
if not Ent:IsPlayer() then return NULL end
return Ent:GetActiveWeapon()
end,
label = function(Out, Ent)
local name = IsValid(Out) and Out:GetClass() or "none"
return string.format("activeWeapon(%s) = %s", tostring(Ent), name)
end
}

GateActions["entity_weapons"] = {
name = "Weapons",
description = "Returns an array of all weapons in the player's inventory.",
inputs = { "Ent" },
inputtypes = { "ENTITY" },
outputtypes = { "ARRAY" },
timed = true,
output = function(gate, Ent)
if not IsValid(Ent) then return {} end
if not Ent:IsPlayer() then return {} end
return Ent:GetWeapons()
end,
label = function(Out, Ent)
return string.format("Weapons(%s) = %d items", tostring(Ent), #Out)
end
}

GateActions["entity_eyepos"] = {
name = "Eye Position",
description = "Returns the position of the player's eyes.",
inputs = { "Ent" },
inputtypes = { "ENTITY" },
outputtypes = { "VECTOR" },
timed = true,
output = function(gate, Ent)
if not IsValid(Ent) or not Ent:IsPlayer() then return vec0 end
return Ent:EyePos()
end,
label = function(Out, Ent)
return string.format("eyePos(%s) = (%d,%d,%d)", tostring(Ent), Out.x, Out.y, Out.z)
end
}

GateActions()
Loading
Loading