1. Ok, so here I am - I'm working on my Building Blocker And I've run into something I can't do.
    What I'm trying to achive - check the position of the block, and see if it in range of the tool cupboard. If so - block placment.
    I was able to do it using OnEntityBuilt - in this hook we are getting GameObject that already exist in the world, so we can easly use it's position. But the problem with this hook is, that it's called AFTER block is placed, so I have to remove it and refund the player it's cost.
    I'm trying to do the same thing, but with CanBuild hook, but there is a problem - this hook is called with Construction class as a var, and I'm unable to get the location where the player is trying to place it.

    So - can anybody help me? What I need is to get the world position of enity that is not created yet. =(
     
  2. Why you can't just get owner from Planner?
     
  3. You don't get it.
    Right now I'm checking player position, but that's not what I need.
    Player can stay out of range of tool cupboard and at the same time - he may try to build something in the range.
    Checking player position is not an option - I need to know the place, where he trying to build.
    I need to check if the block he trying to place is in range, not the player himself...
     
  4. If you can get the player, you can use the Unity function Raycast, it is part of the Physics library.
    for the rotation, you can use player.eyes.headrotation
     
  5. Raycast? How? if it won't be too hard for you - can you please give me an example?
    That main problem is - that I don't know the distance....
    Also - I didn't work much with raycasts, so I can't say that I'm good at it =)
     
  6. here is a basic code :)

    Code:
    // Initialisation of the ray
    Ray ray = new Ray(player.ServerPosition, player.eyes.headRotation.eulerAngles);// Return true if it hits a collider at 1000 Unity units (or less) in front of the player
    if (Physics.Raycast(ray, 1000))
    {
        // Send a message to the player
        player.ChatMessage("You can't place a building here !");
    }
    
    you might want to change the distance because the longer the raycast is, the more CPU it will take on the server ....
    my advice is to test with a distance, then change it and reload the plugin to test, and so on ....
     
  7. Okay, I'm has opened my eyes and found it.
    Use this hook with Vector3 parameter.
    void CanBuild(Planner plan, Construction prefab, Vector3 position) {}
    But it works if prefab without sockets
     
    Last edited by a moderator: May 12, 2017
  8. Where did you found this Vector3? o_O
    Also - where this hooks are ejected? I was unable to find anything related in oxide source....
     
  9. Planner.DoBuild
     
  10. Raycast always returns false. I'm out of ideas.
    Also - what if the players tries to place a wall? The wall would be in the air, and even if I'll manage to make raycast to work - if the player would try to place a wall he would be looking in the sky, so there would be nothing to hit for raycast... Still looking for a solution.
     
  11. Ok, I've checked assembly and true - there is another vector3 param, strange that they didn't put it in the docs.
    But still - the problem with the sockets. It's impossible(as I can see) to get the position of block player are attaching new one....
     
  12. Well - I guess it solved. Now, thanks to @nivex the way was found.

    Code:
    //Getting player position
    var pos = player.ServerPosition;
    //Incementig Y by player height
    pos.y += player.GetHeight();
    //Adding player view point to it.
    var buildPos = pos + (player.eyes.BodyForward() * 4f);
    and we are getting position where player are about to place new foundation.