Skip to content
13 changes: 3 additions & 10 deletions lua/entities/gmod_wire_expression2/core/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
local IsValid = IsValid

local TextList = {
last = { "", 0, nil }
last = { "", 0, NULL }
}
local ChatAlert = {}

Expand All @@ -20,7 +20,7 @@ end)

hook.Add("PlayerSay","Exp2TextReceiving", function(ply, text, teamchat)
chipHideChat, chipChatReplacement = nil, nil

local entry = { text, CurTime(), ply, teamchat }
TextList[ply:EntIndex()] = entry
TextList.last = entry
Expand Down Expand Up @@ -95,14 +95,7 @@ end
--- Returns the last player to speak.
[nodiscard, deprecated = "Use the chat event instead"]
e2function entity lastSpoke()
local entry = TextList.last
if not entry then return nil end

local ply = entry[3]
if not IsValid(ply) then return nil end
if not ply:IsPlayer() then return nil end

return ply
return TextList.last[3]
end

--- Returns the last message in the chat log.
Expand Down
66 changes: 34 additions & 32 deletions lua/entities/gmod_wire_expression2/core/constraint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ local function caps(text)
return capstext
end

-- Returns con.Ent1 or con.Ent2, whichever is not equivalent to ent. Optionally subscripts con with num beforehand.
local function ent1or2(ent,con,num)
if not con then return nil end
if num then
con = con[num]
if not con then return nil end
end
if con.Ent1==ent then return con.Ent2 end
return con.Ent1
end

--[[
-- buildFilters

Expand Down Expand Up @@ -235,59 +224,72 @@ e2function number entity:isConstrained()
return 1
end

-- Returns con.Ent1 or con.Ent2, whichever is not equivalent to ent. Optionally subscripts con with num beforehand.
local function ent1or2(ent, con, num)
if not con then return NULL end

if num then
con = con[num]
if not con then return NULL end
end

local ent1 = con.Ent1
if ent1 == ent then return con.Ent2 or NULL end

return ent1 or NULL
end

--- Returns the first entity <this> was welded to.
e2function entity entity:isWeldedTo()
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
if not constraint.HasConstraints(this) then return nil end
if not IsValid(this) then return self:throw("Invalid entity!", NULL) end
if not constraint.HasConstraints(this) then return NULL end

local filter = {Weld=true} -- create filter directly, no need to call buildFilter here, since it's static
return ent1or2(this,constraint_FindConstraint(this, filter))
return ent1or2(this, constraint_FindConstraint(this, {Weld = true}))
end

--- Returns the <index>th entity <this> was welded to.
e2function entity entity:isWeldedTo(index)
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
if not constraint.HasConstraints(this) then return nil end
if not IsValid(this) then return self:throw("Invalid entity!", NULL) end
if not constraint.HasConstraints(this) then return NULL end

local filter = {Weld=true} -- create filter directly, no need to call buildFilter here, since it's static
return ent1or2(this,constraint_FindConstraints(this, filter), math.floor(index))
return ent1or2(this, constraint_FindConstraints(this, {Weld = true}), math.floor(index))
end

--- Returns the first entity <this> was constrained to.
e2function entity entity:isConstrainedTo()
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
if not constraint.HasConstraints(this) then return nil end
if not IsValid(this) then return self:throw("Invalid entity!", NULL) end
if not constraint.HasConstraints(this) then return NULL end

return ent1or2(this,constraint_GetTable(this),1)
return ent1or2(this, constraint_GetTable(this), 1)
end

--- Returns the <index>th entity <this> was constrained to.
e2function entity entity:isConstrainedTo(index)
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
if not constraint.HasConstraints(this) then return nil end
if not IsValid(this) then return self:throw("Invalid entity!", NULL) end
if not constraint.HasConstraints(this) then return NULL end

return ent1or2(this,constraint_GetTable(this), math.floor(index))
return ent1or2(this, constraint_GetTable(this), math.floor(index))
end

--- Returns the first entity <this> was constrained to with the given constraint type <constraintType>.
e2function entity entity:isConstrainedTo(string constraintType)
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
if not constraint.HasConstraints(this) then return nil end
if not IsValid(this) then return self:throw("Invalid entity!", NULL) end
if not constraint.HasConstraints(this) then return NULL end

return ent1or2(this,constraint_FindConstraint(this, buildFilter({constraintType})))
return ent1or2(this, constraint_FindConstraint(this, buildFilter({constraintType})))
end

--- Returns the <index>th entity <this> was constrained to with the given constraint type <constraintType>.
e2function entity entity:isConstrainedTo(string constraintType, index)
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
if not constraint.HasConstraints(this) then return nil end
if not IsValid(this) then return self:throw("Invalid entity!", NULL) end
if not constraint.HasConstraints(this) then return NULL end

return ent1or2(this,constraint_FindConstraints(this, buildFilter({constraintType})), math.floor(index))
return ent1or2(this, constraint_FindConstraints(this, buildFilter({constraintType})), math.floor(index))
end

--- Returns the '''entity''' <this> is parented to.
e2function entity entity:parent()
if not IsValid(this) then return nil end
if not IsValid(this) then return self:throw("Invalid entity!", NULL) end
return this:GetParent()
end

Expand Down
20 changes: 10 additions & 10 deletions lua/entities/gmod_wire_expression2/core/egpfunctions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ e2function egpobject wirelink:egpBox( number index, vector2 pos, vector2 size )
if (!EGP:IsAllowed( self, this )) then return NULL_EGPOBJECT end
local bool, obj = egp_create("Box", { index = index, w = size[1], h = size[2], x = pos[1], y = pos[2] }, this)
if (bool) then EGP:DoAction( this, self, "SendObject", obj ) Update(self,this) end
return obj
return obj
end

--------------------------------------------------------
Expand Down Expand Up @@ -258,7 +258,7 @@ local function canCreateFont( ply, font, size )
size = size or 18

EGP.PlayerFontCount[ply:SteamID64()] = EGP.PlayerFontCount[ply:SteamID64()] or { fonts = {}, count = 0 }
local fontTable = EGP.PlayerFontCount[ply:SteamID64()]
local fontTable = EGP.PlayerFontCount[ply:SteamID64()]

if fontTable.count >= 50 then return false end

Expand Down Expand Up @@ -779,10 +779,14 @@ e2function void wirelink:egpParent( number index, entity parent )
end

-- Returns the entity a tracker is parented to
e2function entity wirelink:egpTrackerParent( number index )
e2function entity wirelink:egpTrackerParent(number index)
local bool, k, v = hasObject(this, index)

if bool and v.NeedsConstantUpdate then
return (v.parententity and v.parententity:IsValid()) and v.parententity or nil
local parent = v.parententity
return IsValid(parent) and parent or NULL
else
return NULL
end
end

Expand Down Expand Up @@ -1309,9 +1313,7 @@ end

-- Returns the screen which the queue finished sending items for
e2function entity egpQueueScreen()
if (EGP.RunByEGPQueue) then
return EGP.RunByEGPQueue_Ent
end
return EGP.RunByEGPQueue and EGP.RunByEGPQueue_Ent or NULL
end

-- Same as above, except returns wirelink
Expand All @@ -1323,9 +1325,7 @@ end

-- Returns the player which ordered the current items to be sent (This is usually yourself, but if you're sharing pp with someone it might be them. Good way to check if someone is fucking with your screens)
e2function entity egpQueuePlayer()
if (EGP.RunByEGPQueue) then
return EGP.RunByEGPQueue_ply
end
return EGP.RunByEGPQueue and EGP.RunByEGPQueue_ply or NULL
end

-- Returns 1 if the current execution was caused by the EGP queue system and the player <ply> was the player whom ordered the item to be sent (This is usually yourself, but if you're sharing pp with someone it might be them.)
Expand Down
13 changes: 6 additions & 7 deletions lua/entities/gmod_wire_expression2/core/entity.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local wire_expression2_entity_trails_max = CreateConVar("wire_expression2_entity_trails_max", 30, FCVAR_ARCHIVE, "Max amount of trails a player can make. 0 - to disable trails. (Limit is shared between E2s of a player)", 0)

registerType("entity", "e", nil,
registerType("entity", "e", NULL,
nil,
function(self,output) return output or NULL end,
nil,
Expand Down Expand Up @@ -69,8 +69,7 @@ end
--[[******************************************************************************]]

e2function entity entity(id)
local ent = ents.GetByIndex(id)
return IsValid(ent) and ent or nil
return ents.GetByIndex(id)
end

e2function number entity:id()
Expand Down Expand Up @@ -122,8 +121,8 @@ e2function string entity:model()
end

e2function entity entity:owner()
if not IsValid(this) then return self:throw("Invalid entity!", nil) end
return getOwner(self, this)
if not IsValid(this) then return self:throw("Invalid entity!", NULL) end
return getOwner(self, this) or NULL
end

__e2setcost(100)
Expand Down Expand Up @@ -889,12 +888,12 @@ end)
__e2setcost(5)

e2function entity entity:driver()
if not IsValid(this) or not this:IsVehicle() then return self:throw("Invalid vehicle!", nil) end
if not IsValid(this) or not this:IsVehicle() then return self:throw("Invalid vehicle!", NULL) end
return this:GetDriver()
end

e2function entity entity:passenger()
if not IsValid(this) or not this:IsVehicle() then return self:throw("Invalid vehicle!", nil) end
if not IsValid(this) or not this:IsVehicle() then return self:throw("Invalid vehicle!", NULL) end
return this:GetPassenger(0)
end

Expand Down
22 changes: 11 additions & 11 deletions lua/entities/gmod_wire_expression2/core/find.lua
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ end
--- Returns the player with the given name, this is an exception to the rule
[nodiscard]
e2function entity findPlayerByName(string name)
if query_blocked(self, 1) then return nil end
return findPlayer(name)
if query_blocked(self, 1) then return NULL end
return findPlayer(name) or NULL
end

--- Returns the player with the given SteamID
Expand Down Expand Up @@ -519,7 +519,7 @@ end

--- Exclude entities with this model (or partial model name) from future finds
e2function void findExcludeModel(string model)
if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", nil) end
if not pcall(WireLib.CheckRegex, sample_string, model) then return self:throw("Search string too complex!", nil) end
self.data.find.bl_model[string.lower(model)] = true
invalidate_filters(self)
end
Expand Down Expand Up @@ -800,26 +800,26 @@ end
--- Returns the indexed entity from the previous find event (valid parameters are 1 to the number of entities found)
[nodiscard]
e2function entity findResult(index)
return self.data.findlist[index]
return self.data.findlist[index] or NULL
end

--- Returns the closest entity to the given point from the previous find event
[nodiscard]
e2function entity findClosest(vector position)
local closest = nil
local dist = math.huge
local closest, dist = NULL, math.huge
self.prf = self.prf + #self.data.findlist * 10
for _,ent in pairs(self.data.findlist) do

for _, ent in pairs(self.data.findlist) do
if IsValid(ent) then
local pos = ent:GetPos()
local xd, yd, zd = pos.x-position[1], pos.y-position[2], pos.z-position[3]
local curdist = xd*xd + yd*yd + zd*zd
local curdist = ent:GetPos():Distance(position)

if curdist < dist then
closest = ent
dist = curdist
end
end
end

return closest
end

Expand All @@ -837,7 +837,7 @@ end
--- Equivalent to findResult(1)
[nodiscard]
e2function entity find()
return self.data.findlist[1]
return self.data.findlist[1] or NULL
end

--[[************************************************************************]]--
Expand Down
27 changes: 12 additions & 15 deletions lua/entities/gmod_wire_expression2/core/hologram.lua
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ local function CreateHolo(self, index, pos, scale, ang, color, model)
end, self, index )
end

if not IsValid(prop) then return nil end
if not IsValid(prop) then return NULL end

if color then WireLib.SetColor(Holo.ent, Color(color[1],color[2],color[3],color[4] or 255)) end

Expand Down Expand Up @@ -664,7 +664,7 @@ end

local function checkHoloCount(self)
if PlayerAmount[self.uid] >= wire_holograms_max:GetInt() then
return self:throw("You've hit the maximum amount of holograms!", true)
return self:throw("You've hit the maximum amount of holograms!", NULL)
end
end

Expand Down Expand Up @@ -718,8 +718,8 @@ e2function entity holoCreate(index, vector position, vector scale, angle ang, ve

position = Vector(position[1], position[2], position[3])
ang = Angle(ang[1], ang[2], ang[3])
local ret = CreateHolo(self, index, position, scale, ang, color)
if IsValid(ret) then return ret end

return CreateHolo(self, index, position, scale, ang, color)
end

e2function entity holoCreate(index, vector position, vector scale, angle ang)
Expand All @@ -728,10 +728,7 @@ e2function entity holoCreate(index, vector position, vector scale, angle ang)
local Holo = CheckIndex(self, index, true)
if not Holo and checkHoloCount(self) then return end

position = Vector(position[1], position[2], position[3])
ang = Angle(ang[1], ang[2], ang[3])
local ret = CreateHolo(self, index, position, scale, ang)
if IsValid(ret) then return ret end
return CreateHolo(self, index, position, scale, ang)
end

e2function entity holoCreate(index, vector position, vector scale)
Expand All @@ -741,8 +738,8 @@ e2function entity holoCreate(index, vector position, vector scale)
if not Holo and checkHoloCount(self) then return end

position = Vector(position[1],position[2],position[3])
local ret = CreateHolo(self, index, position, scale)
if IsValid(ret) then return ret end

return CreateHolo(self, index, position, scale)
end

e2function entity holoCreate(index, vector position)
Expand All @@ -752,8 +749,8 @@ e2function entity holoCreate(index, vector position)
if not Holo and checkHoloCount(self) then return end

position = Vector(position[1],position[2],position[3])
local ret = CreateHolo(self, index, position)
if IsValid(ret) then return ret end

return CreateHolo(self, index, position)
end

e2function entity holoCreate(index)
Expand All @@ -762,8 +759,7 @@ e2function entity holoCreate(index)
local Holo = CheckIndex(self, index, true)
if not Holo and PlayerAmount[self.uid] >= wire_holograms_max:GetInt() then return end

local ret = CreateHolo(self, index)
if IsValid(ret) then return ret end
return CreateHolo(self, index)
end

__e2setcost(20)
Expand Down Expand Up @@ -1328,7 +1324,8 @@ end
__e2setcost(2)
e2function entity holoEntity(index)
local Holo = CheckIndex(self, index)
if Holo and IsValid(Holo.ent) then return Holo.ent end

return Holo and Holo.ent or NULL
end

__e2setcost(30)
Expand Down
Loading
Loading