diff --git a/lua/entities/gmod_wire_expression2/core/bone.lua b/lua/entities/gmod_wire_expression2/core/bone.lua index 92f0e068ff..37e058f2c7 100644 --- a/lua/entities/gmod_wire_expression2/core/bone.lua +++ b/lua/entities/gmod_wire_expression2/core/bone.lua @@ -108,7 +108,7 @@ end --- Returns an array containing all of 's bones. This array's first element has the index 0! e2function array entity:bones() if not IsValid(this) then return { } end - return GetBones(this) + return table.Copy(GetBones(this)) end --- Returns 's number of bones. @@ -418,7 +418,3 @@ e2function string toString(bone b) end WireLib.registerDebuggerFormat("BONE", e2_tostring_bone) - ---[[************************************************************************]]-- - --- TODO: constraints diff --git a/lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua b/lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua index 566d0e9ce3..f0e8f05723 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/cl_prop.lua @@ -67,3 +67,8 @@ E2Helper.Descriptions["setPos(b:v)"] = "Sets the position of a bone." E2Helper.Descriptions["setAng(b:a)"] = "Set the rotation of a bone." E2Helper.Descriptions["ragdollSetPos(e:v)"] = "Sets the position of a ragdoll while preserving pose." E2Helper.Descriptions["ragdollSetAng(e:a)"] = "Set the rotation of a ragdoll while preserving pose." +E2Helper.Descriptions["setEyeTarget(e:v)"] = "For NPCs, sets the eye target to the world position. For ragdolls, sets the eye target to the local eye position" +E2Helper.Descriptions["setEyeTargetLocal(e:v)"] = "Sets the eye target to the local eye position" +E2Helper.Descriptions["setEyeTargetWorld(e:v)"] = "Sets the eye target to the world position" +E2Helper.Descriptions["setFlexScale(e:n)"] = "Sets the flex scale of the entity" +E2Helper.Descriptions["setFlexWeight"] = "Sets the weight of the flex" \ No newline at end of file diff --git a/lua/entities/gmod_wire_expression2/core/custom/prop.lua b/lua/entities/gmod_wire_expression2/core/custom/prop.lua index 15760e78f0..f45a5db0b5 100644 --- a/lua/entities/gmod_wire_expression2/core/custom/prop.lua +++ b/lua/entities/gmod_wire_expression2/core/custom/prop.lua @@ -497,6 +497,7 @@ e2function void entity:propStatic( number static ) end end +-- Bones -- -------------------------------------------------------------------------------- e2function void bone:boneManipulate(vector pos, angle rot, isFrozen, gravity, collision) @@ -828,6 +829,62 @@ e2function number propCanCreate() return 0 end +-- Flexes -- +-------------------------------------------------------------------------------- + +-- Setters + +__e2setcost(10) + +e2function void entity:setEyeTarget(vector pos) + if not ValidAction(self, this, "eyetarget") then return end + this:SetEyeTarget(pos) +end + +e2function void entity:setFlexWeight(number flex, number weight) + if not ValidAction(self, this, "flexweight" .. flex) then return end + this:SetFlexWeight(flex, weight) +end + +__e2setcost(30) + +e2function void entity:setEyeTargetLocal(vector pos) + if not ValidAction(self, this, "eyetarget") then return end + if not this:IsRagdoll() then + local attachment = this:GetAttachment(this:LookupAttachment("eyes")) + if attachment then + pos = LocalToWorld(pos, angle_zero, attachment.Pos, attachment.Ang) + end + end + this:SetEyeTarget(pos) +end + +e2function void entity:setEyeTargetWorld(vector pos) + if not ValidAction(self, this, "eyetarget") then return end + if this:IsRagdoll() then + local attachment = this:GetAttachment(this:LookupAttachment("eyes")) + if attachment then + pos = WorldToLocal(pos, angle_zero, attachment.Pos, attachment.Ang) + end + end + this:SetEyeTarget(pos) +end + +__e2setcost(20) + +e2function void entity:setFlexWeight(string flex, number weight) + flex = this:GetFlexIDByName(flex) + if flex then + if not ValidAction(self, this, "flexweight" .. flex) then return end + this:SetFlexWeight(flex, weight) + end +end + +e2function void entity:setFlexScale(number scale) + if not ValidAction(self, this, "flexscale") then return end + this:SetFlexScale(scale) +end + registerCallback("construct", function(self) self.data.propSpawnEffect = true diff --git a/lua/entities/gmod_wire_expression2/core/entity.lua b/lua/entities/gmod_wire_expression2/core/entity.lua index 108d154085..8028bbf4e4 100644 --- a/lua/entities/gmod_wire_expression2/core/entity.lua +++ b/lua/entities/gmod_wire_expression2/core/entity.lua @@ -1033,6 +1033,75 @@ e2function void entity:noCollideAll(number state) this:SetCollisionGroup(state == 0 and COLLISION_GROUP_NONE or COLLISION_GROUP_WORLD) end +--[[******************************************************************************]] +-- Flexes + +__e2setcost(5) + +e2function array entity:getFlexBounds(number flex) + if not IsValid(this) then return self:throw("Invalid entity!", {}) end + return { this:GetFlexBounds(flex) } +end + +e2function number entity:getFlexCount() + if not IsValid(this) then return self:throw("Invalid entity!", 0) end + return this:GetFlexNum() +end + +e2function number entity:getFlexID(string flex) + if not IsValid(this) then return self:throw("Invalid entity!", 0) end + return this:GetFlexIDByName(flex) or -1 +end + +e2function number entity:getFlexScale() + if not IsValid(this) then return self:throw("Invalid entity!", 0) end + return this:GetFlexScale() +end + +e2function string entity:getFlexName(number id) + if not IsValid(this) then return self:throw("Invalid entity!", "") end + return this:GetFlexName(id) or "" +end + +e2function number entity:getFlexWeight(number flex) + if not IsValid(this) then return self:throw("Invalid entity!", 0) end + return this:GetFlexWeight(flex) +end + +e2function number entity:hasFlexes() + if not IsValid(this) then return self:throw("Invalid entity!", 0) end + return this:HasFlexManipulator() and 1 or 0 +end + +__e2setcost(15) + +e2function array entity:getFlexBounds(string flex) + if not IsValid(this) then return self:throw("Invalid entity!", {}) end + flex = this:GetFlexIDByName(flex) + return flex and { this:GetFlexBounds(flex) } or {} +end + +e2function number entity:getFlexWeight(string flex) + if not IsValid(this) then return self:throw("Invalid entity!", 0) end + flex = this:GetFlexIDByName(flex) + return flex and this:GetFlexWeight(flex) or 0 +end + +__e2setcost(50) + +e2function array entity:getFlexes() + if not IsValid(this) then return self:throw("Invalid entity!", 0) end + local ret = {} + for i = 0, this:GetFlexNum() - 1 do + ret[i] = this:GetFlexName(i) + end + self.prf = self.prf + (#ret + 1) * 5 + return ret +end + +--[[******************************************************************************]] +-- End e2functions + hook.Add("OnEntityCreated", "E2_entityCreated", function(ent) if not IsValid(ent) then return end -- Engine is precaching a model or bad addon diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index 2bb66d13f4..d27247bd01 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -395,6 +395,16 @@ E2Helper.Descriptions["attachmentPos(e:s)"] = "Same as E:attachmentPos(E:lookupA E2Helper.Descriptions["attachmentAng(e:s)"] = "Same as E:attachmentAng(E:lookupAttachment(attachmentName))" E2Helper.Descriptions["attachments(e:)"] = "Returns array of attachment names of the entity" +-- Flexes +E2Helper.Descriptions["getFlexBounds"] = "Gets the upper and lower bounds of the flex if it exists" +E2Helper.Descriptions["getFlexCount(e:)"] = "Gets the number of flexes on the entity" +E2Helper.Descriptions["getFlexID(e:s)"] = "Gets the flex ID of the given name or -1 if it doesn't exist" +E2Helper.Descriptions["getFlexName(e:n)"] = "Gets the name of the flex" +E2Helper.Descriptions["getFlexScale(e:)"] = "Gets the flex scale of the entity" +E2Helper.Descriptions["getFlexWeight"] = "Gets the weight of the flex" +E2Helper.Descriptions["getFlexes(e:)"] = "Gets a 0-indexed array of all flexes and their names" +E2Helper.Descriptions["hasFlexes(e:)"] = "Returns 1 if the entity has flexes" + -- Vector E2Helper.Descriptions["vec2(n)"] = "Makes a 2D vector" E2Helper.Descriptions["vec2(nn)"] = "Makes a 2D vector"