Jump to content

Better Logging...

Pending 1.3.0

DiGiaComTech
DiGiaComTech

Posted (edited)

I know we all have other things to do outside of Rust development ... but could you please update your plugin's logging to better inform server owners of issues?  Something like this for example...

        private bool TryGetValidGroundPos(Vector3 basePos, out Vector3 groundPos, float radiusMin = 1f, float radiusMax = 25f)
        {
            groundPos = Vector3.zero;
            string function = "Heli Crash Event » TryGetValidGroundPos: ";

            for (int i = 0; i < 100; i++)
            {
                // Random point around the crate/crash
                var offset2D = UnityEngine.Random.insideUnitCircle.normalized * UnityEngine.Random.Range(radiusMin, radiusMax);
                var testPos = new Vector3(basePos.x + offset2D.x, basePos.y, basePos.z + offset2D.y);

                // Start the ray from *above* everything to avoid “inside collider” issues
                float startY = Mathf.Max(basePos.y + 200f, TerrainMeta.HeightMap.GetHeight(testPos) + 200f);
                var rayStart = new Vector3(testPos.x, startY, testPos.z);
                var rayEnd = rayStart + Vector3.down * 500f;

                RaycastHit hit;
                if (!GamePhysics.Trace(new Ray(rayStart, Vector3.down), 0f, out hit, 500f, GroundMask, QueryTriggerInteraction.Ignore))
                {
                    ServerConsole.print($"{function} Invalid Ray Hit Position @ {hit.point}, try {i+1}!");
                    continue;
                }

                // Reject steep slopes (cliff faces)
                float slope = Vector3.Angle(hit.normal, Vector3.up);
                if (slope > 45f) // tune this
                {
                    ServerConsole.print($"{function} Invalid Slope ({slope} > 45°), try {i+1}");
                    continue;
                }

                var p = hit.point;

                // Reject deep water
                float waterlevel = WaterLevel.GetWaterDepth(p, false, false);
                if ( waterlevel > 0.2f)
                {
                    ServerConsole.print($"{function} Invalid Water Depth ({waterlevel} > 0.2m), try {i+1}!");
                    continue;
                }

                // Nudge up a bit so the NPC doesn’t clip into ground due to capsule/skin width
                p += Vector3.up * 0.15f;

                // Optional: ensure there’s room for a human-sized capsule at that spot (prevents spawning inside rocks/props even if ground hit is valid)
                if (UnityEngine.Physics.CheckCapsule(p + Vector3.up * 0.1f, p + Vector3.up * 1.8f, 0.35f, ObstructionMask, QueryTriggerInteraction.Ignore))
                {
                    ServerConsole.print($"{function} Insuffucuent Capsule Space @ {p}, try {i+1}!");
                    continue;
                }

                groundPos = p;
                return true;
            }

            return false;
        }


Note that the log entries indicate the Plugin & Function they originated from and pertinent information, in some cases the number of tries (for later statistical analysis, see 2000 issue below).  And for that last one, the Capsule Height wasn't invalid as it's a fixed value, there was simply Insufficient Vertical Space at that position to allow the NPC to be spawned (i.e., accuracy of language).

The reason for all of this was that my server was crashing because it was sending 2000 'Invalid Water Depth' log entries (see attached).  And at that time I had no idea where they were coming from until my Game Host indicated it was happening after HeliCrashEvent was called.

Sorry for being terse, and am NOT trying to be a jerk.  Just trying to help make this plugin better for all. 😉 

2026-09-09_T0100.txt

Edited by DiGiaComTech
typos, not sure how that HeliSignal file or images got here :S

About Us

Codefling is the largest marketplace for plugins, maps, tools, and more, making it easy for customers to discover new content and for creators to monetize their work.

Downloads
3.1m
Total downloads
Customers
12.1k
Customers served
Files Sold
171.2k
Total sales
Payments
3.7m
Processed total
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.