Jump to content

Better Logging...

Fixed 1.3.0 1.3.1

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} Inadequate 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
Cahnu

Posted

Hello,

Thanks for the recommendation and for taking the time to instrument it yourself. You were right on all three counts and I've made a few changes in version 1.3.1 to address them and hopefully provide a better end result.
 

What changed:

Rejections are tallied, not printed. One warning is emitted, only when placement actually fails. 
Example- 

[HeliCrashEvent] TryGetSpawnPositions: placed only 3 of 6 NPCs within 2-25m of the
crash site at (1204.5, 12.3, -880.1). 412 positions tested - no ground below: 0,
slope over 45deg: 271, water deeper than 0.2m: 138, not enough clear space: 3.


Per-attempt detail is still available, behind a new config option (default off): "Log every rejected NPC spawn position (troubleshooting only - very noisy):": false"

Example-

[HeliCrashEvent] TryGetValidGroundPos: Invalid Slope (58.2deg > 45deg) @ (1204.5, 28.4, -880.1), try 1 (position 1 overall)!


invalid capsule height is gone; you were right that it was wrong. Height is a fixed 1.8m — it now reads Inadequate Vertical Clearance.
Thresholds are named constants shared by the check and the message, so they are more clear what they represent when troubleshooting.
Logging now contains the calling function name + any useful data.

Please download the latest version and let me know if you have any trouble with it. Thanks!

  • Like 1
Cahnu

Posted

Changed Status from Pending to Fixed

Changed Fixed In to 1.3.1

  • Like 1

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.6k
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.