1. How I can find foundation which current object belongs to in C# plugin?

    Example: I'm looking at the wall, I type command, and I get InstanceID of foundation which that wall belongs to, or at least foundation which is below that wall?

    Or I'm looking at furnace which is at 4th floor, I type command, and I get InstanceID of foundation which is on the 1st floor, right below that furnace. (If there's no foundation below, it should find any nearby foundation anyways)
     
  2. You could try running a Raycast downwards from it's position to find a foundation, though I'm not sure if that would always work. I'm not sure if there's a stored variable that contains the 'owner' block, but I assume you've already checked.
     
  3. You could take a look at this plugin and modify it to your likings. EntityOwner for Rust | Oxide
    The command /prod2 shows you all the owners of all the blocks of a building.
     
  4. yes, but that's not what I need, I want to find one foundation, which is part of building/object i'm currently looking into.
     
  5. You can look at the plugin and see how they did the attached blocks.
     
  6. Rust doesn't really store which things belong to a physical building.
    You could have a look at the entity owner code, which solves a similar issue (finding all entities that are part of a building) in massChangeOwner<T>.
    massChangeOwner<T> uses Vis.Entities<T>(Vector3 position, float radius, List<T> list, int layerMask = -1, QueryTriggerInteraction triggerInteraction = 2), which finds all entities in a certain radius around position and adds them to list.
    Basically, massChangeOwner<T> uses the first BuildingBlock, finds all BuildingBlocks within a certain radius and then recursively repeats that process for each new BuildingBlock (excluding ones it has already found).
    The first BuildingBlock can be found through a straight raycast from the player's eyes. EntityOwner calls its method RaycastAll like RaycastAll<Some type that inherits BaseEntity>(player.eyes.HeadRay()).
    RaycastAll looks like this:
    Code:
    private object RaycastAll<T>(Vector3 Pos, Vector3 Aim) where T : BaseEntity
    {
        var hits = Physics.RaycastAll(Pos, Aim);
        GamePhysics.Sort(hits);
        var distance = 100f;
        object target = false;
        foreach (var hit in hits)
        {
            var ent = hit.GetEntity();
            if (ent is T && hit.distance < distance)
            {
                target = ent;
                break;
            }
        }    return target;
    }
    Also, one thing I'd like to add is that Physics.RaycastAll does not guarantee an order, which means that you'll have to iterate the entire hits list to find the closest hit or sort beforehand.
     
  7. What you could do is raycast straight down from the object you are looking at and then find the nearest object which is type of foundation.
     
  8. I'm terrible with raycast method, I'll investigate what Nograd has done in NTeleportation.