How to know if a HackableLockedCrate has spawned on the Cargo Ship.

Hey,

Im trying to get a plugin to know when the HackableLockedCrate appears at cargo, Ive tried getting the cords from the Cargo and the Crate and compare them to see if they are close enough, but I cant really get it to work. Is there any simple method to get this?

void OnEntitySpawned(BaseNetworkable entity)
        {

            if(entity is CargoShip) {
                var entity2 = entity as BaseNetworkable;
                Vector3 pos2 = entity2.transform.position;
            }


            if(entity is HackableLockedCrate) {

                bool IsOnCargo = Math.Sqrt(Math.Pow(Math.Abs(pos2.x - entity.transform.position.x), 2) + Math.Pow(Math.Abs(pos2.z - entity.transform.position.z), 2)) <= 200;
                if(IsOnCargo) {
                    Puts("Funsiona si oke klk");
                }

            }
        }

This was the last thing I've tried but doesnt work,  whats wrong here? Ive been trying for some time now but still couldnt get it to work.

Thank you very much for the help!

The crate should be parented to the cargo ship, so you can probably just check if crate.GetParentEntity() is CargoShip.