Skip to content

Commit 91a1f51

Browse files
authored
More player entities methods and perms (#2243)
* More player methods and permission and ent:getGravity * fix ejectDriver not using the permission for years and player:setFriction * player ignite * __index locals * fix * Update players.lua * Revert friction change * setpos canphysgun default
1 parent 43decbd commit 91a1f51

File tree

4 files changed

+118
-10
lines changed

4 files changed

+118
-10
lines changed

lua/starfall/libs_sh/entities.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,5 +2221,11 @@ function ents_methods:getNetworkVars()
22212221
return istable(ent_tbl.dt) and instance.Sanitize(ent_tbl.GetNetworkVars(ent)) or nil
22222222
end
22232223

2224+
--- Gets the gravity multiplier of the entity.
2225+
-- @shared
2226+
-- @return number The gravity multiplier
2227+
function ents_methods:getGravity()
2228+
return getent(self):GetGravity()
2229+
end
22242230

22252231
end

lua/starfall/libs_sh/vehicles.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ if SERVER then
159159
--- Ejects the driver of the vehicle
160160
-- @server
161161
function vehicle_methods:ejectDriver()
162-
local driver = getveh(self):GetDriver()
162+
local veh = getveh(self)
163+
local driver = veh:GetDriver()
164+
checkpermission(instance, veh, "vehicle.eject")
165+
163166
if Ent_IsValid(driver) then
164167
Ply_ExitVehicle(driver)
165168
end

lua/starfall/libs_sv/entities.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ registerprivilege("entities.applyDamage", "Apply damage", "Allows the user to ap
1313
registerprivilege("entities.applyForce", "Apply force", "Allows the user to apply force to an entity", { entities = {} })
1414
registerprivilege("entities.setPos", "Set Position", "Allows the user to teleport an entity to another location", { entities = {} })
1515
registerprivilege("entities.setAngles", "Set Angles", "Allows the user to rotate an entity to another orientation", { entities = {} })
16-
registerprivilege("entities.setEyeAngles", "Set eye angles", "Allows the user to rotate the view of an entity to another orientation", { entities = {} })
1716
registerprivilege("entities.setVelocity", "Set Velocity", "Allows the user to change the velocity of an entity", { entities = {} })
1817
registerprivilege("entities.setSolid", "Set Solid", "Allows the user to change the solidity of an entity", { entities = {} })
1918
registerprivilege("entities.setContents", "Set Contents", "Allows the user to change the contents flag of an entity", { entities = {} })

lua/starfall/libs_sv/players.lua

Lines changed: 108 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ registerprivilege("player.enterVehicle", "EnterVehicle", "Whether a player can b
1515
registerprivilege("player.exitVehicle", "ExitVehicle", "Whether a player can be forced out of a vehicle", { entities = {} })
1616
registerprivilege("player.setArmor", "SetArmor", "Allows changing a player's armor", { usergroups = { default = 1 }, entities = {} })
1717
registerprivilege("player.setMaxArmor", "SetMaxArmor", "Allows changing a player's max armor", { usergroups = { default = 1 }, entities = {} })
18+
registerprivilege("player.setHealth", "SetHealth", "Allows the user to change an player's health", { entities = {}, usergroups = { default = 1 } })
19+
registerprivilege("player.setMaxHealth", "SetMaxHealth", "Allows the user to change an player's max health", { entities = {}, usergroups = { default = 1 } })
1820
registerprivilege("player.modifyMovementProperties", "ModifyMovementProperties", "Allows various changes to a player's movement", { usergroups = { default = 1 }, entities = {} })
21+
registerprivilege("player.setPos", "Set Position", "Allows the user to teleport a player to another location", { entities = { default = 3}, usergroups = { default = 1 } })
22+
registerprivilege("player.setEyeAngles", "SetEyeAngles", "Allows the user to rotate the view of a player to another orientation", { entities = {}, usergroups = { default = 1 } })
23+
registerprivilege("player.ignite", "Ignite", "Allows the user to ignite players", { entities = {}, usergroups = { default = 1 } })
1924

2025
local PVSLimitCvar = CreateConVar("sf_pvs_pointlimit", 16, FCVAR_ARCHIVE, "The number of PVS points that can be set on each player, limit is shared across all chips")
2126

@@ -111,8 +116,8 @@ local PlayerPVSManager = PVSManager()
111116

112117
return function(instance)
113118
local checkpermission = instance.player ~= SF.Superuser and SF.Permissions.check or function() end
114-
local Ent_SetFriction,Ent_SetModelScale = ENT_META.SetFriction,ENT_META.SetModelScale
115-
local Ply_Alive,Ply_DropNamedWeapon,Ply_DropWeapon,Ply_EnterVehicle,Ply_ExitVehicle,Ply_GetTimeoutSeconds,Ply_HasGodMode,Ply_IsConnected,Ply_IsTimingOut,Ply_Kill,Ply_LastHitGroup,Ply_PacketLoss,Ply_Say,Ply_SetAmmo,Ply_SetArmor,Ply_SetCrouchedWalkSpeed,Ply_SetDuckSpeed,Ply_SetEyeAngles,Ply_SetJumpPower,Ply_SetLadderClimbSpeed,Ply_SetMaxArmor,Ply_SetMaxSpeed,Ply_SetRunSpeed,Ply_SetSlowWalkSpeed,Ply_SetStepSize,Ply_SetUnDuckSpeed,Ply_SetViewEntity,Ply_SetWeaponColor,Ply_SetWalkSpeed,Ply_StripAmmo,Ply_StripWeapon,Ply_StripWeapons,Ply_TimeConnected = PLY_META.Alive,PLY_META.DropNamedWeapon,PLY_META.DropWeapon,PLY_META.EnterVehicle,PLY_META.ExitVehicle,PLY_META.GetTimeoutSeconds,PLY_META.HasGodMode,PLY_META.IsConnected,PLY_META.IsTimingOut,PLY_META.Kill,PLY_META.LastHitGroup,PLY_META.PacketLoss,PLY_META.Say,PLY_META.SetAmmo,PLY_META.SetArmor,PLY_META.SetCrouchedWalkSpeed,PLY_META.SetDuckSpeed,PLY_META.SetEyeAngles,PLY_META.SetJumpPower,PLY_META.SetLadderClimbSpeed,PLY_META.SetMaxArmor,PLY_META.SetMaxSpeed,PLY_META.SetRunSpeed,PLY_META.SetSlowWalkSpeed,PLY_META.SetStepSize,PLY_META.SetUnDuckSpeed,PLY_META.SetViewEntity,PLY_META.SetWeaponColor,PLY_META.SetWalkSpeed,PLY_META.StripAmmo,PLY_META.StripWeapon,PLY_META.StripWeapons,PLY_META.TimeConnected
119+
local Ent_Extinguish,Ent_Ignite,Ent_OBBMaxs,Ent_OBBMins,Ent_SetFriction,Ent_SetGravity,Ent_SetModelScale,Ent_SetPos,Ent_SetVelocity = ENT_META.Extinguish,ENT_META.Ignite,ENT_META.OBBMaxs,ENT_META.OBBMins,ENT_META.SetFriction,ENT_META.SetGravity,ENT_META.SetModelScale,ENT_META.SetPos,ENT_META.SetVelocity
120+
local Ply_Alive,Ply_DropNamedWeapon,Ply_DropWeapon,Ply_EnterVehicle,Ply_ExitVehicle,Ply_GetTimeoutSeconds,Ply_HasGodMode,Ply_IsConnected,Ply_IsTimingOut,Ply_Kill,Ply_LastHitGroup,Ply_PacketLoss,Ply_SetAmmo,Ply_SetArmor,Ply_SetCrouchedWalkSpeed,Ply_SetDuckSpeed,Ply_SetEyeAngles,Ply_SetJumpPower,Ply_SetLadderClimbSpeed,Ply_SetMaxArmor,Ply_SetMaxSpeed,Ply_SetRunSpeed,Ply_SetSlowWalkSpeed,Ply_SetStepSize,Ply_SetUnDuckSpeed,Ply_SetViewEntity,Ply_SetWalkSpeed,Ply_SetWeaponColor,Ply_StripAmmo,Ply_StripWeapon,Ply_StripWeapons,Ply_TimeConnected = PLY_META.Alive,PLY_META.DropNamedWeapon,PLY_META.DropWeapon,PLY_META.EnterVehicle,PLY_META.ExitVehicle,PLY_META.GetTimeoutSeconds,PLY_META.HasGodMode,PLY_META.IsConnected,PLY_META.IsTimingOut,PLY_META.Kill,PLY_META.LastHitGroup,PLY_META.PacketLoss,PLY_META.SetAmmo,PLY_META.SetArmor,PLY_META.SetCrouchedWalkSpeed,PLY_META.SetDuckSpeed,PLY_META.SetEyeAngles,PLY_META.SetJumpPower,PLY_META.SetLadderClimbSpeed,PLY_META.SetMaxArmor,PLY_META.SetMaxSpeed,PLY_META.SetRunSpeed,PLY_META.SetSlowWalkSpeed,PLY_META.SetStepSize,PLY_META.SetUnDuckSpeed,PLY_META.SetViewEntity,PLY_META.SetWalkSpeed,PLY_META.SetWeaponColor,PLY_META.StripAmmo,PLY_META.StripWeapon,PLY_META.StripWeapons,PLY_META.TimeConnected
116121

117122
local player_methods, player_meta, wrap, unwrap = instance.Types.Player.Methods, instance.Types.Player, instance.Types.Player.Wrap, instance.Types.Player.Unwrap
118123
local owrap, ounwrap = instance.WrapObject, instance.UnwrapObject
@@ -133,13 +138,21 @@ instance:AddHook("initialize", function()
133138
aunwrap1 = ang_meta.QuickUnwrap1
134139
end)
135140

141+
local gravity_reset = {}
142+
136143
instance:AddHook("deinitialize", function()
137144
for k, ply in pairs(player.GetAll()) do
138145
if instance.data.viewEntityChanged then
139146
Ply_SetViewEntity(ply)
140147
end
141148
end
142149
PlayerPVSManager:clearInstCountTable( instance )
150+
151+
for i, ply in pairs(gravity_reset) do
152+
if ply and ply:IsValid() then
153+
Ent_SetGravity(ply, 1)
154+
end
155+
end
143156
end)
144157

145158
instance:AddHook( "starfall_hud_disconnected", function( activator, ply )
@@ -245,9 +258,9 @@ end
245258
--- Sets a player's eye angles
246259
-- @param Angle ang New angles
247260
function player_methods:setEyeAngles(ang)
248-
local ent = getent(self)
249-
checkpermission(instance, ent, "entities.setEyeAngles")
250-
Ply_SetEyeAngles(ent, aunwrap1(ang))
261+
local ply = getply(self)
262+
checkpermission(instance, ply, "player.setEyeAngles")
263+
Ply_SetEyeAngles(ply, aunwrap1(ang))
251264
end
252265

253266
--- Returns the packet loss of the client
@@ -312,6 +325,28 @@ function player_methods:setMaxArmor(val)
312325
Ply_SetMaxArmor(ent, val)
313326
end
314327

328+
--- Sets the health of the player.
329+
-- @server
330+
-- @param number newhealth New health value.
331+
function player_methods:setHealth(val)
332+
local ply = getply(self)
333+
checkpermission(instance, ply, "player.setHealth")
334+
checkluatype(val, TYPE_NUMBER)
335+
336+
ply:SetHealth(val)
337+
end
338+
339+
--- Sets the maximum health for player. Note, that you can still set player's health above this amount with Player:setHealth.
340+
-- @server
341+
-- @param number newmaxhealth New max health value.
342+
function player_methods:setMaxHealth(val)
343+
local ply = getply(self)
344+
checkpermission(instance, ply, "player.setMaxHealth")
345+
checkluatype(val, TYPE_NUMBER)
346+
347+
ply:SetMaxHealth(val)
348+
end
349+
315350
--- Sets Crouched Walk Speed
316351
-- @param number newcwalkspeed New Crouch Walk speed, This is a multiplier from 0 to 1.
317352
function player_methods:setCrouchedWalkSpeed(val)
@@ -460,9 +495,74 @@ end
460495

461496
--- Forces the player out of a vehicle.
462497
function player_methods:exitVehicle()
463-
local ent = getply(self)
464-
checkpermission(instance, ent, "player.exitVehicle")
465-
Ply_ExitVehicle(ent)
498+
local ent = getply(self)
499+
checkpermission(instance, ent, "player.exitVehicle")
500+
Ply_ExitVehicle(ent)
501+
end
502+
503+
--- Sets the player's position.
504+
-- @param Vector vec New position
505+
-- @param boolean? revive Revive the player if they are dead
506+
function player_methods:setPos(vec, revive)
507+
local ply = getply(self)
508+
checkpermission(instance, ply, "player.setPos")
509+
510+
if revive and not ply:Alive() then
511+
ply:Spawn()
512+
end
513+
514+
Ent_SetPos(ply, SF.clampPos(vunwrap1(vec)))
515+
end
516+
517+
--- Add the player's linear velocity.
518+
-- @param Vector vel Add velocity
519+
function player_methods:addVelocity(vel)
520+
local ply = getply(self)
521+
vel = vunwrap1(vel)
522+
checkvector(vel)
523+
524+
checkpermission(instance, ply, "player.addVelocity")
525+
Ent_SetVelocity(ply, vel)
526+
end
527+
528+
--- Sets the gravity multiplier of the player.
529+
-- @param number multiplier By how much to multiply the gravity. 1 is normal gravity, 0.5 is half-gravity, etc.
530+
function player_methods:setGravity(multiplier)
531+
local ply = getply(self)
532+
checkpermission(instance, ply, "player.modifyMovementProperties")
533+
checkluatype(multiplier, TYPE_NUMBER)
534+
535+
Ent_SetGravity(ply, multiplier)
536+
537+
if not gravity_reset[ply:UserID()] then
538+
gravity_reset[ply:UserID()] = ply
539+
end
540+
end
541+
542+
--- Ignites a player
543+
-- @param number length How long the fire lasts
544+
-- @param number? radius (optional) How large the fire hitbox is (entity obb is the max)
545+
function player_methods:ignite(length, radius)
546+
local ply = getply(self)
547+
checkluatype(length, TYPE_NUMBER)
548+
549+
checkpermission(instance, ply, "player.ignite")
550+
551+
if radius~=nil then
552+
checkluatype(radius, TYPE_NUMBER)
553+
local obbmins, obbmaxs = Ent_OBBMins(ply), Ent_OBBMaxs(ply)
554+
radius = math.Clamp(radius, 0, (obbmaxs.x - obbmins.x + obbmaxs.y - obbmins.y) / 2)
555+
end
556+
557+
Ent_Ignite(ply, length, radius)
558+
end
559+
560+
--- Extinguishes a player
561+
function player_methods:extinguish()
562+
local ply = getply(self)
563+
checkpermission(instance, ply, "player.ignite")
564+
565+
Ent_Extinguish(ply)
466566
end
467567

468568
end

0 commit comments

Comments
 (0)