Skip to content

Commit

Permalink
Add PhysObj.setContents and Entity.setContents (#1859)
Browse files Browse the repository at this point in the history
* Update physobj.lua

added physobj:setContents(contents)

* Update physobj.lua

* Update physobj.lua

* Update entities.lua

* Update physobj.lua
  • Loading branch information
BenKayyy authored Sep 20, 2024
1 parent 0af9e9d commit cc599df
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lua/starfall/libs_sh/physobj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ if SERVER then
phys:SetBuoyancyRatio(ratio)
end

--- Sets the contents flag of the physobject
-- @server
-- @param number contents The CONTENTS enum
function physobj_methods:setContents(contents)
checkluatype(contents, TYPE_NUMBER)
local phys = unwrap(self)
checkpermission(instance, phys:GetEntity(), "entities.setContents")
phys:SetContents(contents)
end

--- Applies a force to the center of the physics object
-- @server
-- @param Vector force The force vector to apply
Expand Down
16 changes: 16 additions & 0 deletions lua/starfall/libs_sv/entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ registerprivilege("entities.setAngles", "Set Angles", "Allows the user to rotate
registerprivilege("entities.setEyeAngles", "Set eye angles", "Allows the user to rotate the view of an entity to another orientation", { entities = {} })
registerprivilege("entities.setVelocity", "Set Velocity", "Allows the user to change the velocity of an entity", { entities = {} })
registerprivilege("entities.setSolid", "Set Solid", "Allows the user to change the solidity of an entity", { entities = {} })
registerprivilege("entities.setContents", "Set Contents", "Allows the user to change the contents flag of an entity", { entities = {} })
registerprivilege("entities.setMass", "Set Mass", "Allows the user to change the mass of an entity", { entities = {} })
registerprivilege("entities.setInertia", "Set Inertia", "Allows the user to change the inertia of an entity", { entities = {} })
registerprivilege("entities.enableGravity", "Enable gravity", "Allows the user to change whether an entity is affected by gravity", { entities = {} })
Expand Down Expand Up @@ -664,6 +665,21 @@ function ents_methods:enableDrag(drag)
phys:EnableDrag(drag and true or false)
end

--- Sets the contents flag of the physobject
-- @server
-- @param number contents The CONTENTS enum
function ents_methods:setContents(contents)
local ent = getent(self)
if ent:IsPlayer() then SF.Throw("Target is a player!", 2) end
local phys = ent:GetPhysicsObject()
if not IsValidPhys(phys) then SF.Throw("Physics object is invalid", 2) end

checkluatype(contents, TYPE_NUMBER)

checkpermission(instance, ent, "entities.setContents")
phys:SetContents(contents)
end

--- Sets the entity movement state
-- @param boolean move Should the entity move?
function ents_methods:enableMotion(move)
Expand Down

0 comments on commit cc599df

Please sign in to comment.