HolyLib Wiki

HolyLib:OnPhysicsLag

  number HolyLib:OnPhysicsLag( number simulationTime, IPhysicsObject phys1, IPhysicsObject phys2, table recalcPhys, string callerFunction )

Description

Called when the physics simulaton is taking longer than the set lag threshold.
You can freeze all props here and then return physenv.IVP_SkipSimulation to skip the simulation for this tick if someone is trying to crash the server.

Recently Changed

This was recently changed in version (0.8 - DEV).

The arguments phys1, phys2, recalcPhys and callerFunction were added

Arguments

1number simulationTime
How long the simulation already took.
4table recalcPhys
Table containing all physics object that are recalculating their collision rules.Don't modify them since it's highly unstable!
5string callerFunction
Name of the internal IVP function that triggered this Lua call

Returns

1number skipType = physenv.IVP_NoSkip

Example

Example usage of this hook
physenv.SetLagThreshold(50) hook.Add("HolyLib:OnPhysicsLag", "Test", function(delta, phys1, phys2, recalcPhys, callerFunc) local mainEnv = physenv.GetActiveEnvironmentByIndex(0) local simulating = mainEnv:IsInSimulation() print("Tiggered OnPhysicsLag!", mainEnv, simulating, callerFunc)
mainEnv:SetInSimulation(false) for _, v in ipairs(ents.GetAll()) do local phys = v:GetPhysicsObject() if phys:IsValid() and not recalcPhys[phys] then if phys:IsPenetrating() then v:SetCollisionGroup(COLLISION_GROUP_WORLD) end phys:EnableMotion(false) end end mainEnv:SetInSimulation(simulating) return physenv.IVP_SkipSimulation end)